From eeba0195b7211c45d85a4580fe9948700c4cdf0d Mon Sep 17 00:00:00 2001 From: zengbin93 Date: Wed, 17 Jun 2020 14:26:07 +0800 Subject: [PATCH] =?UTF-8?q?0.3.9=20=E4=BC=98=E5=8C=96KlineAnalyze=E6=80=A7?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- czsc/__init__.py | 2 +- czsc/analyze.py | 4 +++- test/profile_df.py | 25 +++++++++++++++++++++++++ test/test_analyze.py | 4 ++-- test/test_solid.py | 3 ++- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 test/profile_df.py diff --git a/czsc/__init__.py b/czsc/__init__.py index df8ada4..3677ac3 100644 --- a/czsc/__init__.py +++ b/czsc/__init__.py @@ -7,7 +7,7 @@ from .solid import SolidAnalyze from .solid import is_in_tolerance, is_first_buy, is_first_sell, is_second_buy, \ is_second_sell, is_third_buy, is_third_sell, is_xd_buy, is_xd_sell -__version__ = "0.3.8" +__version__ = "0.3.9" __author__ = "zengbin93" __email__ = "zeng_bin8888@163.com" diff --git a/czsc/analyze.py b/czsc/analyze.py index 855155e..bab21b0 100644 --- a/czsc/analyze.py +++ b/czsc/analyze.py @@ -234,7 +234,9 @@ class KlineAnalyze(object): def _preprocess(kline): """新增分析所需字段""" if isinstance(kline, pd.DataFrame): - kline = [row.to_dict() for _, row in kline.iterrows()] + columns = kline.columns.to_list() + kline = [{k: v for k, v in zip(columns, row)} for row in kline.values] + # kline = [row.to_dict() for _, row in kline.iterrows()] results = [] for k in kline: diff --git a/test/profile_df.py b/test/profile_df.py new file mode 100644 index 0000000..f815533 --- /dev/null +++ b/test/profile_df.py @@ -0,0 +1,25 @@ +from cobra.data.kline import get_kline + + +def convert_to_list_v1(df): + rows = [x.to_dict() for _, x in df.iterrows()] + return rows + + +def convert_to_list_v2(df): + rows = df.to_dict("records") + return rows + + +def convert_to_list_v3(df): + columns = df.columns.to_list() + rows = [{k: v for k, v in zip(columns, row)} for row in df.values] + return rows + + +if __name__ == '__main__': + df = get_kline(ts_code="000001.SH", end_dt="2020-04-28 15:00:00", freq='D', asset='I') + # convert_to_list_v1(df) + convert_to_list_v2(df) + + diff --git a/test/test_analyze.py b/test/test_analyze.py index 4013ea4..148e04e 100644 --- a/test/test_analyze.py +++ b/test/test_analyze.py @@ -1,14 +1,14 @@ # coding: utf-8 import sys +import warnings from cobra.data.kline import get_kline sys.path.insert(0, '.') sys.path.insert(0, '..') import czsc from czsc import KlineAnalyze from czsc.analyze import is_bei_chi, find_zs -from czsc.utils import plot_ka -print(czsc.__version__) +warnings.warn(f"czsc version is {czsc.__version__}") df = get_kline(ts_code="000001.SH", end_dt="2020-04-28 15:00:00", freq='D', asset='I') ka = KlineAnalyze(df, name="日线") diff --git a/test/test_solid.py b/test/test_solid.py index 1721d5e..c9f0a5c 100644 --- a/test/test_solid.py +++ b/test/test_solid.py @@ -1,11 +1,12 @@ # coding: utf-8 import sys +import warnings from cobra.data.kline import get_klines sys.path.insert(0, '.') sys.path.insert(0, '..') import czsc from czsc.solid import SolidAnalyze, is_in_tolerance -print(czsc.__version__) +warnings.warn(f"czsc version is {czsc.__version__}") def test_in_tolerance(): -- GitLab