diff --git a/pandas-stubs/core/algorithms.pyi b/pandas-stubs/core/algorithms.pyi index 5f749a1b0..4d8905d6b 100644 --- a/pandas-stubs/core/algorithms.pyi +++ b/pandas-stubs/core/algorithms.pyi @@ -23,9 +23,7 @@ from pandas._typing import ( ShapeT, TakeIndexer, np_1darray, - np_1darray_dt, np_1darray_int64, - np_1darray_td, np_ndarray, ) @@ -38,18 +36,17 @@ def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... @overload def unique(values: PeriodIndex) -> PeriodIndex: ... @overload -# switch to DatetimeIndex after Pandas 3.0 -def unique(values: DatetimeIndex) -> np_1darray_dt | DatetimeIndex: ... +def unique(values: DatetimeIndex) -> DatetimeIndex: ... @overload -# switch to TimedeltaIndex after Pandas 3.0 -def unique(values: TimedeltaIndex) -> np_1darray_td: ... +def unique(values: TimedeltaIndex) -> TimedeltaIndex: ... @overload -# switch to Index[int] after Pandas 3.0 -def unique(values: RangeIndex) -> np_1darray_int64: ... +def unique(values: RangeIndex) -> Index[int]: ... @overload -def unique(values: MultiIndex) -> np_ndarray: ... +def unique( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] + values: MultiIndex, +) -> np_ndarray: ... @overload -def unique(values: Index) -> np_1darray | Index: ... # switch to Index after Pandas 3.0 +def unique(values: Index) -> Index: ... @overload def unique(values: Categorical) -> Categorical: ... diff --git a/pandas-stubs/core/arrays/datetimes.pyi b/pandas-stubs/core/arrays/datetimes.pyi index 6ef3c6527..b3c7477a4 100644 --- a/pandas-stubs/core/arrays/datetimes.pyi +++ b/pandas-stubs/core/arrays/datetimes.pyi @@ -8,6 +8,7 @@ from pandas.core.arrays.datetimelike import ( TimelikeOps, ) from pandas.core.arrays.period import PeriodArray +from pandas.core.arrays.string_ import BaseStringArray from pandas.core.indexes.datetimes import DatetimeIndex from pandas.core.series import Series @@ -62,10 +63,8 @@ class DatetimeArray(TimelikeOps, DatelikeOps): def to_pydatetime(self) -> np_1darray_object: ... def normalize(self) -> Self: ... def to_period(self, freq: Frequency | None = None) -> PeriodArray: ... - # TODO: BaseStringArray after Pandas 3.0 pandas-dev/pandas#57064 - def month_name(self, locale: str | None = None) -> np_1darray_object: ... - # TODO: BaseStringArray after Pandas 3.0 pandas-dev/pandas#57064 - def day_name(self, locale: str | None = None) -> np_1darray_object: ... + def month_name(self, locale: str | None = None) -> BaseStringArray: ... + def day_name(self, locale: str | None = None) -> BaseStringArray: ... @property def time(self) -> np_1darray_object: ... @property diff --git a/pandas-stubs/core/frame.pyi b/pandas-stubs/core/frame.pyi index 1397fdd35..3ce323cbc 100644 --- a/pandas-stubs/core/frame.pyi +++ b/pandas-stubs/core/frame.pyi @@ -813,7 +813,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): self, expr: _str, *, - inplace: Literal[False] = False, parser: Literal["pandas", "python"] = ..., engine: Literal["python", "numexpr"] | None = ..., local_dict: dict[_str, Any] | None = ..., @@ -821,6 +820,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): resolvers: MutableSequence[Mapping[Any, Any]] | None = ..., level: int = ..., target: object | None = ..., + inplace: Literal[False] = False, ) -> Self: ... @overload def eval(self, expr: _str, *, inplace: Literal[True], **kwargs: Any) -> None: ... @@ -889,20 +889,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): limit: int | None = None, tolerance: float | Timedelta | None = ..., ) -> Self: ... - @overload - def rename( - self, - mapper: Renamer | None = ..., - *, - index: Renamer | None = ..., - columns: Renamer | None = ..., - axis: Axis | None = ..., - copy: bool = ..., - inplace: Literal[True], - level: Level | None = None, - errors: IgnoreRaise = ..., - ) -> None: ... - @overload def rename( self, mapper: Renamer | None = ..., @@ -911,46 +897,24 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): columns: Renamer | None = ..., axis: Axis | None = ..., copy: bool = ..., - inplace: Literal[False] = False, + inplace: bool = False, level: Level | None = None, errors: IgnoreRaise = ..., ) -> Self: ... - @overload - def fillna( - self, - value: Scalar | NAType | dict[Any, Any] | Series | DataFrame | None = ..., - *, - axis: Axis | None = ..., - limit: int = ..., - inplace: Literal[True], - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def fillna( self, value: Scalar | NAType | dict[Any, Any] | Series | DataFrame | None = ..., *, axis: Axis | None = ..., limit: int = ..., - inplace: Literal[False] = False, + inplace: bool = False, ) -> Self: ... - @overload - def replace( - self, - to_replace: ReplaceValue | Mapping[HashableT2, ReplaceValue] = ..., - value: ReplaceValue | Mapping[HashableT3, ReplaceValue] = ..., - *, - inplace: Literal[True], - regex: ReplaceValue | Mapping[HashableT3, ReplaceValue] = ..., - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def replace( self, to_replace: ReplaceValue | Mapping[HashableT2, ReplaceValue] = ..., value: ReplaceValue | Mapping[HashableT3, ReplaceValue] = ..., *, - inplace: Literal[False] = False, + inplace: bool = False, regex: ReplaceValue | Mapping[HashableT3, ReplaceValue] = ..., ) -> Self: ... def shift( @@ -1373,20 +1337,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): observed: _bool = True, sort: _bool = True, ) -> Self: ... - @overload def stack( self, level: IndexLabel = ..., - *, - future_stack: Literal[True], - ) -> Self | Series: ... - @overload - def stack( - self, - level: IndexLabel = ..., - dropna: _bool = ..., - sort: _bool = ..., - future_stack: Literal[False] = False, + future_stack: Literal[True] = True, ) -> Self | Series: ... def explode( self, column: Sequence[Hashable], ignore_index: _bool = False @@ -1942,22 +1896,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): inclusive: IntervalClosedType = "both", axis: Axis | None = 0, ) -> Self: ... - @overload - def bfill( - self, - *, - axis: Axis | None = None, - inplace: Literal[True], - limit: int | None = ..., - limit_area: Literal["inside", "outside"] | None = ..., - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def bfill( self, *, axis: Axis | None = None, - inplace: Literal[False] = False, + inplace: bool = False, limit: int | None = ..., limit_area: Literal["inside", "outside"] | None = ..., ) -> Self: ... @@ -1968,7 +1911,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): upper: float | None = ..., *, axis: Axis | None = ..., - inplace: Literal[False] = False, + inplace: bool = False, **kwargs: Any, ) -> Self: ... @overload @@ -1978,7 +1921,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): upper: AnyArrayLike | None = ..., *, axis: Axis = ..., - inplace: Literal[False] = False, + inplace: bool = False, **kwargs: Any, ) -> Self: ... @overload @@ -1988,52 +1931,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): upper: AnyArrayLike = ..., *, axis: Axis = ..., - inplace: Literal[False] = False, - **kwargs: Any, - ) -> Self: ... - @overload - def clip( # pyright: ignore[reportOverlappingOverload] - self, - lower: None = None, - upper: None = None, - *, - axis: Axis | None = ..., - inplace: Literal[True], + inplace: bool = False, **kwargs: Any, ) -> Self: ... - @overload - def clip( - self, - lower: float | None = ..., - upper: float | None = ..., - *, - axis: Axis | None = ..., - inplace: Literal[True], - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload - def clip( - self, - lower: AnyArrayLike = ..., - upper: AnyArrayLike | None = ..., - *, - axis: Axis = ..., - inplace: Literal[True], - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload - def clip( - self, - lower: AnyArrayLike | None = ..., - upper: AnyArrayLike = ..., - *, - axis: Axis = ..., - inplace: Literal[True], - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... @final def copy(self, deep: _bool = True) -> Self: ... def cummax( @@ -2109,22 +2009,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): axis: AxisIndex = 0, method: CalculationMethod = "single", ) -> Expanding[Self]: ... - @overload def ffill( self, *, axis: Axis | None = ..., - inplace: Literal[True], - limit: int | None = ..., - limit_area: Literal["inside", "outside"] | None = ..., - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload - def ffill( - self, - *, - axis: Axis | None = ..., - inplace: Literal[False] = False, + inplace: bool = False, limit: int | None = ..., limit_area: Literal["inside", "outside"] | None = ..., ) -> Self: ... @@ -2168,20 +2057,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): def head(self, n: int = 5) -> Self: ... @final def infer_objects(self, copy: _bool | None = ...) -> Self: ... - @overload - def interpolate( - self, - method: InterpolateOptions = ..., - *, - axis: Axis = 0, - limit: int | None = ..., - limit_direction: Literal["forward", "backward", "both"] = ..., - limit_area: Literal["inside", "outside"] | None = ..., - inplace: Literal[True], - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def interpolate( self, method: InterpolateOptions = ..., @@ -2190,7 +2065,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): limit: int | None = ..., limit_direction: Literal["forward", "backward", "both"] = ..., limit_area: Literal["inside", "outside"] | None = ..., - inplace: Literal[False] = False, + inplace: bool = False, **kwargs: Any, ) -> Self: ... def keys(self) -> Index: ... @@ -2222,24 +2097,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): axis: Axis = "columns", level: Level | None = None, ) -> Self: ... - @overload - def mask( - self, - cond: ( - Series - | DataFrame - | np_ndarray_bool - | Callable[[DataFrame], DataFrame] - | Callable[[Any], _bool] - ), - other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level | None = None, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def mask( self, cond: ( @@ -2250,8 +2107,8 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): | Callable[[Any], _bool] ), other: Scalar | Series | DataFrame | Callable[..., Any] | NAType | None = ..., + inplace: bool = False, *, - inplace: Literal[False] = False, axis: Axis | None = ..., level: Level | None = None, ) -> Self: ... @@ -2703,24 +2560,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): numeric_only: _bool = False, **kwargs: Any, ) -> Series: ... - @overload - def where( - self, - cond: ( - Series - | DataFrame - | np_ndarray_bool - | Callable[[DataFrame], DataFrame] - | Callable[[Any], _bool] - ), - other: Scalar | Self | Callable[..., Scalar | Self] = ..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level | None = None, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def where( self, cond: ( @@ -2732,7 +2571,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack): ), other: Scalar | Self | Callable[..., Scalar | Self] = ..., *, - inplace: Literal[False] = False, + inplace: bool = False, axis: Axis | None = ..., level: Level | None = None, ) -> Self: ... diff --git a/pandas-stubs/core/series.pyi b/pandas-stubs/core/series.pyi index 4d041398f..f763e525e 100644 --- a/pandas-stubs/core/series.pyi +++ b/pandas-stubs/core/series.pyi @@ -1255,42 +1255,21 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): limit: int | None = None, tolerance: Scalar | AnyArrayLike | Sequence[Scalar] | None = None, ) -> Self: ... - @overload - def fillna( - self, - value: Scalar | NAType | dict[Any, Any] | Series[S1] | DataFrame | None = ..., - *, - axis: AxisIndex = ..., - limit: int | None = ..., - inplace: Literal[True], - ) -> None: ... - @overload def fillna( self, value: Scalar | NAType | dict[Any, Any] | Series[S1] | DataFrame | None = ..., *, axis: AxisIndex = ..., limit: int | None = ..., - inplace: Literal[False] = False, + inplace: _bool = False, ) -> Series[S1]: ... - @overload - def replace( - self, - to_replace: ReplaceValue = ..., - value: ReplaceValue = ..., - *, - regex: ReplaceValue = ..., - inplace: Literal[True], - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload def replace( self, to_replace: ReplaceValue = ..., value: ReplaceValue = ..., *, regex: ReplaceValue = ..., - inplace: Literal[False] = False, + inplace: _bool = False, ) -> Series[S1]: ... def shift( self, @@ -1498,63 +1477,29 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): def copy(self, deep: _bool = True) -> Series[S1]: ... @final def infer_objects(self, copy: _bool = True) -> Series[S1]: ... - @overload - def ffill( - self, - *, - axis: AxisIndex | None = 0, - inplace: Literal[True], - limit: int | None = ..., - limit_area: Literal["inside", "outside"] | None = ..., - ) -> None: ... - @overload def ffill( self, *, axis: AxisIndex | None = 0, - inplace: Literal[False] = False, + inplace: _bool = False, limit: int | None = ..., limit_area: Literal["inside", "outside"] | None = ..., ) -> Series[S1]: ... - @overload def bfill( self, *, axis: AxisIndex | None = 0, - inplace: Literal[True], - limit: int | None = ..., - limit_area: Literal["inside", "outside"] | None = ..., - ) -> None: ... - @overload - def bfill( - self, - *, - axis: AxisIndex | None = 0, - inplace: Literal[False] = False, + inplace: _bool = False, limit: int | None = ..., limit_area: Literal["inside", "outside"] | None = ..., ) -> Series[S1]: ... - @overload def interpolate( self, method: InterpolateOptions = ..., *, axis: AxisIndex | None = 0, limit: int | None = ..., - inplace: Literal[True], - limit_direction: Literal["forward", "backward", "both"] | None = ..., - limit_area: Literal["inside", "outside"] | None = ..., - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload - def interpolate( - self, - method: InterpolateOptions = ..., - *, - axis: AxisIndex | None = 0, - limit: int | None = ..., - inplace: Literal[False] = False, + inplace: _bool = False, limit_direction: Literal["forward", "backward", "both"] | None = ..., limit_area: Literal["inside", "outside"] | None = ..., **kwargs: Any, @@ -1566,13 +1511,13 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): subset: None = None, ) -> Scalar | Series[S1]: ... @overload - def clip( # pyright: ignore[reportOverlappingOverload] + def clip( self, lower: None = None, upper: None = None, *, axis: AxisIndex | None = 0, - inplace: Literal[True], + inplace: _bool = False, **kwargs: Any, ) -> Self: ... @overload @@ -1582,18 +1527,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame): upper: AnyArrayLike | float | None = ..., *, axis: AxisIndex | None = 0, - inplace: Literal[True], - **kwargs: Any, - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - ) -> None: ... - @overload - def clip( - self, - lower: AnyArrayLike | float | None = ..., - upper: AnyArrayLike | float | None = ..., - *, - axis: AxisIndex | None = 0, - inplace: Literal[False] = False, + inplace: _bool = False, **kwargs: Any, ) -> Series[S1]: ... @final diff --git a/pandas-stubs/io/formats/style_render.pyi b/pandas-stubs/io/formats/style_render.pyi index 45409bdee..afe94bce4 100644 --- a/pandas-stubs/io/formats/style_render.pyi +++ b/pandas-stubs/io/formats/style_render.pyi @@ -15,7 +15,7 @@ from jinja2.environment import ( Environment, Template, ) -from jinja2.loaders import PackageLoader +from jinja2.loaders import FileSystemLoader from pandas import Index # The class is private in pandas implementation. We have to ignore the private usage in the stubs. @@ -51,7 +51,7 @@ CSSStyles: TypeAlias = list[CSSDict] Subset: TypeAlias = _IndexSlice | slice | tuple[slice, ...] | list[HashableT] | Index class StylerRenderer: - loader: PackageLoader + loader: FileSystemLoader env: Environment template_html: Template template_html_table: Template diff --git a/pyproject.toml b/pyproject.toml index ed945d13c..5ae690717 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,10 +34,11 @@ exclude = ["pandas-stubs/__init__.py"] python = ">=3.11" types-pytz = ">=2022.1.1" numpy = ">=1.23.5" +pytz = "^2025.2" [tool.poetry.group.dev.dependencies] mypy = ">=1.19.1" -pandas = "2.3.3" +pandas = "3.0.0" pyarrow = ">=10.0.1" pytest = ">=8.4.2" pyright = ">=1.1.408" diff --git a/tests/arrays/test_arrow_string_array.py b/tests/arrays/test_arrow_string_array.py index 8016efb5a..90cb5445a 100644 --- a/tests/arrays/test_arrow_string_array.py +++ b/tests/arrays/test_arrow_string_array.py @@ -14,7 +14,6 @@ from pandas._libs.missing import NAType from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) @@ -107,8 +106,7 @@ def test_dtype() -> None: check(assert_type(arr.dtype, "pd.StringDtype[Literal['pyarrow']]"), pd.StringDtype) assert assert_type(arr.dtype.storage, Literal["pyarrow"]) == "pyarrow" - if not PD_LTE_23: - # pandas-dev/pandas#63567 - arr_arrow = cast("ArrowStringArray", pd.array([pd.NA], str)) - check(assert_type(arr_arrow, ArrowStringArray), ArrowStringArray, float) - assert pd.isna(assert_type(arr_arrow.dtype.na_value, NAType | float)) + # TODO: pandas-dev/pandas#54466 should give BaseStringArray after 3.0 + arr_arrow = cast("ArrowStringArray", pd.array([pd.NA], str)) + check(assert_type(arr_arrow, ArrowStringArray), ArrowStringArray, float) + assert pd.isna(assert_type(arr_arrow.dtype.na_value, NAType | float)) diff --git a/tests/arrays/test_base_string_array.py b/tests/arrays/test_base_string_array.py index 891ac51eb..b81ead711 100644 --- a/tests/arrays/test_base_string_array.py +++ b/tests/arrays/test_base_string_array.py @@ -18,10 +18,7 @@ from pandas._libs.missing import NAType -from tests import ( - PD_LTE_23, - check, -) +from tests import check from tests._typing import PandasBaseStrDtypeArg from tests.dtypes import ( PANDAS_BASE_STRING_ARGS, @@ -80,23 +77,19 @@ def test_construction_dtype( target_dtype: type, ) -> None: is_builtin_str = dtype in PYTHON_STRING_ARGS - is_numpy_extension_array = PD_LTE_23 and is_builtin_str - # TODO: pandas-dev/pandas#54466 should give BaseStringArray after Pandas 3.0 - target_type = NumpyExtensionArray if is_numpy_extension_array else BaseStringArray dtype_notna = target_dtype if data else None - check(pd.array([*data], dtype), target_type, dtype_notna) - check(pd.array([*data, *data], dtype), target_type, dtype_notna) + check(pd.array([*data], dtype), BaseStringArray, dtype_notna) + check(pd.array([*data, *data], dtype), BaseStringArray, dtype_notna) dtype_na = ( target_dtype - # TODO: pandas-dev/pandas#54466 drop `or is_numpy_extension_array` after Pandas 3.0 - if data or is_numpy_extension_array + if data # pandas-dev/pandas#63567 Pandas 3.0 gives StringDtype(na_value=nan) if dtype is str or "str" else float if is_builtin_str else NAType ) - check(pd.array([*data, np.nan], dtype), target_type, dtype_na) - check(pd.array([*data, *data, np.nan], dtype), target_type, dtype_na) + check(pd.array([*data, np.nan], dtype), BaseStringArray, dtype_na) + check(pd.array([*data, *data, np.nan], dtype), BaseStringArray, dtype_na) if TYPE_CHECKING: # TODO: pandas-dev/pandas#54466 should give BaseStringArray after 3.0 diff --git a/tests/arrays/test_datetime_array.py b/tests/arrays/test_datetime_array.py index ad1f4d35c..e57e5abe6 100644 --- a/tests/arrays/test_datetime_array.py +++ b/tests/arrays/test_datetime_array.py @@ -24,7 +24,6 @@ from pandas._libs.tslibs.nattype import NaTType from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) @@ -239,14 +238,8 @@ def test_construction_dtype( def test_properties() -> None: arr = pd.array([datetime(1748, 12, 24)]) - check( - assert_type(arr.month_name(), np_1darray_object), - np_1darray_object if PD_LTE_23 else BaseStringArray, - ) - check( - assert_type(arr.day_name(), np_1darray_object), - np_1darray_object if PD_LTE_23 else BaseStringArray, - ) + check(assert_type(arr.month_name(), BaseStringArray), BaseStringArray) + check(assert_type(arr.day_name(), BaseStringArray), BaseStringArray) check(assert_type(arr.time, np_1darray_object), np_1darray_object, time) check(assert_type(arr.timetz, np_1darray_object), np_1darray_object, time) check(assert_type(arr.date, np_1darray_object), np_1darray_object, date) diff --git a/tests/arrays/test_floating.py b/tests/arrays/test_floating.py index 7d4a9fd97..98892cc77 100644 --- a/tests/arrays/test_floating.py +++ b/tests/arrays/test_floating.py @@ -15,11 +15,9 @@ FloatingArray, FloatingDtype, ) -from pandas.core.arrays.numpy_ import NumpyExtensionArray import pytest from tests import ( - PD_LTE_23, check, exception_on_platform, ) @@ -67,10 +65,7 @@ def test_construction_sequence( def test_construction_sequence_nan( data: tuple[Any, ...], typ: Callable[[Sequence[Any]], Sequence[Any]] ) -> None: - expected_type = ( - NumpyExtensionArray if data == (np.nan,) and PD_LTE_23 else FloatingArray - ) - check(pd.array(typ(data)), expected_type) + check(pd.array(typ(data)), FloatingArray) if TYPE_CHECKING: assert_type(pd.array([]), FloatingArray) diff --git a/tests/arrays/test_sparse.py b/tests/arrays/test_sparse.py index a8fbcb8e0..15e81f564 100644 --- a/tests/arrays/test_sparse.py +++ b/tests/arrays/test_sparse.py @@ -17,7 +17,6 @@ from pandas.core.dtypes.dtypes import SparseDtype from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) @@ -209,17 +208,10 @@ def test_sparse_sum() -> None: def test_sparse_cumsum() -> None: - """ - Test cumsum method for SparseArray. - - Note: At runtime, cumsum has a recursion bug in pandas. - This test only validates the type signature. - """ + """Test cumsum method for SparseArray.""" arr = SparseArray([1, 0, 0, 2, 3], fill_value=0) - if not PD_LTE_23: - # TODO: pandas-dev/pandas#62669 fix is in 3.0 - check(assert_type(arr.cumsum(), SparseArray), SparseArray) - check(assert_type(arr.cumsum(axis=0), SparseArray), SparseArray) + check(assert_type(arr.cumsum(), SparseArray), SparseArray) + check(assert_type(arr.cumsum(axis=0), SparseArray), SparseArray) def test_sparse_mean() -> None: diff --git a/tests/frame/test_frame.py b/tests/frame/test_frame.py index 7cd1c6b30..d9bb6ffc7 100644 --- a/tests/frame/test_frame.py +++ b/tests/frame/test_frame.py @@ -46,7 +46,6 @@ from pandas._typing import Scalar from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -73,10 +72,7 @@ else: PandasNamedTuple: TypeAlias = tuple -if not PD_LTE_23: - from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] -else: - Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] +from pandas.errors import Pandas4Warning def getCols(k: int) -> str: @@ -458,21 +454,14 @@ def test_types_drop_duplicates() -> None: pd.DataFrame, ) - if not PD_LTE_23: - check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame) - check( - assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame - ) + check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame) + check(assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame) def test_types_fillna() -> None: df = pd.DataFrame(data={"col1": [np.nan, np.nan], "col2": [3, np.nan]}) check(assert_type(df.fillna(0), pd.DataFrame), pd.DataFrame) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.fillna(0, axis=1, inplace=True), None), type(None)) - else: - check(assert_type(df.fillna(0, axis=1, inplace=True), None), pd.DataFrame) + check(assert_type(df.fillna(0, axis=1, inplace=True), pd.DataFrame), pd.DataFrame) def test_types_sort_index() -> None: @@ -780,25 +769,18 @@ def test_dataframe_clip() -> None: ), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(lower=5, upper=None, axis=None, inplace=True), None), - type(None), - ) - check( - assert_type(df.clip(lower=None, upper=15, axis=None, inplace=True), None), - type(None), - ) - else: - check( - assert_type(df.clip(lower=5, upper=None, axis=None, inplace=True), None), - pd.DataFrame, - ) - check( - assert_type(df.clip(lower=None, upper=15, axis=None, inplace=True), None), - pd.DataFrame, - ) + check( + assert_type( + df.clip(lower=5, upper=None, axis=None, inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) + check( + assert_type( + df.clip(lower=None, upper=15, axis=None, inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) check( assert_type(df.clip(lower=None, upper=None, axis=0), pd.DataFrame), pd.DataFrame @@ -821,65 +803,32 @@ def test_dataframe_clip() -> None: ), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(lower=5, upper=None, axis="index", inplace=True), None), - type(None), - ) - check( - assert_type( - df.clip(lower=None, upper=15, axis="index", inplace=True), None - ), - type(None), - ) - check( - assert_type( - df.clip( - lower=pd.Series([1, 2]), upper=None, axis="index", inplace=True - ), - None, - ), - type(None), - ) - check( - assert_type( - df.clip( - lower=None, upper=pd.Series([1, 2]), axis="index", inplace=True - ), - None, - ), - type(None), - ) - else: - check( - assert_type(df.clip(lower=5, upper=None, axis="index", inplace=True), None), - pd.DataFrame, - ) - check( - assert_type( - df.clip(lower=None, upper=15, axis="index", inplace=True), None - ), - pd.DataFrame, - ) - check( - assert_type( - df.clip( - lower=pd.Series([1, 2]), upper=None, axis="index", inplace=True - ), - None, - ), + check( + assert_type( + df.clip(lower=5, upper=None, axis="index", inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) + check( + assert_type( + df.clip(lower=None, upper=15, axis="index", inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) + check( + assert_type( + df.clip(lower=pd.Series([1, 2]), upper=None, axis="index", inplace=True), pd.DataFrame, - ) - check( - assert_type( - df.clip( - lower=None, upper=pd.Series([1, 2]), axis="index", inplace=True - ), - None, - ), + ), + pd.DataFrame, + ) + check( + assert_type( + df.clip(lower=None, upper=pd.Series([1, 2]), axis="index", inplace=True), pd.DataFrame, - ) + ), + pd.DataFrame, + ) check( assert_type(df.clip(lower=None, upper=None, axis="index"), pd.DataFrame), pd.DataFrame, @@ -910,25 +859,14 @@ def test_dataframe_clip() -> None: ), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(lower=5, upper=None, axis=0, inplace=True), None), - type(None), - ) - check( - assert_type(df.clip(lower=None, upper=15, axis=0, inplace=True), None), - type(None), - ) - else: - check( - assert_type(df.clip(lower=5, upper=None, axis=0, inplace=True), None), - pd.DataFrame, - ) - check( - assert_type(df.clip(lower=None, upper=15, axis=0, inplace=True), None), - pd.DataFrame, - ) + check( + assert_type(df.clip(lower=5, upper=None, axis=0, inplace=True), pd.DataFrame), + pd.DataFrame, + ) + check( + assert_type(df.clip(lower=None, upper=15, axis=0, inplace=True), pd.DataFrame), + pd.DataFrame, + ) # without lower check(assert_type(df.clip(upper=None, axis=None), pd.DataFrame), pd.DataFrame) @@ -937,13 +875,10 @@ def test_dataframe_clip() -> None: assert_type(df.clip(upper=None, axis=None, inplace=True), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.clip(upper=15, axis=None, inplace=True), None), type(None)) - else: - check( - assert_type(df.clip(upper=15, axis=None, inplace=True), None), pd.DataFrame - ) + check( + assert_type(df.clip(upper=15, axis=None, inplace=True), pd.DataFrame), + pd.DataFrame, + ) check(assert_type(df.clip(upper=None, axis=0), pd.DataFrame), pd.DataFrame) check(assert_type(df.clip(upper=15, axis=0), pd.DataFrame), pd.DataFrame) @@ -955,28 +890,16 @@ def test_dataframe_clip() -> None: assert_type(df.clip(upper=None, axis="index", inplace=True), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(upper=15, axis="index", inplace=True), None), type(None) - ) - check( - assert_type( - df.clip(upper=pd.Series([1, 2]), axis="index", inplace=True), None - ), - type(None), - ) - else: - check( - assert_type(df.clip(upper=15, axis="index", inplace=True), None), - pd.DataFrame, - ) - check( - assert_type( - df.clip(upper=pd.Series([1, 2]), axis="index", inplace=True), None - ), - pd.DataFrame, - ) + check( + assert_type(df.clip(upper=15, axis="index", inplace=True), pd.DataFrame), + pd.DataFrame, + ) + check( + assert_type( + df.clip(upper=pd.Series([1, 2]), axis="index", inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) check(assert_type(df.clip(upper=None, axis="index"), pd.DataFrame), pd.DataFrame) check(assert_type(df.clip(upper=15, axis="index"), pd.DataFrame), pd.DataFrame) check( @@ -988,13 +911,10 @@ def test_dataframe_clip() -> None: pd.DataFrame, ) # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.clip(upper=15, axis=0, inplace=True), None), type(None)) - else: - check( - assert_type(df.clip(upper=15, axis=0, inplace=True), None), - pd.DataFrame, - ) + check( + assert_type(df.clip(upper=15, axis=0, inplace=True), pd.DataFrame), + pd.DataFrame, + ) # without upper check( @@ -1007,16 +927,10 @@ def test_dataframe_clip() -> None: pd.DataFrame, ) # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(lower=5, axis=None, inplace=True), None), - type(None), - ) - else: - check( - assert_type(df.clip(lower=5, axis=None, inplace=True), None), - pd.DataFrame, - ) + check( + assert_type(df.clip(lower=5, axis=None, inplace=True), pd.DataFrame), + pd.DataFrame, + ) check( assert_type(df.clip(lower=None, axis=None, inplace=True), pd.DataFrame), pd.DataFrame, @@ -1032,32 +946,16 @@ def test_dataframe_clip() -> None: assert_type(df.clip(lower=None, axis="index", inplace=True), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.clip(lower=5, axis="index", inplace=True), None), - type(None), - ) - else: - check( - assert_type(df.clip(lower=5, axis="index", inplace=True), None), - pd.DataFrame, - ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type( - df.clip(lower=pd.Series([1, 2]), axis="index", inplace=True), None - ), - type(None), - ) - else: - check( - assert_type( - df.clip(lower=pd.Series([1, 2]), axis="index", inplace=True), None - ), - pd.DataFrame, - ) + check( + assert_type(df.clip(lower=5, axis="index", inplace=True), pd.DataFrame), + pd.DataFrame, + ) + check( + assert_type( + df.clip(lower=pd.Series([1, 2]), axis="index", inplace=True), pd.DataFrame + ), + pd.DataFrame, + ) check( assert_type(df.clip(lower=None, axis="index"), pd.DataFrame), pd.DataFrame, @@ -1074,14 +972,10 @@ def test_dataframe_clip() -> None: assert_type(df.clip(lower=None, axis=0, inplace=True), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.clip(lower=5, axis=0, inplace=True), None), type(None)) - else: - check( - assert_type(df.clip(lower=5, axis=0, inplace=True), None), - pd.DataFrame, - ) + check( + assert_type(df.clip(lower=5, axis=0, inplace=True), pd.DataFrame), + pd.DataFrame, + ) def test_types_abs() -> None: @@ -3007,49 +2901,6 @@ class ReadCsvKwargs(TypedDict): ), pd.DataFrame, ) - if PD_LTE_23: - parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]} - with pytest_warns_bounded( - FutureWarning, "Support for nested sequences", lower="2.1.99" - ): - check( - assert_type( - pd.read_csv(path_str, parse_dates=parse_dates_2), pd.DataFrame - ), - pd.DataFrame, - ) - parse_dates_3 = {"combined_date": [1, 2, 3]} - with pytest_warns_bounded( - FutureWarning, "Support for nested sequences", lower="2.1.99" - ): - check( - assert_type( - pd.read_csv(path_str, parse_dates=parse_dates_3), pd.DataFrame - ), - pd.DataFrame, - ) - # MyPy calls this Dict[str, object] by default which necessitates the explicit annotation (Pyright does not) - parse_dates_4: dict[str, list[str | int]] = {"combined_date": [1, "Month", 3]} - with pytest_warns_bounded( - FutureWarning, "Support for nested sequences", lower="2.1.99" - ): - check( - assert_type( - pd.read_csv(path_str, parse_dates=parse_dates_4), pd.DataFrame - ), - pd.DataFrame, - ) - - parse_dates_6 = [[1, 2, 3]] - with pytest_warns_bounded( - FutureWarning, "Support for nested sequences", lower="2.1.99" - ): - check( - assert_type( - pd.read_csv(path_str, parse_dates=parse_dates_6), pd.DataFrame - ), - pd.DataFrame, - ) parse_dates_5 = [0] check( assert_type(pd.read_csv(path_str, parse_dates=parse_dates_5), pd.DataFrame), @@ -3145,18 +2996,11 @@ def test_types_ffill() -> None: assert_type(df.ffill(inplace=False, limit_area="inside"), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.ffill(inplace=True), None), type(None)) - check( - assert_type(df.ffill(inplace=True, limit_area="outside"), None), type(None) - ) - else: - check(assert_type(df.ffill(inplace=True), None), pd.DataFrame) - check( - assert_type(df.ffill(inplace=True, limit_area="outside"), None), - pd.DataFrame, - ) + check(assert_type(df.ffill(inplace=True), pd.DataFrame), pd.DataFrame) + check( + assert_type(df.ffill(inplace=True, limit_area="outside"), pd.DataFrame), + pd.DataFrame, + ) def test_types_bfill() -> None: @@ -3168,18 +3012,11 @@ def test_types_bfill() -> None: assert_type(df.bfill(inplace=False, limit_area="inside"), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.bfill(inplace=True), None), type(None)) - check( - assert_type(df.bfill(inplace=True, limit_area="outside"), None), type(None) - ) - else: - check(assert_type(df.bfill(inplace=True), None), pd.DataFrame) - check( - assert_type(df.bfill(inplace=True, limit_area="outside"), None), - pd.DataFrame, - ) + check(assert_type(df.bfill(inplace=True), pd.DataFrame), pd.DataFrame) + check( + assert_type(df.bfill(inplace=True, limit_area="outside"), pd.DataFrame), + pd.DataFrame, + ) def test_types_replace() -> None: @@ -3187,11 +3024,7 @@ def test_types_replace() -> None: df = pd.DataFrame([[1, 2, 3]]) check(assert_type(df.replace(1, 2), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(1, 2, inplace=False), pd.DataFrame), pd.DataFrame) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.replace(1, 2, inplace=True), None), type(None)) - else: - check(assert_type(df.replace(1, 2, inplace=True), None), pd.DataFrame) + check(assert_type(df.replace(1, 2, inplace=True), pd.DataFrame), pd.DataFrame) def test_dataframe_replace() -> None: @@ -3369,37 +3202,17 @@ def test_frame_stack() -> None: [[1.0, 2.0], [3.0, 4.0]], index=["cat", "dog"], columns=multicol2 ) - with pytest_warns_bounded( - FutureWarning, - "The previous implementation of stack is deprecated", - upper="2.3.99", - ): - check( - assert_type(df_multi_level_cols2.stack(0), pd.DataFrame | pd.Series), - pd.DataFrame, - ) - check( - assert_type( - df_multi_level_cols2.stack([0, 1]), - pd.DataFrame | pd.Series, - ), - pd.Series, - ) - if PD_LTE_23: - check( - assert_type( - df_multi_level_cols2.stack(0, future_stack=False), - pd.DataFrame | pd.Series, - ), - pd.DataFrame, - ) - check( - assert_type( - df_multi_level_cols2.stack(0, dropna=True, sort=True), - pd.DataFrame | pd.Series, - ), - pd.DataFrame, - ) + check( + assert_type(df_multi_level_cols2.stack(0), pd.DataFrame | pd.Series), + pd.DataFrame, + ) + check( + assert_type( + df_multi_level_cols2.stack([0, 1]), + pd.DataFrame | pd.Series, + ), + pd.Series, + ) def test_frame_reindex() -> None: @@ -3709,20 +3522,15 @@ def test_where( df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]}) check(df.where(cond), pd.DataFrame) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(df.where(cond, inplace=True), type(None)) - else: - check(df.where(cond, inplace=True), pd.DataFrame) + check(df.where(cond, inplace=True), pd.DataFrame) if TYPE_CHECKING: assert_type(df.where(where_cond1), pd.DataFrame) assert_type(df.where(where_cond2), pd.DataFrame) assert_type(df.where(where_cond3), pd.DataFrame) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - assert_type(df.where(where_cond1, inplace=True), None) - assert_type(df.where(where_cond2, inplace=True), None) - assert_type(df.where(where_cond3, inplace=True), None) + assert_type(df.where(where_cond1, inplace=True), pd.DataFrame) + assert_type(df.where(where_cond2, inplace=True), pd.DataFrame) + assert_type(df.where(where_cond3, inplace=True), pd.DataFrame) def test_mask() -> None: @@ -3732,11 +3540,7 @@ def cond1(x: int) -> bool: return x % 2 == 0 check(assert_type(df.mask(cond1), pd.DataFrame), pd.DataFrame) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(df.mask(cond1, inplace=True), None), type(None)) - else: - check(assert_type(df.mask(cond1, inplace=True), None), pd.DataFrame) + check(assert_type(df.mask(cond1, inplace=True), pd.DataFrame), pd.DataFrame) def test_replace_na() -> None: @@ -3766,6 +3570,8 @@ def test_reset_index_150_changes() -> None: check(assert_type(df4, pd.DataFrame), pd.DataFrame) check(assert_type(df4[["num"]], pd.DataFrame), pd.DataFrame) + check(assert_type(frame.reset_index(inplace=True), None), type(None)) + def test_compare_150_changes() -> None: frame_a = pd.DataFrame({"a": [1, 2, 3, 4]}, index=[-10, -9, -8, -7]) @@ -4133,16 +3939,10 @@ def test_interpolate() -> None: assert_type(df.interpolate(method="linear", inplace=False), pd.DataFrame), pd.DataFrame, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(df.interpolate(method="linear", inplace=True), None), type(None) - ) - else: - check( - assert_type(df.interpolate(method="linear", inplace=True), None), - pd.DataFrame, - ) + check( + assert_type(df.interpolate(method="linear", inplace=True), pd.DataFrame), + pd.DataFrame, + ) def test_itertuples() -> None: diff --git a/tests/frame/test_groupby.py b/tests/frame/test_groupby.py index 0194f2dc3..79e1aea4c 100644 --- a/tests/frame/test_groupby.py +++ b/tests/frame/test_groupby.py @@ -18,7 +18,6 @@ from pandas._typing import Scalar from tests import ( - PD_LTE_23, check, pytest_warns_bounded, ) @@ -163,21 +162,6 @@ def test_types_groupby() -> None: assert_type(df.groupby(by=["col1", "col2"]).nunique(), pd.DataFrame), pd.DataFrame, ) - with pytest_warns_bounded( - FutureWarning, - "(The provided callable is currently using|The behavior of DataFrame.sum with)", - upper="2.3.99", - ): - with pytest_warns_bounded( - FutureWarning, - "DataFrameGroupBy.apply operated on the grouping columns", - upper="2.3.99", - ): - if PD_LTE_23: - check( - assert_type(df.groupby(by="col1").apply(sum), pd.DataFrame), - pd.DataFrame, - ) check(assert_type(df.groupby("col1").transform("sum"), pd.DataFrame), pd.DataFrame) s1 = df.set_index("col1")["col2"] check(assert_type(s1, pd.Series), pd.Series) @@ -381,10 +365,7 @@ def test_groupby_result() -> None: index, value = next(iterator) assert_type((index, value), tuple[tuple[Hashable, ...], pd.DataFrame]) - if PD_LTE_23: - check(assert_type(index, tuple[Hashable, ...]), tuple, np.integer) - else: - check(assert_type(index, tuple[Hashable, ...]), tuple, int) + check(assert_type(index, tuple[Hashable, ...]), tuple, int) check(assert_type(value, pd.DataFrame), pd.DataFrame) diff --git a/tests/indexes/test_indexes.py b/tests/indexes/test_indexes.py index eb47975de..48e887bff 100644 --- a/tests/indexes/test_indexes.py +++ b/tests/indexes/test_indexes.py @@ -29,7 +29,6 @@ from pandas._typing import Scalar # noqa: F401 from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -1039,7 +1038,7 @@ def test_getitem() -> None: check( assert_type(iri[[0, 2, 4]], pd.Index), pd.Index, - np.integer if PD_LTE_23 else int, + int, ) mi = pd.MultiIndex.from_product([["a", "b"], ["c", "d"]], names=["ab", "cd"]) diff --git a/tests/indexes/timedeltaindex/test_floordiv.py b/tests/indexes/timedeltaindex/test_floordiv.py index 97256a304..f787968c2 100644 --- a/tests/indexes/timedeltaindex/test_floordiv.py +++ b/tests/indexes/timedeltaindex/test_floordiv.py @@ -14,7 +14,6 @@ import pytest from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) @@ -63,12 +62,7 @@ def test_floordiv_py_sequence(left: pd.TimedeltaIndex) -> None: if TYPE_CHECKING_INVALID_USAGE: _03 = left // c # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] _04 = left // s # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] - # TODO: pandas-dev/pandas#62552 switch to np.integer after Pandas 3.0 - check( - assert_type(left // d, "pd.Index[int]"), - pd.Index, - int if PD_LTE_23 else np.integer, - ) + check(assert_type(left // d, "pd.Index[int]"), pd.Index, np.integer) if TYPE_CHECKING_INVALID_USAGE: _10 = b // left # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] diff --git a/tests/scalars/test_scalars.py b/tests/scalars/test_scalars.py index 6073413f9..2a654e4bf 100644 --- a/tests/scalars/test_scalars.py +++ b/tests/scalars/test_scalars.py @@ -5,7 +5,6 @@ from typing import ( Any, Literal, - TypeAlias, assert_type, ) @@ -17,9 +16,9 @@ from pandas._libs.tslibs.timedeltas import Components from pandas._typing import TimeUnit +from pandas.errors import Pandas4Warning from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -40,11 +39,6 @@ Day, ) -if not PD_LTE_23: - from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] -else: - Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] - def test_interval() -> None: interval_i = pd.Interval(0, 1, closed="left") diff --git a/tests/series/test_indexing.py b/tests/series/test_indexing.py index 12f73d77d..c1779bf8f 100644 --- a/tests/series/test_indexing.py +++ b/tests/series/test_indexing.py @@ -10,23 +10,13 @@ import pandas as pd from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, - pytest_warns_bounded, ) def test_types_select() -> None: s = pd.Series(data={"row1": 1, "row2": 2}) - if PD_LTE_23: - # Not valid in 3.0 - with pytest_warns_bounded( - FutureWarning, - "Series.__getitem__ treating keys as positions is deprecated", - lower="2.0.99", - ): - s[0] check(assert_type(s[1:], "pd.Series[int]"), pd.Series, np.integer) diff --git a/tests/series/test_series.py b/tests/series/test_series.py index 630b480ce..24039e9b1 100644 --- a/tests/series/test_series.py +++ b/tests/series/test_series.py @@ -48,9 +48,9 @@ DtypeObj, Scalar, ) +from pandas.errors import Pandas4Warning from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, WINDOWS, check, @@ -94,11 +94,6 @@ YearEnd, ) -if not PD_LTE_23: - from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] -else: - Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] - # Tests will use numpy 2.1 in python 3.10 or later # From Numpy 2.1 __init__.pyi _DTypeKind: TypeAlias = Literal[ @@ -335,11 +330,11 @@ def test_types_fillna() -> None: pd.Series, float, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - assert assert_type(s.fillna(0, inplace=True), None) is None - else: - check(assert_type(s.fillna(0, inplace=True), None), pd.Series, np.floating) + check( + assert_type(s.fillna(0, inplace=True), "pd.Series[float]"), + pd.Series, + np.floating, + ) check(assert_type(s.fillna(0), "pd.Series[float]"), pd.Series, float) check( assert_type(s.fillna(0, limit=1), "pd.Series[float]"), @@ -587,38 +582,26 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(s.clip(lower=0, upper=5, inplace=True), None), type(None)) - check(assert_type(s.clip(lower=0, upper=None, inplace=True), None), type(None)) - else: - check( - assert_type(s.clip(lower=0, upper=5, inplace=True), None), - pd.Series, - np.integer, - ) - check( - assert_type(s.clip(lower=0, upper=None, inplace=True), None), - pd.Series, - np.integer, - ) + check( + assert_type(s.clip(lower=0, upper=5, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.clip(lower=0, upper=None, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) check( assert_type(s.clip(lower=None, upper=None, inplace=True), "pd.Series[int]"), pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(s.clip(lower=None, upper=5, inplace=True), None), - type(None), - ) - else: - check( - assert_type(s.clip(lower=None, upper=5, inplace=True), None), - pd.Series, - np.integer, - ) + check( + assert_type(s.clip(lower=None, upper=5, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) check( assert_type(s.clip(lower=lower, upper=upper), "pd.Series[int]"), pd.Series, @@ -634,40 +617,26 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(s.clip(lower=lower, upper=upper, inplace=True), None), - type(None), - ) - check( - assert_type(s.clip(lower=lower, upper=upper, axis=0, inplace=True), None), - type(None), - ) - check( - assert_type( - s.clip(lower=lower, upper=upper, axis="index", inplace=True), None - ), - type(None), - ) - else: - check( - assert_type(s.clip(lower=lower, upper=upper, inplace=True), None), - pd.Series, - np.integer, - ) - check( - assert_type(s.clip(lower=lower, upper=upper, axis=0, inplace=True), None), - pd.Series, - np.integer, - ) - check( - assert_type( - s.clip(lower=lower, upper=upper, axis="index", inplace=True), None - ), - pd.Series, - np.integer, - ) + check( + assert_type(s.clip(lower=lower, upper=upper, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type( + s.clip(lower=lower, upper=upper, axis=0, inplace=True), "pd.Series[int]" + ), + pd.Series, + np.integer, + ) + check( + assert_type( + s.clip(lower=lower, upper=upper, axis="index", inplace=True), + "pd.Series[int]", + ), + pd.Series, + np.integer, + ) # without lower check(assert_type(s.clip(upper=None), "pd.Series[int]"), pd.Series, np.integer) @@ -677,11 +646,11 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(s.clip(upper=5, inplace=True), None), type(None)) - else: - check(assert_type(s.clip(upper=5, inplace=True), None), pd.Series, np.integer) + check( + assert_type(s.clip(upper=5, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) check(assert_type(s.clip(upper=upper), "pd.Series[int]"), pd.Series, np.integer) check( assert_type(s.clip(upper=upper, axis=0), "pd.Series[int]"), @@ -693,28 +662,21 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(s.clip(upper=upper, inplace=True), None), type(None)) - check(assert_type(s.clip(upper=upper, axis=0, inplace=True), None), type(None)) - check( - assert_type(s.clip(upper=upper, axis="index", inplace=True), None), - type(None), - ) - else: - check( - assert_type(s.clip(upper=upper, inplace=True), None), pd.Series, np.integer - ) - check( - assert_type(s.clip(upper=upper, axis=0, inplace=True), None), - pd.Series, - np.integer, - ) - check( - assert_type(s.clip(upper=upper, axis="index", inplace=True), None), - pd.Series, - np.integer, - ) + check( + assert_type(s.clip(upper=upper, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.clip(upper=upper, axis=0, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.clip(upper=upper, axis="index", inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) # without upper check(assert_type(s.clip(lower=None), "pd.Series[int]"), pd.Series, np.integer) @@ -725,11 +687,11 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(s.clip(lower=0, inplace=True), None), type(None)) - else: - check(assert_type(s.clip(lower=0, inplace=True), None), pd.Series, np.integer) + check( + assert_type(s.clip(lower=0, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) check( assert_type(s.clip(lower=None, inplace=True), "pd.Series[int]"), pd.Series, @@ -746,32 +708,25 @@ def test_types_clip() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check(assert_type(s.clip(lower=lower, inplace=True), None), type(None)) - check(assert_type(s.clip(lower=lower, axis=0, inplace=True), None), type(None)) - check( - assert_type(s.clip(lower=lower, axis="index", inplace=True), None), - type(None), - ) - else: - check( - assert_type(s.clip(lower=lower, inplace=True), None), pd.Series, np.integer - ) - check( - assert_type(s.clip(lower=lower, axis=0, inplace=True), None), - pd.Series, - np.integer, - ) - check( - assert_type(s.clip(lower=lower, axis="index", inplace=True), None), - pd.Series, - np.integer, - ) + check( + assert_type(s.clip(lower=lower, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.clip(lower=lower, axis=0, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) + check( + assert_type(s.clip(lower=lower, axis="index", inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) if TYPE_CHECKING_INVALID_USAGE: - s.clip(lower=lower, axis=1) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] - s.clip(lower=lower, axis="column") # type: ignore[call-overload] # pyright: ignore[reportArgumentType] + s.clip(lower=lower, axis=1) # type: ignore[call-overload] # pyright: ignore[reportCallIssue, reportArgumentType] + s.clip(lower=lower, axis="column") # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] def test_types_abs() -> None: @@ -978,10 +933,7 @@ def test_groupby_result() -> None: index, value = next(iterator) assert_type((index, value), tuple[tuple[Hashable, ...], "pd.Series[int]"]) - if PD_LTE_23: - check(assert_type(index, tuple[Hashable, ...]), tuple, np.integer) - else: - check(assert_type(index, tuple[Hashable, ...]), tuple, int) + check(assert_type(index, tuple[Hashable, ...]), tuple, int) check(assert_type(value, "pd.Series[int]"), pd.Series, np.integer) @@ -1362,7 +1314,7 @@ def test_types_agg() -> None: r"The provided callable <(built-in function (min|max|mean)|function mean at 0x\w+)> is currently using", upper="2.3.99", ): - check(assert_type(s.agg(min), int), np.integer if PD_LTE_23 else int) + check(assert_type(s.agg(min), int), int) check(assert_type(s.agg([min, max]), pd.Series), pd.Series, np.integer) check(assert_type(s.agg({0: min}), pd.Series), pd.Series, np.integer) check( @@ -1382,7 +1334,7 @@ def test_types_aggregate() -> None: r"The provided callable is currently using", upper="2.3.99", ): - check(assert_type(s.aggregate(min), int), np.integer if PD_LTE_23 else int) + check(assert_type(s.aggregate(min), int), int) check(assert_type(s.aggregate([min, max]), pd.Series), pd.Series, np.integer) check(assert_type(s.aggregate({0: min}), pd.Series), pd.Series, np.integer) @@ -1472,7 +1424,7 @@ def test_types_values() -> None: assert_type( pd.Series(list("aabc")).values, np_1darray | ExtensionArray | pd.Categorical ), - np_1darray if PD_LTE_23 else BaseStringArray, + BaseStringArray, str, ) check( @@ -1556,17 +1508,12 @@ def test_types_bfill() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - assert assert_type(s1.bfill(inplace=True), None) is None - assert assert_type(s1.bfill(inplace=True, limit_area="outside"), None) is None - else: - check(assert_type(s1.bfill(inplace=True), None), pd.Series, np.integer) - check( - assert_type(s1.bfill(inplace=True, limit_area="outside"), None), - pd.Series, - np.integer, - ) + check(assert_type(s1.bfill(inplace=True), "pd.Series[int]"), pd.Series, np.integer) + check( + assert_type(s1.bfill(inplace=True, limit_area="outside"), "pd.Series[int]"), + pd.Series, + np.integer, + ) def test_types_ewm() -> None: @@ -1615,17 +1562,12 @@ def test_types_ffill() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - assert assert_type(s1.ffill(inplace=True), None) is None - assert assert_type(s1.ffill(inplace=True, limit_area="outside"), None) is None - else: - check(assert_type(s1.ffill(inplace=True), None), pd.Series, np.integer) - check( - assert_type(s1.ffill(inplace=True, limit_area="outside"), None), - pd.Series, - np.integer, - ) + check(assert_type(s1.ffill(inplace=True), "pd.Series[int]"), pd.Series, np.integer) + check( + assert_type(s1.ffill(inplace=True, limit_area="outside"), "pd.Series[int]"), + pd.Series, + np.integer, + ) def test_types_as_type() -> None: @@ -1687,11 +1629,11 @@ def test_types_replace() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - assert assert_type(s.replace(1, 2, inplace=True), None) is None - else: - check(assert_type(s.replace(1, 2, inplace=True), None), pd.Series, np.integer) + check( + assert_type(s.replace(1, 2, inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) def test_series_replace() -> None: @@ -2097,22 +2039,6 @@ def test_bitwise_operators() -> None: check(assert_type(s ^ s2, "pd.Series[int]"), pd.Series, np.integer) check(assert_type(s2 ^ s, "pd.Series[int]"), pd.Series, np.integer) - if PD_LTE_23: - with pytest_warns_bounded( - FutureWarning, - r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences " - r"\(e.g. list, tuple\) are deprecated", - lower="2.0.99", - ): - check(assert_type(s & [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_) - check(assert_type([1, 2, 3, 4] & s, "pd.Series[bool]"), pd.Series, np.bool_) - - check(assert_type(s | [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_) - check(assert_type([1, 2, 3, 4] | s, "pd.Series[bool]"), pd.Series, np.bool_) - - check(assert_type(s ^ [1, 2, 3, 4], "pd.Series[bool]"), pd.Series, np.bool_) - check(assert_type([1, 2, 3, 4] ^ s, "pd.Series[bool]"), pd.Series, np.bool_) - def test_logical_operators() -> None: # GH 380 @@ -2145,44 +2071,6 @@ def test_logical_operators() -> None: check(assert_type(True ^ (df["a"] >= 2), "pd.Series[bool]"), pd.Series, np.bool_) - if PD_LTE_23: - with pytest_warns_bounded( - FutureWarning, - r"Logical ops \(and, or, xor\) between Pandas objects and dtype-less sequences " - r"\(e.g. list, tuple\) are deprecated", - lower="2.0.99", - ): - check( - assert_type((df["a"] >= 2) ^ [True, False, True], "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - check( - assert_type((df["a"] >= 2) & [True, False, True], "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - check( - assert_type((df["a"] >= 2) | [True, False, True], "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - check( - assert_type([True, False, True] & (df["a"] >= 2), "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - check( - assert_type([True, False, True] | (df["a"] >= 2), "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - check( - assert_type([True, False, True] ^ (df["a"] >= 2), "pd.Series[bool]"), - pd.Series, - np.bool_, - ) - def test_AnyArrayLike_and_clip() -> None: ser = pd.Series([1, 2, 3]) @@ -2415,17 +2303,11 @@ def test_interpolate() -> None: pd.Series, np.integer, ) - # TODO: pandas-dev/pandas#63195 return Self after Pandas 3.0 - if PD_LTE_23: - check( - assert_type(s.interpolate(method="linear", inplace=True), None), type(None) - ) - else: - check( - assert_type(s.interpolate(method="linear", inplace=True), None), - pd.Series, - np.integer, - ) + check( + assert_type(s.interpolate(method="linear", inplace=True), "pd.Series[int]"), + pd.Series, + np.integer, + ) def test_groupby_diff() -> None: diff --git a/tests/series/timedelta/test_floordiv.py b/tests/series/timedelta/test_floordiv.py index c0e15ee78..14fb8c257 100644 --- a/tests/series/timedelta/test_floordiv.py +++ b/tests/series/timedelta/test_floordiv.py @@ -14,7 +14,6 @@ import pytest from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, ) @@ -88,12 +87,7 @@ def test_floordiv_py_sequence(left: "pd.Series[pd.Timedelta]") -> None: if TYPE_CHECKING_INVALID_USAGE: _03 = left // c # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] _04 = left // s # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] - # TODO: pandas-dev/pandas#62552 switch to np.integer after Pandas 3.0 - check( - assert_type(left // d, "pd.Series[int]"), - pd.Series, - int if PD_LTE_23 else np.integer, - ) + check(assert_type(left // d, "pd.Series[int]"), pd.Series, np.integer) if TYPE_CHECKING_INVALID_USAGE: _10 = b // left # type: ignore[operator] # pyright: ignore[reportOperatorIssue,reportUnknownVariableType] diff --git a/tests/test_errors.py b/tests/test_errors.py index 23be71fd8..4fb5ab89c 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -3,10 +3,7 @@ from pandas import errors import pytest -from tests import ( - PD_LTE_23, - WINDOWS, -) +from tests import WINDOWS def test_abstract_method_error() -> None: @@ -107,18 +104,6 @@ def test_specification_error() -> None: raise errors.SpecificationError -def test_setting_with_copy_error() -> None: - if PD_LTE_23: - with pytest.raises(errors.SettingWithCopyError): - raise errors.SettingWithCopyError - - -def test_setting_with_copy_warning() -> None: - if PD_LTE_23: - with pytest.warns(errors.SettingWithCopyWarning): - warnings.warn("", errors.SettingWithCopyWarning, stacklevel=2) - - def test_numexpr_clobbering_error() -> None: with pytest.raises(errors.NumExprClobberingError): raise errors.NumExprClobberingError diff --git a/tests/test_groupby.py b/tests/test_groupby.py index a78d15691..7c0dbb1c0 100644 --- a/tests/test_groupby.py +++ b/tests/test_groupby.py @@ -32,7 +32,6 @@ ) from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -247,16 +246,6 @@ def df2scalar(val: DataFrame) -> float: DatetimeIndexResamplerGroupby, ) - # interpolate - if PD_LTE_23: - check(assert_type(GB_DF.resample("ME").interpolate(), DataFrame), DataFrame) - check( - assert_type( - GB_DF.resample("ME").interpolate(method="linear"), DataFrame - ), - DataFrame, - ) - def resample_interpolate(x: DataFrame) -> DataFrame: return x.resample("ME").interpolate() @@ -403,21 +392,13 @@ def f(val: Series) -> float: # asfreq check(assert_type(GB_S.resample("ME").asfreq(-1.0), "Series[float]"), Series, float) - # interpolate - if PD_LTE_23: - check( - assert_type(GB_S.resample("ME").interpolate(), "Series[float]"), - Series, - float, - ) - else: - check( - assert_type( - GB_S.apply(lambda x: x.resample("ME").interpolate()), "Series[float]" - ), - Series, - float, - ) + check( + assert_type( + GB_S.apply(lambda x: x.resample("ME").interpolate()), "Series[float]" + ), + Series, + float, + ) # pipe def g(val: Resampler[Series]) -> float: @@ -467,8 +448,6 @@ def test_frame_groupby_rolling() -> None: # props check(assert_type(GB_DF.rolling(1).on, str | Index | None), type(None)) check(assert_type(GB_DF.rolling(1).method, Literal["single", "table"]), str) - if PD_LTE_23: - check(assert_type(GB_DF.rolling(1).axis, int), int) # agg funcs check(assert_type(GB_DF.rolling(1).sum(), DataFrame), DataFrame) @@ -658,8 +637,6 @@ def test_frame_groupby_expanding() -> None: # props check(assert_type(GB_DF.expanding(1).on, str | Index | None), type(None)) check(assert_type(GB_DF.expanding(1).method, Literal["single", "table"]), str) - if PD_LTE_23: - check(assert_type(GB_DF.expanding(1).axis, int), int) # agg funcs check(assert_type(GB_DF.expanding(1).sum(), DataFrame), DataFrame) @@ -853,8 +830,6 @@ def test_frame_groupby_ewm() -> None: # props check(assert_type(GB_DF.ewm(1).on, str | Index | None), type(None)) check(assert_type(GB_DF.ewm(1).method, Literal["single", "table"]), str) - if PD_LTE_23: - check(assert_type(GB_DF.ewm(1).axis, int), int) # agg funcs check(assert_type(GB_DF.ewm(1).sum(), DataFrame), DataFrame) @@ -865,64 +840,6 @@ def test_frame_groupby_ewm() -> None: check(assert_type(GB_DF.ewm(1).std(), DataFrame), DataFrame) check(assert_type(GB_DF.ewm(1).var(), DataFrame), DataFrame) - # aggregate - if PD_LTE_23: - with pytest_warns_bounded( - FutureWarning, - r"The provided callable is currently using ", - upper="2.99", - ): - check(assert_type(GB_DF.ewm(1).aggregate(np.sum), DataFrame), DataFrame) - check(assert_type(GB_DF.ewm(1).agg(np.sum), DataFrame), DataFrame) - check( - assert_type(GB_DF.ewm(1).aggregate([np.sum, np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type( - GB_DF.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), - DataFrame, - ), - DataFrame, - ) - check( - assert_type( - GB_DF.ewm(1).aggregate({"col1": ["sum", np.mean], "col2": np.mean}), - DataFrame, - ), - DataFrame, - ) - - # aggregate combinations - with pytest_warns_bounded( - FutureWarning, - r"The provided callable is currently using ", - upper="2.99", - ): - check(GB_DF.ewm(1).aggregate(np.sum), DataFrame) - check(GB_DF.ewm(1).aggregate([np.mean]), DataFrame) - check(GB_DF.ewm(1).aggregate(["sum", np.mean]), DataFrame) - check(GB_DF.ewm(1).aggregate({"col1": np.sum}), DataFrame) - check( - GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": np.mean}), - DataFrame, - ) - check( - GB_DF.ewm(1).aggregate({"col1": [np.sum], "col2": ["sum", np.mean]}), - DataFrame, - ) - check( - GB_DF.ewm(1).aggregate({"col1": np.sum, "col2": ["sum", np.mean]}), - DataFrame, - ) - check( - GB_DF.ewm(1).aggregate({"col1": "sum", "col2": [np.mean]}), - DataFrame, - ) check(GB_DF.ewm(1).aggregate("sum"), DataFrame) # getattr @@ -967,31 +884,6 @@ def test_series_groupby_ewm() -> None: check(assert_type(GB_S.ewm(1).std(), "Series[float]"), Series, float) check(assert_type(GB_S.ewm(1).var(), "Series[float]"), Series, float) - # aggregate - with pytest_warns_bounded( - FutureWarning, - r"The provided callable is currently using ", - upper="2.99", - ): - check(assert_type(GB_S.ewm(1).aggregate("sum"), Series), Series) - if PD_LTE_23: - check(assert_type(GB_S.ewm(1).aggregate(np.sum), Series), Series) - check(assert_type(GB_S.ewm(1).agg(np.sum), Series), Series) - check( - assert_type(GB_S.ewm(1).aggregate([np.sum, np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type(GB_S.ewm(1).aggregate(["sum", np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type( - GB_S.ewm(1).aggregate({"col1": "sum", "col2": np.mean}), DataFrame - ), - DataFrame, - ) - # iter iterator = iter(GB_S.ewm(1)) check(assert_type(iterator, "Iterator[Series[float]]"), Iterator) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index ebef07051..e711c3a71 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1,3 +1,4 @@ +# TODO: pandas-dev/pandas#55023 from __future__ import annotations import datetime as dt @@ -19,14 +20,11 @@ from pandas.core.arrays.integer import IntegerArray from pandas.core.groupby.grouper import Grouper import pandas.util as pdutil - -# TODO: pandas-dev/pandas#55023 import pytest from pandas._typing import Scalar from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -35,11 +33,9 @@ np_1darray, np_1darray_anyint, np_1darray_bool, - np_1darray_dt, np_1darray_float, np_1darray_int64, np_1darray_intp, - np_1darray_td, np_2darray, np_ndarray, np_ndarray_bool, @@ -954,32 +950,14 @@ def test_index_unqiue() -> None: interval_i = pd.interval_range(1, 10, periods=10) check(assert_type(pd.unique(ci), pd.CategoricalIndex), pd.CategoricalIndex) - check( - assert_type(pd.unique(dti), np_1darray_dt | pd.DatetimeIndex), - np_1darray if PD_LTE_23 else pd.DatetimeIndex, - ) - check( - assert_type(pd.unique(dti_zoned), np_1darray_dt | pd.DatetimeIndex), - pd.DatetimeIndex, - ) - check( - assert_type(pd.unique(i), np_1darray | pd.Index), - np_1darray if PD_LTE_23 else pd.Index, - ) - check(assert_type(pd.unique(ii_pd), np_1darray | pd.Index), pd.Index) + check(assert_type(pd.unique(dti), pd.DatetimeIndex), pd.DatetimeIndex) + check(assert_type(pd.unique(dti_zoned), pd.DatetimeIndex), pd.DatetimeIndex) + check(assert_type(pd.unique(i), pd.Index), pd.Index) + check(assert_type(pd.unique(ii_pd), pd.Index), pd.Index) check(assert_type(pd.unique(pi), pd.PeriodIndex), pd.PeriodIndex) - check( - assert_type(pd.unique(ri), np_1darray_int64), - np_1darray_int64 if PD_LTE_23 else pd.Index, - ) - check( - assert_type(pd.unique(tdi), np_1darray_td), - np_1darray if PD_LTE_23 else pd.TimedeltaIndex, - ) - check( - assert_type(pd.unique(mi), np_ndarray), - np_ndarray if PD_LTE_23 else pd.MultiIndex, - ) + check(assert_type(pd.unique(ri), "pd.Index[int]"), pd.Index) + check(assert_type(pd.unique(tdi), pd.TimedeltaIndex), pd.TimedeltaIndex) + check(assert_type(pd.unique(mi), np_ndarray), pd.MultiIndex) check( assert_type(pd.unique(interval_i), "pd.IntervalIndex[pd.Interval[int]]"), pd.IntervalIndex, diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 9fba5335e..924692027 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -16,10 +16,7 @@ from pandas import Series import pytest -from tests import ( - PD_LTE_23, - check, -) +from tests import check from tests._typing import np_ndarray_object from pandas.plotting import ( @@ -636,20 +633,19 @@ def test_grouped_dataframe_boxplot(close_figures: None) -> None: check(assert_type(grouped.boxplot(subplots=True), Series), Series) # a single plot - if not PD_LTE_23: - check( - assert_type( - grouped.boxplot( - subplots=False, - rot=45, - fontsize=12, - figsize=(8, 10), - orientation="horizontal", - ), - Axes, + check( + assert_type( + grouped.boxplot( + subplots=False, + rot=45, + fontsize=12, + figsize=(8, 10), + orientation="horizontal", ), Axes, - ) + ), + Axes, + ) def test_grouped_dataframe_boxplot_single(close_figures: None) -> None: @@ -681,20 +677,19 @@ def test_grouped_dataframe_boxplot_single(close_figures: None) -> None: Axes, ) - if not PD_LTE_23: - check( - assert_type( - grouped.boxplot( - subplots=False, - rot=45, - fontsize=12, - figsize=(8, 10), - orientation="horizontal", - ), - Axes, + check( + assert_type( + grouped.boxplot( + subplots=False, + rot=45, + fontsize=12, + figsize=(8, 10), + orientation="horizontal", ), Axes, - ) + ), + Axes, + ) # not a literal bool check(assert_type(grouped.boxplot(subplots=bool(0.5)), Axes | Series), Series) diff --git a/tests/test_resampler.py b/tests/test_resampler.py index 50d2f6190..ee3219eb9 100644 --- a/tests/test_resampler.py +++ b/tests/test_resampler.py @@ -4,7 +4,6 @@ Iterator, ) from typing import ( - TypeAlias, assert_type, ) @@ -18,18 +17,14 @@ from pandas.core.resample import DatetimeIndexResampler from pandas.core.series import Series +from pandas.errors import Pandas4Warning + from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, ) -if not PD_LTE_23: - from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] -else: - Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] - DR = date_range("1999-1-1", periods=365, freq="D") DF_ = DataFrame(np.random.standard_normal((365, 1)), index=DR) S = DF_.iloc[:, 0] diff --git a/tests/test_styler.py b/tests/test_styler.py index 6128af9c5..2ed5026de 100644 --- a/tests/test_styler.py +++ b/tests/test_styler.py @@ -11,7 +11,7 @@ Environment, Template, ) -from jinja2.loaders import PackageLoader +from jinja2.loaders import FileSystemLoader import numpy as np from pandas import ( DataFrame, @@ -22,10 +22,7 @@ from pandas._typing import Scalar -from tests import ( - PD_LTE_23, - check, -) +from tests import check from tests._typing import np_ndarray_str from pandas.io.formats.style import Styler @@ -144,9 +141,7 @@ def test_highlight_quantile() -> None: def test_loader() -> None: - if PD_LTE_23: - # see GH62123 for pandas main repo, type changes in pandas 3.0 - check(assert_type(DF.style.loader, PackageLoader), PackageLoader) + check(assert_type(DF.style.loader, FileSystemLoader), FileSystemLoader) def test_pipe() -> None: diff --git a/tests/test_testing.py b/tests/test_testing.py index fe2a9591d..995fbd22d 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -7,7 +7,6 @@ ) from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, ) @@ -16,19 +15,9 @@ def test_types_assert_series_equal() -> None: s1 = pd.Series([0, 1, 1, 0]) s2 = pd.Series([0, 1, 1, 0]) assert_series_equal(left=s1, right=s2) - if PD_LTE_23: - assert_series_equal( - s1, - s2, - check_freq=False, - check_categorical=True, - check_flags=True, - check_datetimelike_compat=True, - ) - else: - assert_series_equal( - s1, s2, check_freq=False, check_categorical=True, check_flags=True - ) + assert_series_equal( + s1, s2, check_freq=False, check_categorical=True, check_flags=True + ) if TYPE_CHECKING_INVALID_USAGE: assert_series_equal( # type: ignore[call-overload] # pyright: ignore[reportCallIssue] s1, s2, check_dtype=True, check_less_precise=True, check_names=True diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 2e67fc795..ee77abc8c 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -2,7 +2,6 @@ import datetime as dt from typing import ( - TypeAlias, assert_never, assert_type, ) @@ -23,9 +22,9 @@ import pytz from pandas._typing import TimeUnit +from pandas.errors import Pandas4Warning from tests import ( - PD_LTE_23, TYPE_CHECKING_INVALID_USAGE, check, pytest_warns_bounded, @@ -51,11 +50,6 @@ Day, ) -if not PD_LTE_23: - from pandas.errors import Pandas4Warning # pyright: ignore[reportRedeclaration] -else: - Pandas4Warning: TypeAlias = FutureWarning # type: ignore[no-redef] - def test_types_init() -> None: check(assert_type(pd.Timestamp("2021-03-01T12"), pd.Timestamp), pd.Timestamp) @@ -364,9 +358,10 @@ def test_series_dt_accessors() -> None: "The behavior of DatetimeProperties.to_pydatetime is deprecated", upper="2.3.99", ): + # TODO: pandas-dev/pandas-stubs#1641 discuss deprecation check( assert_type(s0.dt.to_pydatetime(), np_1darray_object), - np_1darray_object if PD_LTE_23 else pd.Series, + pd.Series, dt.datetime, ) s0_local = s0.dt.tz_localize("UTC") @@ -543,7 +538,7 @@ def test_series_dt_accessors() -> None: upper="2.99", ), pytest_warns_bounded( - Pandas4Warning, # should be Pandas4Warning but only exposed starting pandas 3.0.0 + Pandas4Warning, "The behavior of TimedeltaProperties.to_pytimedelta is deprecated", lower="2.99", upper="3.0.99", diff --git a/tests/test_windowing.py b/tests/test_windowing.py index fd9364a0e..5f1227f23 100644 --- a/tests/test_windowing.py +++ b/tests/test_windowing.py @@ -21,7 +21,6 @@ from pandas._libs.tslibs.offsets import BaseOffset from tests import ( - PD_LTE_23, check, pytest_warns_bounded, ) @@ -350,24 +349,6 @@ def test_ewm_basic_math() -> None: def test_ewm_aggregate() -> None: - if PD_LTE_23: - with pytest_warns_bounded( - FutureWarning, - r"The provided callable is currently using ", - upper="2.3.99", - ): - check(assert_type(DF.ewm(span=10).aggregate(np.mean), DataFrame), DataFrame) - check( - assert_type(DF.ewm(span=10).aggregate(["mean", np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type( - DF.ewm(span=10).aggregate({"col1": "mean", "col2": np.mean}), - DataFrame, - ), - DataFrame, - ) check(assert_type(DF.ewm(span=10).agg("sum"), DataFrame), DataFrame) @@ -381,24 +362,6 @@ def test_ewm_basic_math_series() -> None: def test_ewm_aggregate_series() -> None: - if PD_LTE_23: - with pytest_warns_bounded( - FutureWarning, - r"The provided callable is currently using ", - upper="2.3.99", - ): - check(assert_type(S.ewm(span=10).aggregate(np.mean), Series), Series) - check( - assert_type(S.ewm(span=10).aggregate(["mean", np.mean]), DataFrame), - DataFrame, - ) - check( - assert_type( - S.ewm(span=10).aggregate({"col1": "mean", "col2": np.mean}), - DataFrame, - ), - DataFrame, - ) check(assert_type(S.ewm(span=10).agg("sum"), Series), Series)