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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
with:
persist-credentials: false
- name: Install uv and set the Python version
uses: astral-sh/setup-uv@v10.3.3
uses: astral-sh/setup-uv@v10.4.0
with:
python-version: ${{ matrix.python-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@v10.3.3
uses: astral-sh/setup-uv@v10.4.0
- name: Run pre-commit
run: uvx pre-commit run --all-files --show-diff-on-failure --color=always
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@v10.3.3
uses: astral-sh/setup-uv@v10.4.0
- name: Install Python
run: uv python install
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.17.4
rev: v0.17.6
hooks:
# Run the linter.
- id: ruff-check
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# uv export --format requirements-txt --no-emit-project --no-hashes --no-dev -o requirements.txt
beautifulsoup4==4.15.0
# via yahooquery
certifi==2026.10.23
certifi==2026.11.20
# via
# curl-cffi
# requests
cffi==2.1.1
# via curl-cffi
charset-normalizer==3.5.2
charset-normalizer==3.5.3
# via requests
colorama==0.4.6 ; sys_platform == 'win32'
# via tqdm
curl-cffi==0.17.0
# via yahooquery
exchange-calendars==4.13.2
exchange-calendars==4.13.3
# via market-prices
idna==3.20
# via requests
Expand All @@ -32,7 +32,7 @@ numpy==2.4.6 ; python_full_version == '3.11.*'
# exchange-calendars
# market-prices
# pandas
numpy==2.5.4 ; python_full_version >= '3.12'
numpy==2.5.5 ; python_full_version >= '3.12'
# via
# exchange-calendars
# market-prices
Expand Down Expand Up @@ -67,7 +67,7 @@ six==1.17.0 ; python_full_version < '3.11'
# via python-dateutil
soupsieve==2.10 ; python_full_version < '3.11.5'
# via beautifulsoup4
soupsieve==4.0.1 ; python_full_version >= '3.11.5'
soupsieve==4.1.3 ; python_full_version >= '3.11.5'
# via beautifulsoup4
toolz==1.2.0
# via exchange-calendars
Expand Down
7 changes: 4 additions & 3 deletions tests/test_base_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pandas as pd
import pytest
import valimp
from pandas.testing import assert_frame_equal, assert_index_equal
from pandas.testing import assert_frame_equal

import market_prices.prices.base as m
from market_prices import data, errors, helpers, intervals, mptypes, pt
Expand All @@ -38,6 +38,7 @@
from .utils import (
RESOURCES_PATH,
XHKGAsAt4132,
assert_index_equal,
clean_temp_test_dir,
get_resource_pbt,
)
Expand Down Expand Up @@ -960,7 +961,7 @@ def assertions_daily(
end_ = cc.sessions.get_slice_bound(end, "right")
slc = slice(start_, end_)
expected = cc.sessions[slc]
assert_index_equal(df.index, expected)
assert_index_equal(df.index, expected, check_freq=False)

symbols = prices.symbols
for s in symbols:
Expand Down Expand Up @@ -1244,7 +1245,7 @@ def test__get_table_daily(prices_us, one_day, monkeypatch):
expected = cal.sessions_in_range(start, end)
if expected.tz is not None:
expected = expected.tz_convert(None)
assert_index_equal(table.index, expected)
assert_index_equal(table.index, expected, check_freq=False)


class TestTableIntraday:
Expand Down
15 changes: 11 additions & 4 deletions tests/test_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
import numpy as np
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal, assert_index_equal, assert_series_equal
from pandas.testing import assert_frame_equal, assert_series_equal

import market_prices.pt as m
from market_prices import errors, helpers
from market_prices.helpers import UTC
from market_prices.intervals import TDInterval
from market_prices.utils import calendar_utils as calutils

from .utils import CMESAsAt4132, get_resource, multiple_sessions_freq
from .utils import (
CMESAsAt4132,
assert_index_equal,
get_resource,
multiple_sessions_freq,
)


@pytest.fixture
Expand Down Expand Up @@ -534,7 +539,9 @@ def test_daily_pt(
assert df.pt.has_regular_interval

xnys = calendars[0]
assert_index_equal(daily_pt_ss.pt.get_trading_index(xnys), daily_pt_ss.index)
assert_index_equal(
daily_pt_ss.pt.get_trading_index(xnys), daily_pt_ss.index, check_freq=False
)

for cal in calendars:
ti = df.pt.get_trading_index(cal)
Expand Down Expand Up @@ -877,7 +884,7 @@ def test_multiple_sessions_pt(
non_trading_sessions = dates.intersection(non_sessions)
assert not non_trading_sessions.empty
assert not dates.intersection(sessions).empty
assert_index_equal(info[indice], non_trading_sessions)
assert_index_equal(info[indice], non_trading_sessions, check_freq=False)

for indice in df.pt.indices_trading(cal):
dates = pd.date_range(indice.left, indice.right - one_day)
Expand Down
59 changes: 40 additions & 19 deletions tests/test_tutorial_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import pandas as pd
import pytest
from pandas import Timestamp as T
from pandas.testing import assert_index_equal

import market_prices.support.tutorial_helpers as m
from market_prices import errors, intervals
from market_prices.helpers import UTC
from market_prices.prices.base import PricesBase
from market_prices.utils import calendar_utils as calutils

from .utils import assert_index_equal


@pytest.fixture(scope="class")
def side() -> abc.Iterator[str]:
Expand Down Expand Up @@ -266,16 +267,16 @@ def match(
length = full_session_xlon
expected = pd.DatetimeIndex([start]).as_unit("ns")
num = 1
assert_index_equal(f(cals, [length], start, end, num), expected)
assert_index_equal(f(cals, [length], start, end, num), expected, check_freq=False)
assert_index_equal(f_cc(cc, length, start, end, num), expected)
lengths = [[length]]
assert_index_equal(f_var(cals, lengths, start, end), expected)
assert_index_equal(f_cc_var(cc, [length], start, end), expected)
assert_index_equal(f_var(cals, lengths, start, end), expected, check_freq=False)
assert_index_equal(f_cc_var(cc, [length], start, end), expected, check_freq=False)

num = 10 # limit that can be fuflilled
expected = xlon.sessions_in_range(start, T("2021-12-23"))
assert_index_equal(f(cals, [length], start, end, num), expected)
assert_index_equal(f_cc(cc, length, start, end, num), expected)
assert_index_equal(f_cc(cc, length, start, end, num), expected, check_freq=False)
lengths = [[length] * num]
assert_index_equal(f_var(cals, lengths, start, end), expected)
assert_index_equal(f_cc_var(cc, [length] * num, start, end), expected)
Expand All @@ -300,10 +301,10 @@ def match(
lengths = [[length]]
num = 1
expected = pd.DatetimeIndex([T("2021-12-24")]).as_unit("ns")
assert_index_equal(f(cals, [length], start, end, num), expected)
assert_index_equal(f(cals, [length], start, end, num), expected, check_freq=False)
assert_index_equal(f_cc(cc, length, start, end, num), expected)
assert_index_equal(f_var(cals, lengths, start, end), expected)
assert_index_equal(f_cc_var(cc, [length], start, end), expected)
assert_index_equal(f_var(cals, lengths, start, end), expected, check_freq=False)
assert_index_equal(f_cc_var(cc, [length], start, end), expected, check_freq=False)

num += 1
msg = match(cals, [[length] * num], start, end)
Expand Down Expand Up @@ -342,12 +343,20 @@ def match(
).as_unit("ns")
cc_lengths = [full_session_xlon, half_session_xlon]
lengths = [cc_lengths]
assert_index_equal(f_var(cals, lengths, start, end), full_expected[:2])
assert_index_equal(f_cc_var(cc, cc_lengths, start, end), full_expected[:2])
assert_index_equal(
f_var(cals, lengths, start, end), full_expected[:2], check_freq=False
)
assert_index_equal(
f_cc_var(cc, cc_lengths, start, end), full_expected[:2], check_freq=False
)
cc_lengths = [*cc_lengths, full_session_xlon]
lengths = [cc_lengths]
assert_index_equal(f_var(cals, lengths, start, end), full_expected)
assert_index_equal(f_cc_var(cc, cc_lengths, start, end), full_expected)
assert_index_equal(
f_var(cals, lengths, start, end), full_expected, check_freq=False
)
assert_index_equal(
f_cc_var(cc, cc_lengths, start, end), full_expected, check_freq=False
)

# two calendars
cals = [xlon, xnys]
Expand All @@ -368,11 +377,17 @@ def match(

num = 10 # limit that can be fuflilled
expected = xlon.sessions_in_range(start, T("2021-12-23"))
assert_index_equal(f(cals, length_by_cal, start, end, num), expected)
assert_index_equal(f_cc(cc, length_cc, start, end, num), expected)
assert_index_equal(
f(cals, length_by_cal, start, end, num), expected, check_freq=False
)
assert_index_equal(f_cc(cc, length_cc, start, end, num), expected, check_freq=False)
lengths_by_cal = [[full_session_xlon] * num, [full_session_xnys] * num]
assert_index_equal(f_var(cals, lengths_by_cal, start, end), expected)
assert_index_equal(f_cc_var(cc, [length_cc] * num, start, end), expected)
assert_index_equal(
f_var(cals, lengths_by_cal, start, end), expected, check_freq=False
)
assert_index_equal(
f_cc_var(cc, [length_cc] * num, start, end), expected, check_freq=False
)

# beyond limit
num += 1
Expand Down Expand Up @@ -470,14 +485,20 @@ def match(

num = 10 # limit that can be fuflilled
expected = xlon.sessions_in_range(start, T("2021-12-23"))
assert_index_equal(f(cals, length_by_cal, start, end, num), expected)
assert_index_equal(
f(cals, length_by_cal, start, end, num), expected, check_freq=False
)
lengths_by_cal = [
[full_session_xlon] * num,
[full_session_xnys] * num,
[full_session_xhkg] * num,
]
assert_index_equal(f_var(cals, lengths_by_cal, start, end), expected)
assert_index_equal(f_cc_var(cc, [length_cc] * num, start, end), expected)
assert_index_equal(
f_var(cals, lengths_by_cal, start, end), expected, check_freq=False
)
assert_index_equal(
f_cc_var(cc, [length_cc] * num, start, end), expected, check_freq=False
)

# beyond limit
num += 1
Expand Down
21 changes: 21 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime as dt
import functools
import inspect
import os
import shelve
from collections import abc
Expand All @@ -14,6 +15,7 @@
from exchange_calendars.exchange_calendar_cmes import CMESExchangeCalendar
from exchange_calendars.exchange_calendar_xhkg import XHKGExchangeCalendar
from exchange_calendars.utils import pandas_utils as xcals_pdutils
from pandas.testing import assert_index_equal as _pd_assert_index_equal

from market_prices import intervals
from market_prices.helpers import UTC
Expand All @@ -22,6 +24,25 @@

ONE_DAY = pd.Timedelta(1, "D")

# pandas added `check_freq` to `assert_index_equal` in pandas 3.1.
_ASSERT_INDEX_EQUAL_HAS_CHECK_FREQ = (
"check_freq" in inspect.signature(_pd_assert_index_equal).parameters
)


def assert_index_equal(left: pd.Index, right: pd.Index, **kwargs):
"""Assert `left` and `right` indices are equal.

As `pandas.testing.assert_index_equal` although silently drops a passed
`check_freq` keyword on a pandas version that predates that parameter
(such a version never checks an index's `freq` attribute, so dropping
the keyword cannot change the comparison).
"""
if not _ASSERT_INDEX_EQUAL_HAS_CHECK_FREQ:
kwargs.pop("check_freq", None)
_pd_assert_index_equal(left, right, **kwargs)


TEST_ROOT = Path(__file__).parent
RESOURCES_PATH = TEST_ROOT / "resources"
STORE_PATH = RESOURCES_PATH / "store.h5"
Expand Down
Loading
Loading