From 4fae83aacd7b116719232828b7402516e6749bd3 Mon Sep 17 00:00:00 2001 From: Marcus Read Date: Sun, 22 Sep 2024 21:17:33 +0100 Subject: [PATCH] Reinstate xfail on `test_monthly_freq` Pandas fix yet to be included to a release - see comments in code by test. Also: - corrects typing of decorated hypothesis strategies. - updates `test_yahoo` flaky list --- tests/hypstrtgy.py | 66 ++++++++++++++----------------------------- tests/test_helpers.py | 6 ++++ tests/test_pt.py | 6 ++++ tests/test_yahoo.py | 3 ++ 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/tests/hypstrtgy.py b/tests/hypstrtgy.py index 1af947a..435d5c5 100644 --- a/tests/hypstrtgy.py +++ b/tests/hypstrtgy.py @@ -68,7 +68,7 @@ def calendar_session( draw, calendar_name: str, limit: tuple[pd.Timestamp | None, pd.Timestamp | None] = (None, None), -) -> st.SearchStrategy[pd.Timestamp]: +) -> pd.Timestamp: """Return strategy to generate a session for a given calendar. Parameters @@ -96,7 +96,7 @@ def calendar_start_end_sessions( limit: tuple[pd.Timestamp | None, pd.Timestamp | None] = (None, None), min_dist: int | pd.Timedelta = 0, max_dist: int | pd.Timedelta | None = None, -) -> st.SearchStrategy[tuple[pd.Timestamp, pd.Timestamp]]: +) -> tuple[pd.Timestamp, pd.Timestamp]: """Return strategy to generate a start and end session for a given calendar. Parameters @@ -163,7 +163,7 @@ def start_minutes( draw, calendar_name: str, limit: tuple[pd.Timestamp | None, pd.Timestamp | None] = (None, None), -) -> st.SearchStrategy[pd.Timestamp]: +) -> pd.Timestamp: """Return strategy to generate a 'start' minute for a given calendar. Minute will represent a trading minute (not a close). @@ -211,7 +211,7 @@ def end_minutes( draw, calendar_name: str, limit: tuple[pd.Timestamp | None, pd.Timestamp | None] = (None, None), -) -> st.SearchStrategy[pd.Timestamp]: +) -> pd.Timestamp: """Return strategy to generate an 'end' minute for a given calendar. Minute will represent a trading minute, excluding open minutes, or a @@ -267,7 +267,7 @@ def end_minutes( def calendar_start_end_minutes( draw, calendar_name: str, -) -> st.SearchStrategy[tuple[pd.Timestamp, pd.Timestamp]]: +) -> tuple[pd.Timestamp, pd.Timestamp]: """Return strategy to generate a start and end minute for a given calendar. 'start' will be a trading minute. @@ -297,9 +297,7 @@ def get_pp_default() -> dict[str, typing.Any]: @st.composite -def pp_start_end_sessions( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_start_end_sessions(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate period parameters with 'start' and 'end' only. 'start' and 'end' will both be sessions of `calendar`. @@ -312,9 +310,7 @@ def pp_start_end_sessions( @st.composite -def pp_end_minute_only( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_end_minute_only(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate period parameters with 'end' only. 'end' will be a trading minute or a close minute of `calendar_name`. @@ -327,9 +323,7 @@ def pp_end_minute_only( @st.composite -def pp_start_end_minutes( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_start_end_minutes(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate period parameters with 'start' and 'end' only. 'start' will be a trading minute, 'end' will be a trading minute or a @@ -344,7 +338,7 @@ def pp_start_end_minutes( @st.composite -def pp_days(draw, calendar_name: str) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_days(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'days'. @@ -374,7 +368,7 @@ def pp_days_start_session( draw, calendar_name: str, start_will_roll_to_ms: bool = False, -) -> st.SearchStrategy[dict[str, typing.Any]]: +) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'days'. @@ -411,9 +405,7 @@ def pp_days_start_session( @st.composite -def pp_days_end_session( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_days_end_session(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'days'. @@ -438,9 +430,7 @@ def pp_days_end_session( @st.composite -def pp_days_start_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_days_start_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'days'. @@ -461,9 +451,7 @@ def pp_days_start_minute( @st.composite -def pp_days_end_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_days_end_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'days'. @@ -481,7 +469,7 @@ def pp_days_end_minute( @st.composite -def pp_caldur(draw) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_caldur(draw) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. duration defined in 'weeks' and/or 'months' and/or 'years' (i.e. @@ -500,9 +488,7 @@ def pp_caldur(draw) -> st.SearchStrategy[dict[str, typing.Any]]: @st.composite -def pp_caldur_start_session( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_caldur_start_session(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'weeks' and/or 'months' and/or 'years' (i.e. @@ -530,9 +516,7 @@ def pp_caldur_start_session( @st.composite -def pp_caldur_end_session( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_caldur_end_session(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'weeks' and/or 'months' and/or 'years' (i.e. @@ -568,9 +552,7 @@ def pp_caldur_end_session( @st.composite -def pp_caldur_start_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_caldur_start_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'weeks' and/or 'months' and/or 'years' (i.e. @@ -598,9 +580,7 @@ def pp_caldur_start_minute( @st.composite -def pp_caldur_end_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_caldur_end_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'weeks' and/or 'months' and/or 'years' (i.e. @@ -619,7 +599,7 @@ def pp_caldur_end_minute( @st.composite -def pp_intraday(draw) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_intraday(draw) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'minutes' and/or 'hours' (i.e. in trading @@ -637,9 +617,7 @@ def pp_intraday(draw) -> st.SearchStrategy[dict[str, typing.Any]]: @st.composite -def pp_intraday_start_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_intraday_start_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'minutes' and/or 'hours' (i.e. in trading @@ -660,9 +638,7 @@ def pp_intraday_start_minute( @st.composite -def pp_intraday_end_minute( - draw, calendar_name: str -) -> st.SearchStrategy[dict[str, typing.Any]]: +def pp_intraday_end_minute(draw, calendar_name: str) -> dict[str, typing.Any]: """Return strategy to generate specific arrangment of period parameters. - duration defined in 'minutes' and/or 'hours' (i.e. in trading diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 0256377..4b0d0ac 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -310,6 +310,12 @@ def test_volume_to_na(intraday_pt, intraday_pt_ss): assert_frame_equal(rtrn, df) +# TODO Remove xfail when pandas >3 or fix otherwise released +# NB pd bug manifests in test, not package (manifests where evaluate +# `expected_ooo.index = df[::12]`) +# pandas issue ref is https://github.com/pandas-dev/pandas/issues/58604 +# https://github.com/pandas-dev/pandas/pull/58043, related PR, ya merged to dev +@pytest.mark.xfail(reason="Known pd issue with py3.12, should resolve with pd>3.0") def test_resample(intraday_pt): """Test `resample`. diff --git a/tests/test_pt.py b/tests/test_pt.py index fd98771..a37fcfe 100644 --- a/tests/test_pt.py +++ b/tests/test_pt.py @@ -2140,6 +2140,12 @@ def test_cbday_freq(self, daily_pt_ss, xnys): df.pt.downsample("3d", xnys), ) + # TODO Remove xfail when pandas >3 or fix otherwise released + # NB pd bug manifests in test, not package (manifests where takes a slice to + # evaluate 'subset'). + # pandas issue ref is https://github.com/pandas-dev/pandas/issues/58604 + # https://github.com/pandas-dev/pandas/pull/58043, related PR, ya merged to dev + @pytest.mark.xfail(reason="Known pd issue with py3.12, should resolve with pd>3.0") def test_monthly_freq(self, daily_pt, xnys, x247, one_day, symbols): """Verify "MS" and "QS" frequencies.""" df = daily_pt diff --git a/tests/test_yahoo.py b/tests/test_yahoo.py index 6276773..0f54530 100644 --- a/tests/test_yahoo.py +++ b/tests/test_yahoo.py @@ -46,6 +46,9 @@ # ...sessions that yahoo temporarily fails to return prices for if (seemingly) # send a high frequency of requests for prices from the same IP address. _flakylist = ( + pd.Timestamp("2024-08-26"), + pd.Timestamp("2024-08-25"), + pd.Timestamp("2024-08-24"), pd.Timestamp("2024-05-28"), pd.Timestamp("2024-05-27"), pd.Timestamp("2024-01-21"),