Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/market_prices/prices/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class PricesCsvIgnoredUnalignedIndicesWarning(PricesCsvWarning):
def __init__(self, indices: pd.DatetimeIndex, interval: TDInterval, symbol: str):
self._msg = (
f"For symbol '{symbol}' at base interval {interval} the csv file included"
" the following indices that are not aligned with the evaluated index and:"
" the following indices that are not aligned with the evaluated index and"
f" have therefore been ignored:\n{indices}"
)

Expand Down
3 changes: 2 additions & 1 deletion src/market_prices/pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,8 @@ def _get_session(indice) -> pd.Timestamp:
direction_ = "none" if direction is None else direction
s = calendar.minute_to_session(indice, direction=direction_)
else:
s = calendar.minute_to_sessions(indice, direction=direction)[0]
sessions = calendar.minute_to_sessions(indice, direction=direction)
s = sessions[0] if len(sessions) else pd.NaT
except ValueError:
s = pd.NaT
return s
Expand Down
2 changes: 0 additions & 2 deletions tests/resources/to_csv/9988.HK_1D_191126_240214.csv
Original file line number Diff line number Diff line change
Expand Up @@ -927,12 +927,10 @@ date,open,high,low,close,volume
2023-08-29,90.05,91.5,89.65,90.9,33359481.0
2023-08-30,92.0,92.0,89.85,90.35,39173999.0
2023-08-31,91.25,91.7,89.6,90.2,68704748.0
2023-09-01,90.2,90.2,90.2,90.2,0.0
2023-09-04,92.95,94.0,92.0,93.15,85600311.0
2023-09-05,93.0,93.95,91.75,92.35,54564801.0
2023-09-06,92.1,92.95,91.15,92.25,26538431.0
2023-09-07,93.05,93.05,90.5,90.8,26196625.0
2023-09-08,90.8,90.8,90.8,90.8,0.0
2023-09-11,87.95,88.8,86.85,88.05,64101748.0
2023-09-12,86.7,87.15,85.9,86.3,33461787.0
2023-09-13,86.85,87.1,85.3,85.55,31205429.0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def test_raises_csv_no_data_error(csv_dir, symbols, calendars):
dti_repr = repr(pd.DatetimeIndex(["2022-04-18 16:02:00+00:00"]))
match = (
re.escape(
f"For symbols '['MSFT', 'AZN.L', '9988.HK', 'MSFTEXTRA']' it was not possible to create a price table for any interval from csv files. The following errors and warnings occurred during parsing:\n\n0) Prices are not available at base interval {TDInterval.T20} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n1) Prices are not available at base interval {TDInterval.T1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n2) Prices are not available at base interval {TDInterval.D1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n3) Prices are not available at base interval {TDInterval.H1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n4) Prices are not available at base interval {TDInterval.T2} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n5) For symbol 'MSFT' at base interval {TDInterval.T5} the csv file included the following indices that are not aligned with the evaluated index and: have therefore been ignored:\n{dti_repr}\n\n6) For symbol 'MSFTEXTRA with interval '{TDInterval.T5}' no indice aligned with index evaluated from calendar 'XHKG'.\n\n7) Prices are not available at base interval {TDInterval.T5} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\nSee the 'path' parameter and 'Notes' sections of help(PricesCsv) for advices on how csv files should be named and formatted and for use of the `read_csv_kwargs` parameter."
f"For symbols '['MSFT', 'AZN.L', '9988.HK', 'MSFTEXTRA']' it was not possible to create a price table for any interval from csv files. The following errors and warnings occurred during parsing:\n\n0) Prices are not available at base interval {TDInterval.T20} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n1) Prices are not available at base interval {TDInterval.T1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n2) Prices are not available at base interval {TDInterval.D1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n3) Prices are not available at base interval {TDInterval.H1} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n4) Prices are not available at base interval {TDInterval.T2} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\n5) For symbol 'MSFT' at base interval {TDInterval.T5} the csv file included the following indices that are not aligned with the evaluated index and have therefore been ignored:\n{dti_repr}\n\n6) For symbol 'MSFTEXTRA with interval '{TDInterval.T5}' no indice aligned with index evaluated from calendar 'XHKG'.\n\n7) Prices are not available at base interval {TDInterval.T5} as (aligned) data was not found at this interval for symbols '['MSFTEXTRA']'.\n\nSee the 'path' parameter and 'Notes' sections of help(PricesCsv) for advices on how csv files should be named and formatted and for use of the `read_csv_kwargs` parameter."
)
if WINDOWS
else None
Expand All @@ -700,7 +700,7 @@ def test_consolidated_warning(csv_dir, symbols, calendars):
dti_repr = repr(pd.DatetimeIndex(["2022-04-18 16:02:00+00:00"]))
match = (
re.escape(
f"Price data has been found for all symbols at a least one interval, however, you may find that not all the expected price data is available. See the `limits` property for available base intervals and the limits between which price data is available at each of these intervals. See the `csv_paths` property for paths to all csv files that were found for the requested symbols. See the 'path' parameter and 'Notes' sections of help(PricesCsv) for advices on how csv files should be named and formatted and for use of the `read_csv_kwargs` parameter.\n\nThe following errors and/or warnings occurred during parsing:\n\n0) Unable to create dataframe from csv file at 'f_9988.HK_T20_fails_on_ohlc_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n1) Unable to create dataframe from csv file at 'f_AZN.L_H1_fails_on_vol_dtype.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvVolDtypeError'> 'volume' column will not convert to 'float64' dtype.\nThe source error's message was:\n\t<class 'ValueError'>: could not convert string to float: 'not a volume'\n\n2) Unable to create dataframe from csv file at 'f_AZN.L_H1_fails_on_vol_dtype.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n3) Unable to create dataframe from csv file at 'f_AZN.L_T20_fails_on_read_csv.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvReadError'> `pd.read_csv` raises error.\nThe source error's message was:\n\t<class 'ValueError'>: could not convert string to float: 'not_digits'\n\n4) Unable to create dataframe from csv file at 'f_MSFT_H1_fails_on_no_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvDataframeEmptyError'> No price data parsed from csv file.\n\n5) Unable to create dataframe from csv file at 'f_MSFT_H1_fails_on_no_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n6) Unable to create dataframe from csv file at 'f_MSFT_T20_fails_on_high_low.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvHighLowError'> At least one row has a high value that is lower than the corresponding low value.\n\n7) Unable to create dataframe from csv file at 'f_MSFT_T20_fails_on_high_low.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n8) Prices are not available at base interval {TDInterval.H1} as (aligned) data was not found at this interval for symbols '['AZN.L', 'MSFT']'.\n\n9) For symbol 'MSFT' at base interval {TDInterval.T5} the csv file included the following indices that are not aligned with the evaluated index and: have therefore been ignored:\n{dti_repr}"
f"Price data has been found for all symbols at a least one interval, however, you may find that not all the expected price data is available. See the `limits` property for available base intervals and the limits between which price data is available at each of these intervals. See the `csv_paths` property for paths to all csv files that were found for the requested symbols. See the 'path' parameter and 'Notes' sections of help(PricesCsv) for advices on how csv files should be named and formatted and for use of the `read_csv_kwargs` parameter.\n\nThe following errors and/or warnings occurred during parsing:\n\n0) Unable to create dataframe from csv file at 'f_9988.HK_T20_fails_on_ohlc_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n1) Unable to create dataframe from csv file at 'f_AZN.L_H1_fails_on_vol_dtype.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvVolDtypeError'> 'volume' column will not convert to 'float64' dtype.\nThe source error's message was:\n\t<class 'ValueError'>: could not convert string to float: 'not a volume'\n\n2) Unable to create dataframe from csv file at 'f_AZN.L_H1_fails_on_vol_dtype.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n3) Unable to create dataframe from csv file at 'f_AZN.L_T20_fails_on_read_csv.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvReadError'> `pd.read_csv` raises error.\nThe source error's message was:\n\t<class 'ValueError'>: could not convert string to float: 'not_digits'\n\n4) Unable to create dataframe from csv file at 'f_MSFT_H1_fails_on_no_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvDataframeEmptyError'> No price data parsed from csv file.\n\n5) Unable to create dataframe from csv file at 'f_MSFT_H1_fails_on_no_data.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n6) Unable to create dataframe from csv file at 'f_MSFT_T20_fails_on_high_low.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvHighLowError'> At least one row has a high value that is lower than the corresponding low value.\n\n7) Unable to create dataframe from csv file at 'f_MSFT_T20_fails_on_high_low.csv' due to the following error:\n\t<class 'market_prices.prices.csv.CsvIntervalError'> Date indices do not reflect the expected interval.\n\n8) Prices are not available at base interval {TDInterval.H1} as (aligned) data was not found at this interval for symbols '['AZN.L', 'MSFT']'.\n\n9) For symbol 'MSFT' at base interval {TDInterval.T5} the csv file included the following indices that are not aligned with the evaluated index and have therefore been ignored:\n{dti_repr}"
)
if WINDOWS
else None
Expand Down
12 changes: 8 additions & 4 deletions tests/test_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,13 @@ def test_daily_pt(self, daily_pt, symbols, calendars):
self.assertions_no_partial_indices(daily_pt, symbols[:-1], calendars[:-1])

def test_intraday_pt(self, intraday_pt, symbols, calendars):
self.assertions_no_partial_indices(intraday_pt, symbols, calendars)
# do not include ES=F as trading does not fully align with calendar.
self.assertions_no_partial_indices(intraday_pt, symbols[:-1], calendars[:-1])

def test_composite_intraday_pt(self, composite_intraday_pt, symbols, calendars):
# do not include ES=F as trading does not fully align with calendar.
self.assertions_no_partial_indices(
composite_intraday_pt, symbols, calendars, reindex=False
composite_intraday_pt, symbols[:-1], calendars[:-1], reindex=False
)

def test_composite_daily_intraday_pt(
Expand Down Expand Up @@ -2955,15 +2957,17 @@ def test_reindex_equivalence(self, intraday_pt, symbols, calendars):
df = intraday_pt
freq = df.pt.interval.as_pdfreq

for s, cal in zip(symbols, calendars, strict=True):
# do not include ES=F as trading does not fully align with calendar.
for s, cal in zip(symbols[:-1], calendars[:-1], strict=True):
rtrn = df.pt.downsample(freq, anchor="open", calendar=cal)
bv = rtrn[s].notna().all(axis=1)
rtrn_reindex = df.pt.reindex_to_calendar(cal)
assert_frame_equal(rtrn[bv], rtrn_reindex)

# Also serves to test single symbol tables
# do not include ES=F as trading does not fully align with calendar.
for anchor in ["open", "workback"]:
for s, cal in zip(symbols, calendars, strict=True):
for s, cal in zip(symbols[:-1], calendars[:-1], strict=True):
rtrn = df[s].pt.downsample(freq, anchor=anchor, calendar=cal)
rtrn_reindex = df[s].pt.reindex_to_calendar(cal)
assert_frame_equal(rtrn.dropna(how="all"), rtrn_reindex)
Expand Down
Loading
Loading