Skip to content

Commit

Permalink
0.9.59 update
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Sep 14, 2024
1 parent dae4747 commit 30fecea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions czsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from czsc.utils import (
mac_address,
overlap,
to_arrow,

format_standard_kline,

Expand All @@ -65,6 +66,7 @@
save_json,
get_sub_elements,
get_py_namespace,
code_namespace,
freqs_sorted,
x_round,
import_by_name,
Expand Down
26 changes: 26 additions & 0 deletions czsc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def get_py_namespace(file_py: str, keys: list = []) -> dict:
return namespace


def code_namespace(code: str, keys: list = []) -> dict:
"""获取 python 代码中的 namespace
:param code: python 代码
:param keys: 指定需要的对象名称
:return: namespace
"""
namespace = {"code": code}
exec(code, namespace)
if keys:
namespace = {k: v for k, v in namespace.items() if k in keys}
return namespace


def import_by_name(name):
"""通过字符串导入模块、类、函数
Expand Down Expand Up @@ -199,3 +213,15 @@ def mac_address():
x = uuid.UUID(int=uuid.getnode()).hex[-12:].upper()
x = "-".join([x[i : i + 2] for i in range(0, 11, 2)])
return x


def to_arrow(df: pd.DataFrame):
"""将 pandas.DataFrame 转换为 pyarrow.Table"""
import io
import pyarrow as pa

table = pa.Table.from_pandas(df)
with io.BytesIO() as sink:
with pa.ipc.new_file(sink, table.schema) as writer:
writer.write_table(table)
return sink.getvalue()
1 change: 1 addition & 0 deletions czsc/utils/bar_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def is_trading_time(dt: datetime = datetime.now(), market="A股"):
def get_intraday_times(freq="1分钟", market="A股"):
"""获取指定市场的交易时间段
:param freq: K线周期,如 1分钟、5分钟、15分钟、30分钟、60分钟
:param market: 市场名称,可选值:A股、期货、默认
:return: 交易时间段列表
"""
Expand Down

0 comments on commit 30fecea

Please sign in to comment.