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: 2 additions & 0 deletions .agents/skills/dependencies-management/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Any failing tests and fixable warnings will likely have their origin in changes

As a general RULE, **change the package code to get the tests passing, not the test code!** You may make changes to the test code only with good reason and only when this does not impair the test's efficacy.

One such reason is a test failure that arises because a new version of `exchange_calendars` corrects a calendar that stored test resources were created with. Fix such a failure by reverting the correction in the class of `tests/utils.py` that reproduces the calendar as at an earlier version (for example `CMESAsAt4132`), and list the change in that class's docstring. If `tests/utils.py` has no such class for the calendar, add one that follows the pattern of the existing classes. Do not edit the stored resources to agree with the corrected calendar.

To facilitate identifying the cause of test failures consider researching the changelogs of updated dependencies for versions released since the previously locked version.

Iterate on this process until:
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
11 changes: 6 additions & 5 deletions 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 Expand Up @@ -2194,13 +2195,13 @@ def downsample(
against `calendar`, one indice per session will represent
a partial trading indice. Any data falling within a break
or between a session close and the following session open
will be consolidated to non-trading indices (when evaluate
will be consolidated to non-trading indices (when evaluated
against `calendar`).

When there is no data immediately following a session close
although there is subsequently data prior to the next
session open, indices in between will be included and
filled with missing values (session's evalutated against
filled with missing values (sessions evaluated against
`calendar`). The introduction of these 'missing values'
indices can be avoided by passing a `composite_calendar`.

Expand All @@ -2217,12 +2218,12 @@ def downsample(
True: Curtail final rows of base table in order that
downsampled indice is evaluated from a full interval of
data, i.e. if the resampled interval is 60 minutes then the
final interval will be evaluated from 60 mintues of base
final interval will be evaluated from 60 minutes of base
data, albeit at the cost that any excess rows at the
end of the base table will be excluded from the downsampled
data.
False: Include all final rows in the resampled data. This may
result in the final indice being evaluted from fewer
result in the final indice being evaluated from fewer
minutes of data than the interval length, e.g. if the
table interval is 60 minutes then the final indice of
the resampled table may have been evaluated from only, for
Expand Down
11 changes: 9 additions & 2 deletions tests/test_base_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
from market_prices.prices import csv
from market_prices.support import tutorial_helpers as th

from .utils import RESOURCES_PATH, clean_temp_test_dir, get_resource_pbt
from .utils import (
RESOURCES_PATH,
XHKGAsAt4132,
clean_temp_test_dir,
get_resource_pbt,
)

# ruff: noqa: PLW0127 # self-assigning-variable serves role in some tests here

Expand Down Expand Up @@ -6276,10 +6281,12 @@ def calendars(symbols) -> abc.Iterator[dict[str, str]]:
calendars = {
"MSFT": "XNYS",
"AZN.L": "XLON",
"9988.HK": "XHKG",
"9988.HK": "XHKG_4132",
}
assert set(symbols) == set(calendars)
xcals.register_calendar_type(calendars["9988.HK"], XHKGAsAt4132)
yield calendars
xcals.deregister_calendar(calendars["9988.HK"])


def test_to_csv(to_csv_dir, temp_dir, symbols, calendars, one_day):
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
Loading
Loading