Skip to content

Commit 1cfb868

Browse files
Merge pull request #4 from pfnet-research/masanori/support-latest-python
support python 3.12, 3.13
2 parents cf6b61c + d5f8dcc commit 1cfb868

File tree

6 files changed

+67
-14
lines changed

6 files changed

+67
-14
lines changed

.github/workflows/ci-python.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ jobs:
2424
max-parallel: 5
2525
matrix:
2626
platform: [ubuntu-latest, macos-latest, windows-latest]
27-
python-version: [3.9, "3.10", "3.11"] # TODO (masanori): add 3.12, 3.13 when it is available
27+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
28+
pandas-and-numpy-version:
29+
- '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'
30+
- '"pandas>=2.0.0" "numpy>=2.0.0"'
31+
exclude:
32+
- python-version: "3.12"
33+
pandas-and-numpy-version: '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'
34+
- python-version: "3.13"
35+
pandas-and-numpy-version: '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'
2836

2937
# Steps represent a sequence of tasks that will be executed as part of the job
3038
steps:
@@ -41,6 +49,7 @@ jobs:
4149
- name: Install dependencies
4250
run: |
4351
uv sync --dev
52+
uv run pip install -U ${{ matrix.pandas-and-numpy-version }}
4453
- name: Test
4554
run: |
4655
uv run black --check --diff --quiet .

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# qfeval-data
2-
[![python](https://img.shields.io/badge/python-%3E=3.9,%3C3.12-blue.svg)](https://pypi.org/project/qfeval_data/)
2+
[![python](https://img.shields.io/badge/python-%3E=3.9-blue.svg)](https://pypi.org/project/qfeval_data/)
33
[![pypi](https://img.shields.io/pypi/v/qfeval_data.svg)](https://pypi.org/project/qfeval_data/)
44
[![CI](https://github.com/pfnet-research/qfeval-data/actions/workflows/ci-python.yaml/badge.svg)](https://github.com/pfnet-research/qfeval-data/actions/workflows/ci-python.yaml)
55
[![codecov](https://codecov.io/gh/pfnet-research/qfeval-data/graph/badge.svg?token=5A02B1JV7V)](https://codecov.io/gh/pfnet-research/qfeval-data)

pyproject.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@ version = "0.1.0"
44
description = "Data structures for quantitative finance"
55
readme = "README.md"
66
# Don't forget to fix the badge in README.md after changing requires-python
7-
# TODO (masanori): Support python 3.12, 3.13 (pandas 2.0.0+). also update CI
8-
requires-python = ">=3.9,<3.12"
7+
requires-python = ">=3.9"
98
dependencies = [
10-
"pandas>=1.5.0,<2.0.0",
11-
"numpy>=1.24.0,<2.0.0",
9+
"pandas",
10+
"numpy",
1211
"torch",
1312
"qfeval-functions",
1413
]
1514

1615
[project.optional-dependencies]
1716
plot = [
18-
"matplotlib>=3.8.3"
17+
"matplotlib"
1918
]
2019

2120
[dependency-groups]

qfeval_data/data.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,25 @@ def __set_xticks(self, ax: matplotlib.axes.Axes) -> None:
14971497
# first candlestick of a month would start with its previous
14981498
# month.
14991499
unit, _ = np.datetime_data(delta)
1500+
unit = typing.cast(
1501+
typing.Literal[
1502+
"Y",
1503+
"M",
1504+
"W",
1505+
"D",
1506+
"h",
1507+
"m",
1508+
"s",
1509+
"ms",
1510+
"us",
1511+
"μs",
1512+
"ns",
1513+
"ps",
1514+
"fs",
1515+
"as",
1516+
],
1517+
unit,
1518+
)
15001519
label_ticks = util.ceil_time(
15011520
timestamps[tick_indices], np.timedelta64(1, unit)
15021521
)
@@ -1521,8 +1540,14 @@ def __xtick_deltas(
15211540
"m": [(30, 10), (20, 5), (10, 5), (5, 1), (2, 1), (1, 1)],
15221541
"s": [(30, 10), (20, 5), (10, 5), (5, 1), (2, 1), (1, 1)],
15231542
}
1524-
last_deltas = (np.timedelta64(100, "Y"), np.timedelta64(100, "Y"))
1543+
last_deltas: typing.Tuple[
1544+
np.timedelta64,
1545+
np.timedelta64,
1546+
] = (np.timedelta64(100, "Y"), np.timedelta64(100, "Y"))
15251547
for unit, sizes in deltas.items():
1548+
unit = typing.cast(
1549+
typing.Literal["Y", "M", "D", "h", "m", "s"], unit
1550+
)
15261551
for major, minor in sizes:
15271552
major_delta = np.timedelta64(major, unit)
15281553
minor_delta = np.timedelta64(minor, unit)
@@ -1642,8 +1667,8 @@ def downsample(
16421667
dest_unit = np.datetime_data(delta)[0]
16431668
timestamps = util.floor_time(self.timestamps, delta, origin, offset)
16441669
timestamps = timestamps.astype(f"datetime64[{dest_unit}]")
1645-
timestamps, group_ids = np.unique(timestamps, return_inverse=True)
1646-
group_ids = torch.tensor(group_ids, device=self.device)
1670+
timestamps, _group_ids = np.unique(timestamps, return_inverse=True)
1671+
group_ids = torch.tensor(_group_ids, device=self.device)
16471672

16481673
tensors = {}
16491674
for k, v in self.__tensors.items():

qfeval_data/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,27 @@ def floor_time(
169169

170170
def time_origin(d: np.timedelta64) -> np.datetime64:
171171
unit, _ = np.datetime_data(d)
172+
unit = typing.cast(
173+
typing.Literal[
174+
"Y",
175+
"M",
176+
"W",
177+
"D",
178+
"h",
179+
"m",
180+
"s",
181+
"ms",
182+
"us",
183+
"μs",
184+
"ns",
185+
"ps",
186+
"fs",
187+
"as",
188+
],
189+
unit,
190+
)
172191
if unit in ("M", "Y"):
192+
unit = typing.cast(typing.Literal["M", "Y"], unit)
173193
# qfeval uses 1000-01-01 as the datetime origin for monthly/yearly
174194
# ticks so as to show multiples of 10/100/1000 years for a long term
175195
# x-axis.

tests/test_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def test_to_matrix(self) -> None:
495495
df = pd.read_csv(io.StringIO(csv))
496496
data = Data.from_dataframe(df)
497497
actual_df = data.weight.to_matrix()
498-
assert actual_df.to_csv(line_terminator="\n") == expected
498+
assert actual_df.to_csv(lineterminator="\n") == expected
499499

500500
def test_missing_to_matrix(self) -> None:
501501
csv = """timestamp,symbol,return,weight
@@ -507,7 +507,7 @@ def test_missing_to_matrix(self) -> None:
507507
df = pd.read_csv(io.StringIO(csv))
508508
data = Data.from_dataframe(df)
509509
actual_df = data.weight.to_matrix()
510-
assert actual_df.to_csv(line_terminator="\n") == expected
510+
assert actual_df.to_csv(lineterminator="\n") == expected
511511

512512
def test_rename(self) -> None:
513513
data = Data.from_dataframe(self.create_simple_dataframe())
@@ -834,7 +834,7 @@ def test_downsample(self) -> None:
834834
np.timedelta64(2, "D"), origin=np.datetime64("2018-01-01")
835835
)
836836
.to_dataframe()
837-
.to_csv(index=False, line_terminator="\n")
837+
.to_csv(index=False, lineterminator="\n")
838838
== "timestamp,symbol,open,high,low,close\n"
839839
+ "2018-01-01,AAPL,154.0,162.0,154.0,160.0\n"
840840
+ "2018-01-03,AAPL,159.0,161.0,154.0,159.0\n"
@@ -849,7 +849,7 @@ def test_downsample(self) -> None:
849849
assert (
850850
data.weekly(origin=np.datetime64("2018-01-01"))
851851
.to_dataframe()
852-
.to_csv(index=False, line_terminator="\n")
852+
.to_csv(index=False, lineterminator="\n")
853853
== "timestamp,symbol,open,high,low,close\n"
854854
+ "2018-01-01,AAPL,154.0,163.0,154.0,163.0\n"
855855
+ "2018-01-08,AAPL,161.0,177.0,160.0,162.0\n"

0 commit comments

Comments
 (0)