Skip to content

Commit

Permalink
Pandas 2.2; remove some deprecated behavior; update pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein committed Feb 10, 2024
1 parent 56a5564 commit 47890d6
Show file tree
Hide file tree
Showing 27 changed files with 393 additions and 527 deletions.
2 changes: 0 additions & 2 deletions pandas-stubs/_libs/lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from typing import (
)

import numpy as np
from pandas import Interval
from typing_extensions import (
TypeAlias,
TypeGuard,
Expand All @@ -21,7 +20,6 @@ def infer_dtype(value: object, skipna: bool = ...) -> str: ...
def is_iterator(obj: object) -> bool: ...
def is_scalar(val: object) -> bool: ...
def is_list_like(obj: object, allow_sets: bool = ...) -> bool: ...
def is_interval(val: object) -> TypeGuard[Interval]: ...
def is_complex(val: object) -> TypeGuard[complex]: ...
def is_bool(val: object) -> TypeGuard[bool | np.bool_]: ...
def is_integer(val: object) -> TypeGuard[int | np.integer]: ...
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/api/types/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ from pandas.core.dtypes.api import (
is_hashable as is_hashable,
is_integer as is_integer,
is_integer_dtype as is_integer_dtype,
is_interval as is_interval,
is_iterator as is_iterator,
is_list_like as is_list_like,
is_named_tuple as is_named_tuple,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/dtypes/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ from pandas.core.dtypes.common import (
is_hashable as is_hashable,
is_integer as is_integer,
is_integer_dtype as is_integer_dtype,
is_interval as is_interval,
is_iterator as is_iterator,
is_list_like as is_list_like,
is_named_tuple as is_named_tuple,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/dtypes/common.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ from pandas.core.dtypes.inference import (
is_float as is_float,
is_hashable as is_hashable,
is_integer as is_integer,
is_interval as is_interval,
is_iterator as is_iterator,
is_list_like as is_list_like,
is_named_tuple as is_named_tuple,
Expand Down
1 change: 0 additions & 1 deletion pandas-stubs/core/dtypes/inference.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ is_integer = lib.is_integer
is_float = lib.is_float
is_complex = lib.is_complex
is_scalar = lib.is_scalar
is_interval = lib.is_interval
is_list_like = lib.is_list_like
is_iterator = lib.is_iterator

Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ class DataFrame(NDFrame, OpsMixin):
self,
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: Axis | None = ...,
limit: int = ...,
downcast: dict | None = ...,
Expand All @@ -721,7 +720,6 @@ class DataFrame(NDFrame, OpsMixin):
self,
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: Axis | None = ...,
limit: int = ...,
downcast: dict | None = ...,
Expand All @@ -732,7 +730,6 @@ class DataFrame(NDFrame, OpsMixin):
self,
value: Scalar | NAType | dict | Series | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: Axis | None = ...,
inplace: _bool | None = ...,
limit: int = ...,
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class NDFrame(indexing.IndexingMixin):
def to_hdf(
self,
path_or_buf: FilePath | HDFStore,
*,
key: _str,
mode: Literal["a", "w", "r+"] = ...,
complevel: int | None = ...,
Expand Down Expand Up @@ -403,7 +404,6 @@ class NDFrame(indexing.IndexingMixin):
self,
value=...,
*,
method=...,
axis=...,
inplace: _bool = ...,
limit=...,
Expand Down
11 changes: 0 additions & 11 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,6 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]):
ascending: bool = ...,
dropna: bool = ...,
) -> Series[float]: ...
def fillna(
self,
value: (
Scalar | ArrayLike | Series | DataFrame | Mapping[Hashable, Scalar] | None
) = ...,
method: Literal["bfill", "ffill"] | None = ...,
axis: Axis | None | NoDefault = ...,
inplace: Literal[False] = ...,
limit: int | None = ...,
downcast: dict | None | NoDefault = ...,
) -> DataFrame: ...
def take(
self, indices: TakeIndexer, axis: Axis | None | NoDefault = ..., **kwargs
) -> DataFrame: ...
Expand Down
2 changes: 0 additions & 2 deletions pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
data: ArrayLike | AnyArrayLike | list | tuple,
freq=...,
tz=...,
normalize: bool = ...,
closed=...,
ambiguous: str = ...,
dayfirst: bool = ...,
yearfirst: bool = ...,
Expand Down
3 changes: 0 additions & 3 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
self,
value: Scalar | NAType | dict | Series[S1] | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: AxisIndex = ...,
limit: int | None = ...,
downcast: dict | None = ...,
Expand All @@ -1052,7 +1051,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
self,
value: Scalar | NAType | dict | Series[S1] | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: AxisIndex = ...,
limit: int | None = ...,
downcast: dict | None = ...,
Expand All @@ -1063,7 +1061,6 @@ class Series(IndexOpsMixin[S1], NDFrame):
self,
value: Scalar | NAType | dict | Series[S1] | DataFrame | None = ...,
*,
method: FillnaOptions | None = ...,
axis: AxisIndex = ...,
inplace: _bool = ...,
limit: int | None = ...,
Expand Down
7 changes: 0 additions & 7 deletions pandas-stubs/core/tools/numeric.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ def to_numeric(
dtype_backend: DtypeBackend | NoDefault = ...,
) -> float: ...
@overload
def to_numeric(
arg: Scalar,
errors: Literal["ignore"],
downcast: _Downcast = ...,
dtype_backend: DtypeBackend | NoDefault = ...,
) -> Scalar: ...
@overload
def to_numeric(
arg: list | tuple | np.ndarray,
errors: IgnoreRaiseCoerce = ...,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ numpy = { version = ">=1.26.0", python = "<3.13" }

[tool.poetry.group.dev.dependencies]
mypy = "1.8.0"
pandas = "2.1.4"
pandas = "2.2.0"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = "==1.1.346"
pyright = ">=1.1.350"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand Down
4 changes: 3 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def check(actual: T, klass: type, dtype: type | None = None, attr: str = "left")
elif isinstance(actual, BaseGroupBy):
value = actual.obj
elif hasattr(actual, "__iter__"):
value = next(iter(actual)) # pyright: ignore[reportGeneralTypeIssues]
value = next(
iter(actual) # pyright: ignore[reportArgumentType,reportCallIssue]
)
else:
assert hasattr(actual, attr)
value = getattr(actual, attr)
Expand Down
4 changes: 2 additions & 2 deletions tests/extension/decimal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
return result

if "out" in kwargs:
return arraylike.dispatch_ufunc_with_out( # type: ignore[attr-defined] # pyright: ignore[reportGeneralTypeIssues]
return arraylike.dispatch_ufunc_with_out( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
self, ufunc, method, *inputs, **kwargs
)

inputs = tuple(x._data if isinstance(x, DecimalArray) else x for x in inputs)
result = getattr(ufunc, method)(*inputs, **kwargs)

if method == "reduce":
result = arraylike.dispatch_reduction_ufunc( # type: ignore[attr-defined] # pyright: ignore[reportGeneralTypeIssues]
result = arraylike.dispatch_reduction_ufunc( # type: ignore[attr-defined] # pyright: ignore[reportAttributeAccessIssue]
self, ufunc, method, *inputs, **kwargs
)
if result is not NotImplemented:
Expand Down
20 changes: 1 addition & 19 deletions tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

from pandas._typing import DtypeObj

from tests import (
check,
pytest_warns_bounded,
)
from tests import check

nparr = np.array([1, 2, 3])
arr = pd.Series([1, 2, 3])
Expand Down Expand Up @@ -209,21 +206,6 @@ def test_is_integer_dtype() -> None:
# check(assert_type(api.is_integer_dtype(ExtensionDtype), bool), bool) pandas GH 50923


def test_is_interval() -> None:
with pytest_warns_bounded(
FutureWarning, "is_interval is deprecated", lower="2.1.99"
):
check(assert_type(api.is_interval(obj), bool), bool)
check(assert_type(api.is_interval(nparr), bool), bool)
check(assert_type(api.is_interval(dtylike), bool), bool)
check(assert_type(api.is_interval(arr), bool), bool)
check(
assert_type(api.is_interval(dframe), bool),
bool,
)
check(assert_type(api.is_interval(ind), bool), bool)


def test_is_iterator() -> None:
check(assert_type(api.is_iterator(obj), bool), bool)
check(assert_type(api.is_iterator(nparr), bool), bool)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def test_period_dtype() -> None:
check(assert_type(pd.PeriodDtype(freq=Day()), pd.PeriodDtype), pd.PeriodDtype)
if TYPE_CHECKING_INVALID_USAGE:
pd.PeriodDtype(
freq=CustomBusinessDay() # type:ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
freq=CustomBusinessDay() # type:ignore[arg-type] # pyright: ignore[reportArgumentType]
)
pd.PeriodDtype(
freq=BusinessDay() # type:ignore[arg-type] # pyright: ignore[reportGeneralTypeIssues]
freq=BusinessDay() # type:ignore[arg-type] # pyright: ignore[reportArgumentType]
)
check(
assert_type(p_dt.freq, pd.tseries.offsets.BaseOffset),
Expand Down
Loading

0 comments on commit 47890d6

Please sign in to comment.