Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/ci-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ jobs:
max-parallel: 5
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, "3.10", "3.11"] # TODO (masanori): add 3.12, 3.13 when it is available
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
pandas-and-numpy-version:
- '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'
- '"pandas>=2.0.0" "numpy>=2.0.0"'
exclude:
- python-version: "3.12"
pandas-and-numpy-version: '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'
- python-version: "3.13"
pandas-and-numpy-version: '"pandas>=1.0.0,<2.0.0" "numpy>=1.0.0,<2.0.0"'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -41,6 +49,7 @@ jobs:
- name: Install dependencies
run: |
uv sync --dev
uv run pip install -U ${{ matrix.pandas-and-numpy-version }}
- name: Test
run: |
uv run black --check --diff --quiet .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# qfeval-data
[![python](https://img.shields.io/badge/python-%3E=3.9,%3C3.12-blue.svg)](https://pypi.org/project/qfeval_data/)
[![python](https://img.shields.io/badge/python-%3E=3.9-blue.svg)](https://pypi.org/project/qfeval_data/)
[![pypi](https://img.shields.io/pypi/v/qfeval_data.svg)](https://pypi.org/project/qfeval_data/)
[![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)
[![codecov](https://codecov.io/gh/pfnet-research/qfeval-data/graph/badge.svg?token=5A02B1JV7V)](https://codecov.io/gh/pfnet-research/qfeval-data)
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ version = "0.1.0"
description = "Data structures for quantitative finance"
readme = "README.md"
# Don't forget to fix the badge in README.md after changing requires-python
# TODO (masanori): Support python 3.12, 3.13 (pandas 2.0.0+). also update CI
requires-python = ">=3.9,<3.12"
requires-python = ">=3.9"
dependencies = [
"pandas>=1.5.0,<2.0.0",
"numpy>=1.24.0,<2.0.0",
"pandas",
"numpy",
"torch",
"qfeval-functions",
]

[project.optional-dependencies]
plot = [
"matplotlib>=3.8.3"
"matplotlib"
]

[dependency-groups]
Expand Down
31 changes: 28 additions & 3 deletions qfeval_data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,25 @@ def __set_xticks(self, ax: matplotlib.axes.Axes) -> None:
# first candlestick of a month would start with its previous
# month.
unit, _ = np.datetime_data(delta)
unit = typing.cast(
typing.Literal[
"Y",
"M",
"W",
"D",
"h",
"m",
"s",
"ms",
"us",
"μs",
"ns",
"ps",
"fs",
"as",
],
unit,
)
label_ticks = util.ceil_time(
timestamps[tick_indices], np.timedelta64(1, unit)
)
Expand All @@ -1521,8 +1540,14 @@ def __xtick_deltas(
"m": [(30, 10), (20, 5), (10, 5), (5, 1), (2, 1), (1, 1)],
"s": [(30, 10), (20, 5), (10, 5), (5, 1), (2, 1), (1, 1)],
}
last_deltas = (np.timedelta64(100, "Y"), np.timedelta64(100, "Y"))
last_deltas: typing.Tuple[
np.timedelta64,
np.timedelta64,
] = (np.timedelta64(100, "Y"), np.timedelta64(100, "Y"))
for unit, sizes in deltas.items():
unit = typing.cast(
typing.Literal["Y", "M", "D", "h", "m", "s"], unit
)
for major, minor in sizes:
major_delta = np.timedelta64(major, unit)
minor_delta = np.timedelta64(minor, unit)
Expand Down Expand Up @@ -1642,8 +1667,8 @@ def downsample(
dest_unit = np.datetime_data(delta)[0]
timestamps = util.floor_time(self.timestamps, delta, origin, offset)
timestamps = timestamps.astype(f"datetime64[{dest_unit}]")
timestamps, group_ids = np.unique(timestamps, return_inverse=True)
group_ids = torch.tensor(group_ids, device=self.device)
timestamps, _group_ids = np.unique(timestamps, return_inverse=True)
group_ids = torch.tensor(_group_ids, device=self.device)

tensors = {}
for k, v in self.__tensors.items():
Expand Down
20 changes: 20 additions & 0 deletions qfeval_data/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,27 @@ def floor_time(

def time_origin(d: np.timedelta64) -> np.datetime64:
unit, _ = np.datetime_data(d)
unit = typing.cast(
typing.Literal[
"Y",
"M",
"W",
"D",
"h",
"m",
"s",
"ms",
"us",
"μs",
"ns",
"ps",
"fs",
"as",
],
unit,
)
if unit in ("M", "Y"):
unit = typing.cast(typing.Literal["M", "Y"], unit)
# qfeval uses 1000-01-01 as the datetime origin for monthly/yearly
# ticks so as to show multiples of 10/100/1000 years for a long term
# x-axis.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def test_to_matrix(self) -> None:
df = pd.read_csv(io.StringIO(csv))
data = Data.from_dataframe(df)
actual_df = data.weight.to_matrix()
assert actual_df.to_csv(line_terminator="\n") == expected
assert actual_df.to_csv(lineterminator="\n") == expected

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

def test_rename(self) -> None:
data = Data.from_dataframe(self.create_simple_dataframe())
Expand Down Expand Up @@ -834,7 +834,7 @@ def test_downsample(self) -> None:
np.timedelta64(2, "D"), origin=np.datetime64("2018-01-01")
)
.to_dataframe()
.to_csv(index=False, line_terminator="\n")
.to_csv(index=False, lineterminator="\n")
== "timestamp,symbol,open,high,low,close\n"
+ "2018-01-01,AAPL,154.0,162.0,154.0,160.0\n"
+ "2018-01-03,AAPL,159.0,161.0,154.0,159.0\n"
Expand All @@ -849,7 +849,7 @@ def test_downsample(self) -> None:
assert (
data.weekly(origin=np.datetime64("2018-01-01"))
.to_dataframe()
.to_csv(index=False, line_terminator="\n")
.to_csv(index=False, lineterminator="\n")
== "timestamp,symbol,open,high,low,close\n"
+ "2018-01-01,AAPL,154.0,163.0,154.0,163.0\n"
+ "2018-01-08,AAPL,161.0,177.0,160.0,162.0\n"
Expand Down