Skip to content

Commit 48354d6

Browse files
ppminamin
andauthored
fix: fix publish issue
* chore: test uv and ruff * feat: new feature( universe define and download data) * fix: fix some olg bugs * fix: fix pytest --------- Co-authored-by: min <[email protected]>
1 parent b64b3e5 commit 48354d6

File tree

8 files changed

+203
-1193
lines changed

8 files changed

+203
-1193
lines changed

.coverage

-52 KB
Binary file not shown.

pyproject.toml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ convention = "google"
9696

9797
[tool.mypy]
9898
python_version = "3.12"
99+
# 忽略缺少类型存根的第三方库
100+
ignore_missing_imports = true
101+
# 当遇到缺少类型存根的导入时,不报告错误
102+
warn_unused_ignores = true
103+
# 显示错误代码
104+
show_error_codes = true
105+
# 严格可选类型检查
106+
strict_optional = true
107+
108+
# 为特定模块配置
109+
[[tool.mypy.overrides]]
110+
module = ["binance.*", "websockets.*"]
111+
ignore_missing_imports = true
99112

100113
[tool.pytest.ini_options]
101114
testpaths = ["tests"]
@@ -106,11 +119,5 @@ addopts = "-v --cov=src/cryptoservice --cov-report=term-missing"
106119
packages = ["src/cryptoservice"]
107120

108121
[dependency-groups]
109-
dev = [
110-
"mypy>=1.16.0",
111-
"pandas-stubs>=2.2.3.250527",
112-
]
113-
test = [
114-
"pytest>=8.3.5",
115-
"pytest-cov>=6.1.1",
116-
]
122+
dev = ["mypy>=1.16.0", "pandas-stubs>=2.2.3.250527"]
123+
test = ["pytest>=8.3.5", "pytest-cov>=6.1.1"]

src/cryptoservice/data/storage_utils.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def store_kdtv_data(
105105
values=feature,
106106
index="K",
107107
columns="T",
108-
aggfunc="first",
108+
aggfunc="mean",
109109
)
110110
array = pivot_data.values
111111

@@ -129,7 +129,7 @@ def store_kdtv_data(
129129
values=feature,
130130
index="K",
131131
columns="T",
132-
aggfunc="first",
132+
aggfunc="mean",
133133
)
134134
array = pivot_data.values
135135
save_path = data_path / freq / feature / f"{date}.npy"
@@ -193,8 +193,8 @@ def read_kdtv_data(
193193
data_path = StorageUtils._resolve_path(data_path)
194194

195195
# 生成日期范围
196-
dates = pd.date_range(start=start_date, end=end_date, freq="D")
197-
dates = [d.strftime("%Y%m%d") for d in dates]
196+
date_range = pd.date_range(start=start_date, end=end_date, freq="D")
197+
dates = [d.strftime("%Y%m%d") for d in date_range]
198198

199199
# 读取交易对列表
200200
universe_path = data_path / freq / "universe_token.pkl"
@@ -230,9 +230,9 @@ def read_kdtv_data(
230230
index=symbols[: len(array)],
231231
columns=times,
232232
)
233-
df = df.stack() # 将时间转为索引
234-
df.name = feature
235-
date_data.append(df)
233+
stacked_series = df.stack() # 将时间转为索引
234+
stacked_series.name = feature
235+
date_data.append(stacked_series)
236236

237237
if date_data:
238238
# 合并同一天的所有特征
@@ -302,11 +302,14 @@ def read_and_visualize_kdtv(
302302
table.add_column(col, justify="right")
303303

304304
# 添加数据行
305-
for (symbol, time), row in df.iterrows():
306-
values = [
307-
f"{x:.4f}" if isinstance(x, (float, np.floating)) else str(x) for x in row
308-
]
309-
table.add_row(str(time), symbol, *values)
305+
for idx, row in df.iterrows():
306+
if isinstance(idx, tuple) and len(idx) == 2:
307+
symbol, time = idx
308+
values = [
309+
(f"{x:.4f}" if isinstance(x, (float, np.floating)) else str(x))
310+
for x in row
311+
]
312+
table.add_row(str(time), str(symbol), *values)
310313

311314
StorageUtils.console.print(table)
312315
else:

src/cryptoservice/models/universe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,20 @@ def from_dict(cls, data: dict[str, Any]) -> "UniverseDefinition":
307307
period_end_ts = snap.get("period_end_ts")
308308

309309
if period_start_ts is None or period_end_ts is None:
310-
from datetime import datetime
310+
from datetime import datetime as dt_class
311311

312312
# 自动计算时间戳
313313
period_start_ts = str(
314314
int(
315-
datetime.strptime(
315+
dt_class.strptime(
316316
f"{period_start_date} 00:00:00", "%Y-%m-%d %H:%M:%S"
317317
).timestamp()
318318
* 1000
319319
)
320320
)
321321
period_end_ts = str(
322322
int(
323-
datetime.strptime(
323+
dt_class.strptime(
324324
f"{period_end_date} 23:59:59", "%Y-%m-%d %H:%M:%S"
325325
).timestamp()
326326
* 1000

tests/README_PIPELINE_TEST.md

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)