From c2bb19d8cfbfa2e375c39c960cc7315f43717965 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Sun, 4 Aug 2024 15:24:55 -0700 Subject: [PATCH 1/7] GH 927 Allow 'integer' in select_dtypes include argument --- pandas-stubs/core/frame.pyi | 1 + tests/test_frame.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 20879b000..8607343c7 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -624,6 +624,7 @@ class DataFrame(NDFrame, OpsMixin): "number", "datetime64", "datetime", + "integer", "timedelta", "timedelta64", "datetimetz", diff --git a/tests/test_frame.py b/tests/test_frame.py index 4b68f391c..32f23e240 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -3226,6 +3226,7 @@ def test_convert_dtypes_dtype_backend() -> None: def test_select_dtypes() -> None: df = pd.DataFrame({"a": [1, 2] * 3, "b": [True, False] * 3, "c": [1.0, 2.0] * 3}) check(assert_type(df.select_dtypes("number"), pd.DataFrame), pd.DataFrame) + check(assert_type(df.select_dtypes("integer"), pd.DataFrame), pd.DataFrame) check(assert_type(df.select_dtypes(np.number), pd.DataFrame), pd.DataFrame) check(assert_type(df.select_dtypes(object), pd.DataFrame), pd.DataFrame) check(assert_type(df.select_dtypes(include="bool"), pd.DataFrame), pd.DataFrame) From df7dad9275d780cba1c2c1d413c42c8c7e775d32 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Tue, 6 Aug 2024 16:32:24 -0700 Subject: [PATCH 2/7] TypeGuard clean up in dtypes/missing.pyi --- pandas-stubs/core/dtypes/missing.pyi | 6 +++--- tests/test_pandas.py | 27 ++++++++------------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/pandas-stubs/core/dtypes/missing.pyi b/pandas-stubs/core/dtypes/missing.pyi index 22bf8edd8..11319304d 100644 --- a/pandas-stubs/core/dtypes/missing.pyi +++ b/pandas-stubs/core/dtypes/missing.pyi @@ -10,7 +10,7 @@ from pandas import ( Index, Series, ) -from typing_extensions import TypeGuard +from typing_extensions import TypeIs from pandas._libs.missing import NAType from pandas._libs.tslibs import NaTType @@ -32,7 +32,7 @@ def isna(obj: Index[Any] | list[Any] | ArrayLike) -> npt.NDArray[np.bool_]: ... @overload def isna( obj: Scalar | NaTType | NAType | None, -) -> TypeGuard[NaTType | NAType | None]: ... +) -> TypeIs[NaTType | NAType | None]: ... isnull = isna @@ -43,6 +43,6 @@ def notna(obj: Series[Any]) -> Series[bool]: ... @overload def notna(obj: Index[Any] | list[Any] | ArrayLike) -> npt.NDArray[np.bool_]: ... @overload -def notna(obj: ScalarT | NaTType | NAType | None) -> TypeGuard[ScalarT]: ... +def notna(obj: ScalarT | NaTType | NAType | None) -> TypeIs[ScalarT]: ... notnull = notna diff --git a/tests/test_pandas.py b/tests/test_pandas.py index e72538673..04439323e 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -366,52 +366,41 @@ def test_isna() -> None: assert check(assert_type(pd.isna(np_nat), bool), bool) assert not check(assert_type(pd.notna(np_nat), bool), bool) - # Check TypeGuard type narrowing functionality - # TODO: Due to limitations in TypeGuard spec, the true annotations are not always viable - # and as a result the type narrowing does not always work as it intuitively should - # There is a proposal being floated for a StrictTypeGuard that will have more rigid narrowing semantics - # In the test cases below, a commented out assertion will be included to document the optimal test result + # Check TypeIs type narrowing functionality nullable1: str | None | NAType | NaTType = random.choice( ["value", None, pd.NA, pd.NaT] ) if pd.notna(nullable1): check(assert_type(nullable1, str), str) if not pd.isna(nullable1): - # check(assert_type(nullable1, str), str) # TODO: Desired result (see comments above) - check(assert_type(nullable1, Union[str, NaTType, NAType, None]), str) + check(assert_type(nullable1, str), str) if pd.isna(nullable1): assert_type(nullable1, Union[NaTType, NAType, None]) if not pd.notna(nullable1): - # assert_type(nullable1, Union[NaTType, NAType, None]) # TODO: Desired result (see comments above) - assert_type(nullable1, Union[str, NaTType, NAType, None]) + assert_type(nullable1, Union[NaTType, NAType, None]) nullable2: int | None = random.choice([2, None]) if pd.notna(nullable2): check(assert_type(nullable2, int), int) if not pd.isna(nullable2): - # check(assert_type(nullable2, int), int) # TODO: Desired result (see comments above) - check(assert_type(nullable2, Union[int, None]), int) + check(assert_type(nullable2, int), int) if pd.isna(nullable2): - # check(assert_type(nullable2, None), type(None)) # TODO: Desired result (see comments above) - check(assert_type(nullable2, Union[NaTType, NAType, None]), type(None)) + check(assert_type(nullable2, None), type(None)) if not pd.notna(nullable2): - # check(assert_type(nullable2, None), type(None)) # TODO: Desired result (see comments above) + check(assert_type(nullable2, None), type(None)) # TODO: MyPy and Pyright produce conflicting results: # assert_type(nullable2, Union[int, None]) # MyPy result # assert_type( # nullable2, Union[int, NaTType, NAType, None] # ) # Pyright result - pass nullable3: bool | None | NAType = random.choice([True, None, pd.NA]) if pd.notna(nullable3): check(assert_type(nullable3, bool), bool) if not pd.isna(nullable3): - # check(assert_type(nullable3, bool), bool) # TODO: Desired result (see comments above) - check(assert_type(nullable3, Union[bool, NAType, None]), bool) + check(assert_type(nullable3, bool), bool) if pd.isna(nullable3): - # assert_type(nullable3, Union[NAType, None]) # TODO: Desired result (see comments above) - assert_type(nullable3, Union[NaTType, NAType, None]) + assert_type(nullable3, Union[NAType, None]) if not pd.notna(nullable3): # assert_type(nullable3, Union[NAType, None]) # TODO: Desired result (see comments above) # TODO: MyPy and Pyright produce conflicting results: From edfdef14a91eea520fbeddfecef83a4b48432e54 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Tue, 6 Aug 2024 16:46:03 -0700 Subject: [PATCH 3/7] PR Feedback --- tests/test_pandas.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 04439323e..3cd36af71 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -388,11 +388,6 @@ def test_isna() -> None: check(assert_type(nullable2, None), type(None)) if not pd.notna(nullable2): check(assert_type(nullable2, None), type(None)) - # TODO: MyPy and Pyright produce conflicting results: - # assert_type(nullable2, Union[int, None]) # MyPy result - # assert_type( - # nullable2, Union[int, NaTType, NAType, None] - # ) # Pyright result nullable3: bool | None | NAType = random.choice([True, None, pd.NA]) if pd.notna(nullable3): @@ -402,13 +397,7 @@ def test_isna() -> None: if pd.isna(nullable3): assert_type(nullable3, Union[NAType, None]) if not pd.notna(nullable3): - # assert_type(nullable3, Union[NAType, None]) # TODO: Desired result (see comments above) - # TODO: MyPy and Pyright produce conflicting results: - # assert_type(nullable3, Union[bool, NAType, None]) # Mypy result - # assert_type( - # nullable3, Union[bool, NaTType, NAType, None] - # ) # Pyright result - pass + assert_type(nullable3, Union[NAType, None]) # GH 55 From a7a4d45fb2d4a1764978f04e8b52e0cf15d3052c Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Wed, 7 Aug 2024 11:10:23 -0700 Subject: [PATCH 4/7] Restore pandas nightly CI build --- tests/test_frame.py | 56 +++++++++++++++++++++++++++++++++++------ tests/test_indexes.py | 31 +++++++++++++++++++---- tests/test_pandas.py | 16 ++++++++++-- tests/test_scalars.py | 36 ++++++++++++++++++++------ tests/test_timefuncs.py | 8 +++--- tests/test_utility.py | 3 ++- 6 files changed, 125 insertions(+), 25 deletions(-) diff --git a/tests/test_frame.py b/tests/test_frame.py index 32f23e240..d401575e1 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1446,7 +1446,13 @@ def test_types_to_html() -> None: def test_types_resample() -> None: df = pd.DataFrame({"values": [2, 11, 3, 13, 14, 18, 17, 19]}) df["date"] = pd.date_range("01/01/2018", periods=8, freq="W") - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): df.resample("M", on="date") df.resample("20min", origin="epoch", offset=pd.Timedelta(2, "minutes"), on="date") df.resample("20min", origin="epoch", offset=datetime.timedelta(2), on="date") @@ -1583,7 +1589,13 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: assert isinstance(resampler, Resampler) return pd.DataFrame(resampler) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): val = ( pd.DataFrame( { @@ -1595,6 +1607,17 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: .resample("M", on="week_starting") .pipe(resampler_foo) ) + val = ( + pd.DataFrame( + { + "price": [10, 11, 9, 13, 14, 18, 17, 19], + "volume": [50, 60, 40, 100, 50, 100, 40, 50], + } + ) + .assign(week_starting=pd.date_range("01/01/2018", periods=8, freq="W")) + .resample("ME", on="week_starting") + .pipe(resampler_foo) + ) def foo(df: pd.DataFrame) -> pd.DataFrame: return pd.DataFrame(df) @@ -1854,11 +1877,22 @@ def test_types_regressions() -> None: d: datetime.date = pd.Timestamp("2021-01-01") tslist: list[pd.Timestamp] = list(pd.to_datetime(["2022-01-01", "2022-01-02"])) sseries: pd.Series = pd.Series(tslist) - sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "d") + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + sseries + pd.Timedelta(1, "d") + + sseries_plus1: pd.Series = sseries + pd.Timedelta(1, "D") # https://github.com/microsoft/pylance-release/issues/2133 - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): - dr = pd.date_range(start="2021-12-01", periods=24, freq="H") + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + pd.date_range(start="2021-12-01", periods=24, freq="H") + + dr = pd.date_range(start="2021-12-01", periods=24, freq="h") time = dr.strftime("%H:%M:%S") # https://github.com/microsoft/python-type-stubs/issues/115 @@ -2885,8 +2919,16 @@ def test_quantile_150_changes() -> None: def test_resample_150_changes() -> None: idx = pd.date_range("2020-1-1", periods=700) frame = pd.DataFrame(np.random.standard_normal((700, 1)), index=idx, columns=["a"]) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): - resampler = frame.resample("M", group_keys=True) + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + frame.resample("M", group_keys=True) + + resampler = frame.resample("MS", group_keys=True) check( assert_type(resampler, "DatetimeIndexResampler[pd.DataFrame]"), DatetimeIndexResampler, diff --git a/tests/test_indexes.py b/tests/test_indexes.py index e59fc0ca3..85edc3b57 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -259,7 +259,13 @@ def test_interval_range(): pd.IntervalIndex, pd.Interval, ) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.interval_range( @@ -577,9 +583,18 @@ def test_interval_index_arrays(): pd.IntervalIndex, pd.Interval, ) - with pytest_warns_bounded(FutureWarning, "'Y' is deprecated", lower="2.1.99"): - left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y")) - right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y")) + with pytest_warns_bounded( + FutureWarning, + "'Y' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): + pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="Y")) + pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="Y")) + + left_s_ts = pd.Series(pd.date_range("2000-01-01", "2003-01-01", freq="YS")) + right_s_ts = pd.Series(pd.date_range("2001-01-01", "2004-01-01", freq="YS")) check( assert_type( pd.IntervalIndex.from_arrays(left_s_ts, right_s_ts), @@ -989,7 +1004,13 @@ def test_index_constructors(): def test_iter() -> None: # GH 723 - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): for ts in pd.date_range(start="1/1/2023", end="1/08/2023", freq="6H"): check(assert_type(ts, pd.Timestamp), pd.Timestamp) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 3cd36af71..cafa4fba5 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1980,7 +1980,13 @@ def g(x: pd.Series) -> int: }, index=idx, ) - with pytest_warns_bounded(FutureWarning, "'M' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'M' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.pivot_table( @@ -1990,7 +1996,13 @@ def g(x: pd.Series) -> int: ), pd.DataFrame, ) - with pytest_warns_bounded(FutureWarning, "'(M|A)' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'(M|A)' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type( pd.pivot_table( diff --git a/tests/test_scalars.py b/tests/test_scalars.py index 70479da79..30315a22d 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -386,9 +386,11 @@ def test_interval_cmp(): def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta(1, "w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta(1, "d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta(1, "hours"), pd.Timedelta), pd.Timedelta) @@ -421,9 +423,11 @@ def test_timedelta_construction() -> None: check(assert_type(pd.Timedelta(1, "nanosecond"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta("1 w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.Timedelta("1 d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.Timedelta("1 hours"), pd.Timedelta), pd.Timedelta) @@ -1518,7 +1522,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.round("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.round("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated ", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated ", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.round("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, @@ -1553,7 +1563,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.ceil("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.ceil("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.ceil("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, @@ -1587,7 +1603,13 @@ def test_timestamp_misc_methods() -> None: check(assert_type(ts2.floor("1s", ambiguous=False), pd.Timestamp), pd.Timestamp) check(assert_type(ts2.floor("1s", ambiguous="NaT"), pd.Timestamp), pd.Timestamp) - with pytest_warns_bounded(FutureWarning, "'H' is deprecated", lower="2.1.99"): + with pytest_warns_bounded( + FutureWarning, + "'H' is deprecated", + lower="2.1.99", + upper="2.2.99", + upper_exception=ValueError, + ): check( assert_type(ts2.floor("2H", nonexistent="shift_forward"), pd.Timestamp), pd.Timestamp, diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index a61bb92ca..eabbc3707 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -757,11 +757,13 @@ def test_types_to_numpy() -> None: check(assert_type(td_s.to_numpy(na_value=pd.Timedelta(0)), np.ndarray), np.ndarray) -def test_to_timdelta_units() -> None: +def test_to_timedelta_units() -> None: check(assert_type(pd.to_timedelta(1, "W"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'w' is deprecated", lower="2.2.99"): + check(assert_type(pd.to_timedelta(1, "w"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "D"), pd.Timedelta), pd.Timedelta) - check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta) + with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"): + check(assert_type(pd.to_timedelta(1, "d"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "days"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "day"), pd.Timedelta), pd.Timedelta) check(assert_type(pd.to_timedelta(1, "hours"), pd.Timedelta), pd.Timedelta) diff --git a/tests/test_utility.py b/tests/test_utility.py index beb3d7592..3d668daaa 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -10,6 +10,7 @@ from tests import ( NUMPY20, + PD_LTE_22, check, pytest_warns_bounded, ) @@ -23,7 +24,7 @@ def test_show_version(): version_str=platform.python_version(), ): context: AbstractContextManager - if NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 + if PD_LTE_22 and NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 context = pytest.raises(ValueError) else: context = nullcontext() From 370433f296730e94ef81ef3133d75a021111f0d1 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Wed, 7 Aug 2024 11:20:37 -0700 Subject: [PATCH 5/7] Correct freq in test --- tests/test_frame.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_frame.py b/tests/test_frame.py index d401575e1..a8b03e76f 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1596,7 +1596,7 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: upper="2.2.99", upper_exception=ValueError, ): - val = ( + ( pd.DataFrame( { "price": [10, 11, 9, 13, 14, 18, 17, 19], @@ -1607,6 +1607,7 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: .resample("M", on="week_starting") .pipe(resampler_foo) ) + val = ( pd.DataFrame( { @@ -1615,7 +1616,7 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame: } ) .assign(week_starting=pd.date_range("01/01/2018", periods=8, freq="W")) - .resample("ME", on="week_starting") + .resample("MS", on="week_starting") .pipe(resampler_foo) ) From fd0c3f5e73ba4049c4fd978bee7ed3e377d8c6c8 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Wed, 7 Aug 2024 12:29:39 -0700 Subject: [PATCH 6/7] Attempt to fix issue with show_versions and pandas>=3.0.0 --- tests/test_utility.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/tests/test_utility.py b/tests/test_utility.py index 3d668daaa..e18423ed6 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -17,20 +17,26 @@ def test_show_version(): - with pytest_warns_bounded( - UserWarning, - match="Setuptools is replacing distutils", - upper="3.11.99", - version_str=platform.python_version(), - ): - context: AbstractContextManager - if PD_LTE_22 and NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 - context = pytest.raises(ValueError) - else: - context = nullcontext() - with context: - check(assert_type(pd.show_versions(True), None), type(None)) - check(assert_type(pd.show_versions(False), None), type(None)) + """Test show_versions method types with split case for pandas and python versions.""" + if PD_LTE_22: + # distutils warning is only raised with pandas<3.0.0 + with pytest_warns_bounded( + UserWarning, + match="Setuptools is replacing distutils", + upper="3.11.99", + version_str=platform.python_version(), + ): + context: AbstractContextManager + if NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 + context = pytest.raises(ValueError) + else: + context = nullcontext() + with context: + check(assert_type(pd.show_versions(True), None), type(None)) + check(assert_type(pd.show_versions(False), None), type(None)) + else: + check(assert_type(pd.show_versions(True), None), type(None)) + check(assert_type(pd.show_versions(False), None), type(None)) def test_dummies(): From c0e6a1de8356af1201295de9d5b54511bfa0b7b5 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Wed, 7 Aug 2024 12:29:39 -0700 Subject: [PATCH 7/7] Attempt to fix issue with show_versions and pandas>=3.0.0 --- tests/test_utility.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/test_utility.py b/tests/test_utility.py index 3d668daaa..51cb31ccb 100644 --- a/tests/test_utility.py +++ b/tests/test_utility.py @@ -1,7 +1,4 @@ -from contextlib import ( - AbstractContextManager, - nullcontext, -) +from contextlib import nullcontext import platform import pandas as pd @@ -17,17 +14,25 @@ def test_show_version(): - with pytest_warns_bounded( - UserWarning, - match="Setuptools is replacing distutils", - upper="3.11.99", - version_str=platform.python_version(), - ): - context: AbstractContextManager - if PD_LTE_22 and NUMPY20: # https://github.com/PyTables/PyTables/issues/1172 + """Test show_versions method types with split case for pandas and python versions.""" + # https://github.com/PyTables/PyTables/issues/1172 + context = nullcontext() + if PD_LTE_22: + # distutils warning is only raised with pandas<3.0.0 + if NUMPY20: context = pytest.raises(ValueError) - else: - context = nullcontext() + with ( + pytest_warns_bounded( + UserWarning, + match="Setuptools is replacing distutils", + upper="3.11.99", + version_str=platform.python_version(), + ), + context, + ): + check(assert_type(pd.show_versions(True), None), type(None)) + check(assert_type(pd.show_versions(False), None), type(None)) + else: with context: check(assert_type(pd.show_versions(True), None), type(None)) check(assert_type(pd.show_versions(False), None), type(None))