diff --git a/pandas-stubs/core/arrays/boolean.pyi b/pandas-stubs/core/arrays/boolean.pyi index 478ef8f9a..b3739bd1c 100644 --- a/pandas-stubs/core/arrays/boolean.pyi +++ b/pandas-stubs/core/arrays/boolean.pyi @@ -1,5 +1,4 @@ from collections.abc import Sequence -from typing import Any import numpy as np from pandas.core.arrays.integer import IntegerArray @@ -25,10 +24,7 @@ class BooleanArray(BaseMaskedArray): self, values: np_ndarray_bool, mask: np_ndarray_bool, copy: bool = ... ) -> None: ... @property - def dtype(self): ... - def __setitem__(self, key, value) -> None: ... - def any(self, *, skipna: bool = ..., **kwargs: Any): ... - def all(self, *, skipna: bool = ..., **kwargs: Any): ... + def dtype(self) -> BooleanDtype: ... def __and__( self, other: ( diff --git a/pandas-stubs/core/arrays/categorical.pyi b/pandas-stubs/core/arrays/categorical.pyi index bd106a9b9..3c02b8c34 100644 --- a/pandas-stubs/core/arrays/categorical.pyi +++ b/pandas-stubs/core/arrays/categorical.pyi @@ -1,49 +1,58 @@ from collections.abc import ( Callable, + Container, + Hashable, Sequence, ) +import sys from typing import ( Any, overload, ) import numpy as np +import numpy.typing as npt from pandas import Series from pandas.core.accessor import PandasDelegate as PandasDelegate from pandas.core.arrays.base import ExtensionArray as ExtensionArray from pandas.core.base import NoNewAttributesMixin as NoNewAttributesMixin from pandas.core.indexes.base import Index +from pandas.core.indexes.category import CategoricalIndex from typing_extensions import Self from pandas._typing import ( + AnyArrayLike, ListLike, NpDtype, Ordered, PositionalIndexerTuple, + Renamer, Scalar, ScalarIndexer, SequenceIndexer, - TakeIndexer, np_1darray, + np_1darray_anyint, np_1darray_bool, ) from pandas.core.dtypes.dtypes import CategoricalDtype as CategoricalDtype -def contains(cat, key, container): ... +def contains( + cat: Categorical | CategoricalIndex, key: Hashable, container: Container +) -> bool: ... class Categorical(ExtensionArray): __array_priority__: int = ... def __init__( self, values: ListLike, - categories=..., - ordered: bool | None = ..., - dtype: CategoricalDtype | None = ..., - fastpath: bool = ..., + categories: ListLike | None = None, + ordered: bool | None = None, + dtype: CategoricalDtype | None = None, + fastpath: bool = True, ) -> None: ... @property - def categories(self): ... + def categories(self) -> Index: ... @property def ordered(self) -> Ordered: ... @property @@ -62,56 +71,48 @@ class Categorical(ExtensionArray): ) -> Categorical: ... @property def codes(self) -> np_1darray[np.signedinteger]: ... - def set_ordered(self, value) -> Categorical: ... + def set_ordered(self, value: bool) -> Categorical: ... def as_ordered(self) -> Categorical: ... def as_unordered(self) -> Categorical: ... def set_categories( self, - new_categories, + new_categories: AnyArrayLike, ordered: bool | None = False, rename: bool = False, ) -> Categorical: ... - def rename_categories(self, new_categories) -> Categorical: ... + def rename_categories(self, new_categories: AnyArrayLike) -> Categorical: ... def reorder_categories( - self, new_categories, ordered: bool | None = ... + self, new_categories: AnyArrayLike, ordered: bool | None = ... ) -> Categorical: ... - def add_categories(self, new_categories) -> Categorical: ... - def remove_categories(self, removals) -> Categorical: ... def remove_unused_categories(self) -> Categorical: ... - def map(self, mapper): ... - def __eq__(self, other) -> bool: ... - def __ne__(self, other) -> bool: ... - def __lt__(self, other) -> bool: ... - def __gt__(self, other) -> bool: ... - def __le__(self, other) -> bool: ... - def __ge__(self, other) -> bool: ... - @property - def shape(self): ... - def shift(self, periods=1, fill_value=...): ... + def map(self, mapper: Renamer) -> CategoricalIndex | Index: ... def __array__( self, dtype: NpDtype | None = None, copy: bool | None = None ) -> np_1darray: ... @property - def T(self): ... + def T(self) -> Self: ... @property def nbytes(self) -> int: ... - def memory_usage(self, deep: bool = ...): ... + def memory_usage(self, deep: bool = False) -> int: ... def isna(self) -> np_1darray_bool: ... def isnull(self) -> np_1darray_bool: ... def notna(self) -> np_1darray_bool: ... def notnull(self) -> np_1darray_bool: ... - def dropna(self): ... - def value_counts(self, dropna: bool = True): ... - def check_for_ordered(self, op) -> None: ... - def argsort(self, *, ascending: bool = ..., kind: str = ..., **kwargs: Any): ... + def value_counts(self, dropna: bool = True) -> Series: ... + def check_for_ordered(self, op: Any) -> None: ... + if sys.version_info >= (3, 11): + def argsort( + self, *, ascending: bool = ..., kind: str = ..., **kwargs: Any + ) -> npt.NDArray[np.intp]: ... + else: + def argsort( + self, *, ascending: bool = ..., kind: str = ..., **kwargs: Any + ) -> np_1darray_anyint: ... + def sort_values( self, *, inplace: bool = ..., ascending: bool = ..., na_position: str = ... - ): ... - def view(self, dtype=...): ... - def take( - self, indexer: TakeIndexer, *, allow_fill: bool = ..., fill_value=... - ) -> Categorical: ... - def __contains__(self, item) -> bool: ... + ) -> Self: ... + def __contains__(self, item: Hashable) -> bool: ... @overload def __getitem__( # pyrefly: ignore[bad-override,bad-param-name-override] self, key: ScalarIndexer @@ -120,17 +121,9 @@ class Categorical(ExtensionArray): def __getitem__( # ty: ignore[invalid-method-override] self, key: SequenceIndexer | PositionalIndexerTuple ) -> Self: ... - def __setitem__(self, key, value) -> None: ... - def min(self, *, skipna: bool = ...): ... - def max(self, *, skipna: bool = ...): ... - def unique(self): ... - def equals(self, other): ... - def describe(self): ... - def repeat(self, repeats, axis=...): ... - def isin(self, values): ... class CategoricalAccessor(PandasDelegate, NoNewAttributesMixin): - def __init__(self, data) -> None: ... + def __init__(self, data: Series | CategoricalIndex) -> None: ... @property def codes(self) -> Series[int]: ... @property diff --git a/pandas-stubs/core/arrays/datetimelike.pyi b/pandas-stubs/core/arrays/datetimelike.pyi index acc732885..9db5e52e2 100644 --- a/pandas-stubs/core/arrays/datetimelike.pyi +++ b/pandas-stubs/core/arrays/datetimelike.pyi @@ -1,10 +1,12 @@ from collections.abc import Sequence +from datetime import datetime from typing import ( - Any, TypeAlias, overload, ) +import numpy as np +import numpy.typing as npt from pandas.core.arrays.base import ( ExtensionArray, ExtensionOpsMixin, @@ -17,6 +19,8 @@ from pandas._libs import ( ) from pandas._typing import ( DatetimeLikeScalar, + DtypeArg, + Frequency, NpDtype, PositionalIndexerTuple, ScalarIndexer, @@ -30,7 +34,7 @@ from pandas._typing import ( DTScalarOrNaT: TypeAlias = DatetimeLikeScalar | NaTType class DatelikeOps: - def strftime(self, date_format): ... + def strftime(self, date_format: str) -> npt.NDArray[np.object_]: ... class TimelikeOps: @property @@ -38,33 +42,26 @@ class TimelikeOps: def as_unit(self, unit: TimeUnit) -> Self: ... def round( self, - freq, + freq: Frequency, ambiguous: TimeAmbiguous = "raise", nonexistent: TimeNonexistent = "raise", - ): ... + ) -> Self: ... def floor( self, - freq, + freq: Frequency, ambiguous: TimeAmbiguous = "raise", nonexistent: TimeNonexistent = "raise", - ): ... + ) -> Self: ... def ceil( self, - freq, + freq: Frequency, ambiguous: TimeAmbiguous = "raise", nonexistent: TimeNonexistent = "raise", - ): ... + ) -> Self: ... class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray): @property def ndim(self) -> int: ... - @property - def shape(self): ... - def reshape(self, *args: Any, **kwargs: Any): ... - def ravel(self, *args: Any, **kwargs: Any): ... - def __iter__(self): ... - @property - def nbytes(self): ... def __array__( self, dtype: NpDtype | None = None, copy: bool | None = None ) -> np_1darray: ... @@ -79,35 +76,20 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray): self, key: SequenceIndexer | PositionalIndexerTuple ) -> Self: ... def __setitem__( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] - self, key: int | Sequence[int] | Sequence[bool] | slice, value + self, key: int | Sequence[int] | Sequence[bool] | slice, value: datetime ) -> None: ... - def view(self, dtype=...): ... - def unique(self): ... - def copy(self): ... - def shift(self, periods: int = 1, fill_value=..., axis: int = ...): ... - def repeat(self, repeats, *args: Any, **kwargs: Any): ... - def value_counts(self, dropna: bool = True): ... - def map(self, mapper): ... - def isna(self): ... + def view(self, dtype: DtypeArg | None = None) -> Self: ... + def copy(self) -> Self: ... @property - def freq(self): ... + def freq(self) -> Frequency | None: ... @freq.setter - def freq(self, value) -> None: ... + def freq(self, value: Frequency | None) -> None: ... @property - def freqstr(self): ... + def freqstr(self) -> str | None: ... @property - def inferred_freq(self): ... + def inferred_freq(self) -> str | None: ... @property - def resolution(self): ... + def resolution(self) -> str: ... __pow__ = ... __rpow__ = ... __rmul__ = ... - def __add__(self, other): ... - def __radd__(self, other): ... - def __sub__(self, other): ... - def __rsub__(self, other): ... - def __iadd__(self, other): ... - def __isub__(self, other): ... - def min(self, *, axis=..., skipna: bool = ..., **kwargs: Any): ... - def max(self, *, axis=..., skipna: bool = ..., **kwargs: Any): ... - def mean(self, *, skipna: bool = ...): ... diff --git a/pandas-stubs/core/arrays/datetimes.pyi b/pandas-stubs/core/arrays/datetimes.pyi index 79b36c0f3..8cb7ffc71 100644 --- a/pandas-stubs/core/arrays/datetimes.pyi +++ b/pandas-stubs/core/arrays/datetimes.pyi @@ -3,23 +3,39 @@ import sys from typing import Any import numpy as np +import numpy.typing as npt from pandas.core.arrays.datetimelike import ( DatelikeOps, DatetimeLikeArrayMixin, TimelikeOps, ) +from pandas.core.arrays.period import PeriodArray +from pandas.core.indexes.base import Index +from pandas.core.series import Series +from typing_extensions import Self +from pandas._libs.tslibs.period import Period from pandas._typing import ( + DtypeArg, + Frequency, TimeAmbiguous, TimeNonexistent, TimeZones, + np_1darray_float, + np_1darray_object, ) from pandas.core.dtypes.dtypes import DatetimeTZDtype as DatetimeTZDtype class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps): __array_priority__: int = ... - def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ... + def __init__( + self, + values: Series | Index | DatetimeArray | npt.NDArray[np.object_], + dtype: DtypeArg | None = None, + freq: Frequency | None = None, + copy: bool = False, + ) -> None: ... # ignore in dtype() is from the pandas source if sys.version_info >= (3, 11): @property @@ -28,34 +44,28 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps): @property def dtype(self) -> np.dtype[Any] | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] - @property - def tz(self): ... - @tz.setter - def tz(self, value) -> None: ... @property def tzinfo(self) -> _tzinfo | None: ... @property - def is_normalized(self): ... - def __iter__(self): ... - def tz_convert(self, tz: TimeZones): ... + def is_normalized(self) -> bool: ... + def tz_convert(self, tz: TimeZones) -> Self: ... def tz_localize( self, tz: TimeZones, ambiguous: TimeAmbiguous = "raise", nonexistent: TimeNonexistent = "raise", - ): ... - def to_pydatetime(self): ... - def normalize(self): ... - def to_period(self, freq=...): ... - def to_perioddelta(self, freq): ... - def month_name(self, locale=...): ... - def day_name(self, locale=...): ... + ) -> Self: ... + def to_pydatetime(self) -> np_1darray_object: ... + def normalize(self) -> Self: ... + def to_period(self, freq: str | Period | None = None) -> PeriodArray: ... + def month_name(self, locale: str | None = None) -> Series | Index: ... + def day_name(self, locale: str | None = None) -> Series | Index: ... @property - def time(self): ... + def time(self) -> npt.NDArray[np.object_]: ... @property - def timetz(self): ... + def timetz(self) -> npt.NDArray[np.object_]: ... @property - def date(self): ... + def date(self) -> npt.NDArray[np.object_]: ... year = ... month = ... day = ... @@ -77,4 +87,4 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps): is_year_start = ... is_year_end = ... is_leap_year = ... - def to_julian_date(self): ... + def to_julian_date(self) -> np_1darray_float: ... diff --git a/pandas-stubs/core/arrays/integer.pyi b/pandas-stubs/core/arrays/integer.pyi index a32233414..6674a736f 100644 --- a/pandas-stubs/core/arrays/integer.pyi +++ b/pandas-stubs/core/arrays/integer.pyi @@ -1,6 +1,10 @@ from pandas.core.arrays.masked import BaseMaskedArray from pandas._libs.missing import NAType +from pandas._typing import ( + AnyArrayLike, + np_ndarray, +) from pandas.core.dtypes.base import ExtensionDtype as ExtensionDtype @@ -16,8 +20,9 @@ class _IntegerDtype(ExtensionDtype): class IntegerArray(BaseMaskedArray): @property def dtype(self) -> _IntegerDtype: ... - def __init__(self, values, mask, copy: bool = ...) -> None: ... - def __setitem__(self, key, value) -> None: ... + def __init__( + self, values: AnyArrayLike, mask: np_ndarray, copy: bool = False + ) -> None: ... class Int8Dtype(_IntegerDtype): ... class Int16Dtype(_IntegerDtype): ... diff --git a/pandas-stubs/core/arrays/interval.pyi b/pandas-stubs/core/arrays/interval.pyi index 169a295e7..2c6413b64 100644 --- a/pandas-stubs/core/arrays/interval.pyi +++ b/pandas-stubs/core/arrays/interval.pyi @@ -14,7 +14,10 @@ from pandas._libs.interval import ( IntervalMixin as IntervalMixin, ) from pandas._typing import ( + AnyArrayLike, Axis, + DtypeArg, + IntervalClosedType, NpDtype, Scalar, ScalarIndexer, @@ -30,32 +33,37 @@ IntervalOrNA: TypeAlias = Interval | float class IntervalArray(IntervalMixin, ExtensionArray): can_hold_na: bool = ... def __new__( - cls, data, closed=..., dtype=..., copy: bool = ..., verify_integrity: bool = ... + cls, + data: AnyArrayLike, + closed: IntervalClosedType = "right", + dtype: DtypeArg | None = None, + copy: bool = False, + verify_integrity: bool = True, ) -> Self: ... @classmethod def from_breaks( cls, - breaks, + breaks: AnyArrayLike, closed: str = "right", copy: bool = False, - dtype=None, + dtype: DtypeArg | None = None, ) -> Self: ... @classmethod def from_arrays( cls, - left, - right, + left: AnyArrayLike, + right: AnyArrayLike, closed: str = "right", copy: bool = False, - dtype=..., + dtype: DtypeArg | None = None, ) -> Self: ... @classmethod def from_tuples( cls, - data, + data: AnyArrayLike, closed: str = "right", copy: bool = False, - dtype=None, + dtype: DtypeArg | None = None, ) -> Self: ... def __array__( self, dtype: NpDtype | None = None, copy: bool | None = None @@ -64,13 +72,6 @@ class IntervalArray(IntervalMixin, ExtensionArray): def __getitem__(self, item: ScalarIndexer) -> IntervalOrNA: ... @overload def __getitem__(self, item: SequenceIndexer) -> Self: ... - def __setitem__(self, key, value) -> None: ... - def __eq__(self, other): ... - def __ne__(self, other): ... - @property - def dtype(self): ... - def copy(self): ... - def isna(self): ... @property def nbytes(self) -> int: ... @property @@ -81,27 +82,22 @@ class IntervalArray(IntervalMixin, ExtensionArray): indices: TakeIndexer, *, allow_fill: bool = ..., - fill_value=..., - axis=..., + fill_value: Interval | None = None, + axis: Axis | None = None, **kwargs: Any, ) -> Self: ... - def value_counts(self, dropna: bool = True): ... @property def left(self) -> Index: ... @property def right(self) -> Index: ... @property def closed(self) -> bool: ... - def set_closed(self, closed): ... @property def length(self) -> Index: ... @property def mid(self) -> Index: ... @property def is_non_overlapping_monotonic(self) -> bool: ... - def __arrow_array__(self, type=...): ... - def to_tuples(self, na_tuple: bool = True): ... - def repeat(self, repeats, axis: Axis | None = ...): ... @overload def contains(self, other: Series) -> Series[bool]: ... @overload diff --git a/pandas-stubs/core/arrays/masked.pyi b/pandas-stubs/core/arrays/masked.pyi index 89bf39012..0416dbc71 100644 --- a/pandas-stubs/core/arrays/masked.pyi +++ b/pandas-stubs/core/arrays/masked.pyi @@ -1,3 +1,4 @@ +from collections.abc import Iterator from typing import ( Any, overload, @@ -7,9 +8,11 @@ from pandas.core.arrays import ( ExtensionArray as ExtensionArray, ExtensionOpsMixin, ) +from pandas.core.series import Series from typing_extensions import Self from pandas._typing import ( + DtypeArg, NpDtype, Scalar, ScalarIndexer, @@ -23,8 +26,11 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin): def __getitem__(self, item: ScalarIndexer) -> Any: ... @overload def __getitem__(self, item: SequenceIndexer) -> Self: ... - def __iter__(self): ... - def __invert__(self): ... + def __iter__(self) -> Iterator: ... + def __invert__(self) -> Self: ... + def __arrow_array__(self, type: DtypeArg | None = None) -> Any: ... + def copy(self) -> Self: ... + def value_counts(self, dropna: bool = True) -> Series: ... def to_numpy( self, dtype: npt.DTypeLike | None = ..., @@ -35,9 +41,5 @@ class BaseMaskedArray(ExtensionArray, ExtensionOpsMixin): def __array__( self, dtype: NpDtype | None = None, copy: bool | None = None ) -> np_1darray: ... - def __arrow_array__(self, type=...): ... - def isna(self): ... @property def nbytes(self) -> int: ... - def copy(self): ... - def value_counts(self, dropna: bool = True): ... diff --git a/pandas-stubs/core/arrays/period.pyi b/pandas-stubs/core/arrays/period.pyi index 5eaf014dc..030821f7f 100644 --- a/pandas-stubs/core/arrays/period.pyi +++ b/pandas-stubs/core/arrays/period.pyi @@ -1,26 +1,42 @@ +from typing import ( + Any, +) + from pandas import PeriodDtype from pandas.core.arrays.datetimelike import ( DatelikeOps, DatetimeLikeArrayMixin, ) +from pandas.core.indexes.period import PeriodIndex +from pandas.core.series import Series +from typing_extensions import Self from pandas._libs.tslibs import Timestamp from pandas._libs.tslibs.period import Period from pandas._typing import ( + DtypeArg, + Frequency, NpDtype, PeriodFrequency, np_1darray, + np_ndarray_anyint, ) class PeriodArray(DatetimeLikeArrayMixin, DatelikeOps): __array_priority__: int = ... - def __init__(self, values, freq=..., dtype=..., copy: bool = ...) -> None: ... + def __new__( + cls, + values: np_ndarray_anyint | PeriodArray | PeriodIndex | Series[Period], + freq: Frequency | None = None, + dtype: PeriodDtype | None = None, + copy: bool = ..., + ) -> Self: ... @property def dtype(self) -> PeriodDtype: ... def __array__( self, dtype: NpDtype | None = None, copy: bool | None = None ) -> np_1darray: ... - def __arrow_array__(self, type=...): ... + def __arrow_array__(self, type: DtypeArg | None = None) -> Any: ... year: int = ... month: int = ... day: int = ... diff --git a/pandas-stubs/core/arrays/sparse/__init__.pyi b/pandas-stubs/core/arrays/sparse/__init__.pyi index 4f2540a89..7e4c57848 100644 --- a/pandas-stubs/core/arrays/sparse/__init__.pyi +++ b/pandas-stubs/core/arrays/sparse/__init__.pyi @@ -1,6 +1,2 @@ -from pandas.core.arrays.sparse.accessor import ( - SparseAccessor as SparseAccessor, - SparseFrameAccessor as SparseFrameAccessor, -) from pandas.core.arrays.sparse.array import SparseArray as SparseArray from pandas.core.arrays.sparse.dtype import SparseDtype as SparseDtype diff --git a/pandas-stubs/core/arrays/sparse/accessor.pyi b/pandas-stubs/core/arrays/sparse/accessor.pyi deleted file mode 100644 index c99a2558b..000000000 --- a/pandas-stubs/core/arrays/sparse/accessor.pyi +++ /dev/null @@ -1,20 +0,0 @@ -from pandas.core.accessor import PandasDelegate -from pandas.core.series import Series -from typing_extensions import Self - -class BaseAccessor: - def __init__(self, data=...) -> None: ... - -class SparseAccessor(BaseAccessor, PandasDelegate): - @classmethod - def from_coo(cls, A, dense_index: bool = False) -> Series: ... - def to_coo(self, row_levels=..., column_levels=..., sort_labels: bool = False): ... - def to_dense(self): ... - -class SparseFrameAccessor(BaseAccessor, PandasDelegate): - @classmethod - def from_spmatrix(cls, data, index=..., columns=...) -> Self: ... - def to_dense(self): ... - def to_coo(self): ... - @property - def density(self) -> float: ... diff --git a/pandas-stubs/core/arrays/sparse/array.pyi b/pandas-stubs/core/arrays/sparse/array.pyi index b10e64059..a5252af71 100644 --- a/pandas-stubs/core/arrays/sparse/array.pyi +++ b/pandas-stubs/core/arrays/sparse/array.pyi @@ -1,65 +1,79 @@ from enum import Enum +import sys from typing import ( Any, final, overload, ) +import numpy as np from pandas.core.arrays import ( ExtensionArray, ExtensionOpsMixin, ) from typing_extensions import Self +from pandas._libs.sparse import SparseIndex from pandas._typing import ( + AnyArrayLike, NpDtype, + Scalar, ScalarIndexer, SequenceIndexer, np_1darray, ) +from pandas.core.dtypes.dtypes import SparseDtype + @final class ellipsis(Enum): Ellipsis = "..." class SparseArray(ExtensionArray, ExtensionOpsMixin): - def __init__( - self, - data, - sparse_index=..., - fill_value=..., - kind: str = ..., - dtype=..., - copy: bool = ..., - ) -> None: ... + if sys.version_info >= (3, 11): + def __new__( + cls, + data: AnyArrayLike | Scalar, + sparse_index: SparseIndex | None = None, + fill_value: Scalar | None = None, + kind: str = "integer", + dtype: np.dtype | SparseDtype | None = ..., + copy: bool = ..., + ) -> Self: ... + else: + def __new__( + cls, + data: AnyArrayLike | Scalar, + sparse_index: SparseIndex | None = None, + fill_value: Scalar | None = None, + kind: str = "integer", + dtype: np.dtype[Any] | SparseDtype | None = ..., + copy: bool = ..., + ) -> Self: ... + @classmethod - def from_spmatrix(cls, data) -> Self: ... - def __array__( - self, dtype: NpDtype | None = None, copy: bool | None = None - ) -> np_1darray: ... - def __setitem__(self, key, value) -> None: ... + def from_spmatrix(cls, data: Any) -> Self: ... @property - def sp_index(self): ... + def sp_index(self) -> SparseIndex: ... @property - def sp_values(self): ... + def sp_values(self) -> np.ndarray: ... @property - def dtype(self): ... + def dtype(self) -> SparseDtype: ... @property - def fill_value(self): ... + def fill_value(self) -> Any: ... @fill_value.setter - def fill_value(self, value) -> None: ... + def fill_value(self, value: Any) -> None: ... + def __array__( + self, dtype: NpDtype | None = None, copy: bool | None = None + ) -> np_1darray: ... @property def kind(self) -> str: ... @property def nbytes(self) -> int: ... @property - def density(self): ... + def density(self) -> float: ... @property def npoints(self) -> int: ... - def isna(self): ... - def shift(self, periods: int = 1, fill_value=...): ... - def unique(self): ... - def value_counts(self, dropna: bool = True): ... @overload def __getitem__( # pyrefly: ignore[bad-override,bad-param-name-override] self, key: ScalarIndexer @@ -68,15 +82,3 @@ class SparseArray(ExtensionArray, ExtensionOpsMixin): def __getitem__( # ty: ignore[invalid-method-override] self, key: SequenceIndexer | tuple[int | ellipsis, ...] ) -> Self: ... - def copy(self): ... - def map(self, mapper): ... - def to_dense(self): ... - def nonzero(self): ... - def all(self, axis=..., *args: Any, **kwargs: Any): ... - def any(self, axis: int = ..., *args: Any, **kwargs: Any): ... - def sum(self, axis: int = 0, *args: Any, **kwargs: Any): ... - def cumsum(self, axis: int = ..., *args: Any, **kwargs: Any): ... - def mean(self, axis: int = ..., *args: Any, **kwargs: Any): ... - @property - def T(self): ... - def __abs__(self): ... diff --git a/pandas-stubs/core/arrays/string_.pyi b/pandas-stubs/core/arrays/string_.pyi index 845870de7..10ad1d0f7 100644 --- a/pandas-stubs/core/arrays/string_.pyi +++ b/pandas-stubs/core/arrays/string_.pyi @@ -1,8 +1,17 @@ -from typing import Literal +from typing import ( + Any, + Literal, +) from pandas.core.arrays import PandasArray +from pandas.core.series import Series +from typing_extensions import Self from pandas._libs.missing import NAType +from pandas._typing import ( + AnyArrayLike, + DtypeArg, +) from pandas.core.dtypes.base import ExtensionDtype @@ -12,7 +21,6 @@ class StringDtype(ExtensionDtype): def na_value(self) -> NAType: ... class StringArray(PandasArray): - def __init__(self, values, copy: bool = ...) -> None: ... - def __arrow_array__(self, type=...): ... - def __setitem__(self, key, value) -> None: ... - def value_counts(self, dropna: bool = True): ... + def __new__(cls, values: AnyArrayLike, copy: bool = False) -> Self: ... + def value_counts(self, dropna: bool = True) -> Series: ... + def __arrow_array__(self, type: DtypeArg | None = None) -> Any: ... diff --git a/pandas-stubs/core/arrays/timedeltas.pyi b/pandas-stubs/core/arrays/timedeltas.pyi index fd0d71c99..e4868f6b7 100644 --- a/pandas-stubs/core/arrays/timedeltas.pyi +++ b/pandas-stubs/core/arrays/timedeltas.pyi @@ -5,55 +5,23 @@ from pandas.core.arrays.datetimelike import ( DatetimeLikeArrayMixin, TimelikeOps, ) +from typing_extensions import Self + +from pandas._typing import ( + AnyArrayLike, + DtypeArg, + Frequency, +) class TimedeltaArray(DatetimeLikeArrayMixin, TimelikeOps): __array_priority__: int = ... - @property - def dtype(self): ... - def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ... - def sum( - self, - *, - axis=..., - dtype=..., - out=..., - keepdims: bool = ..., - initial=..., - skipna: bool = ..., - min_count: int = ..., - ): ... - def std( - self, - *, - axis=..., - dtype=..., - out=..., - ddof: int = ..., - keepdims: bool = ..., - skipna: bool = ..., - ): ... - def median( - self, - *, - axis=..., - out=..., - overwrite_input: bool = ..., - keepdims: bool = ..., - skipna: bool = ..., - ): ... - def __mul__(self, other): ... - __rmul__ = ... - def __truediv__(self, other): ... - def __rtruediv__(self, other): ... - def __floordiv__(self, other): ... - def __rfloordiv__(self, other): ... - def __mod__(self, other): ... - def __rmod__(self, other): ... - def __divmod__(self, other): ... - def __rdivmod__(self, other): ... - def __neg__(self): ... - def __pos__(self): ... - def __abs__(self): ... + def __new__( + cls, + values: AnyArrayLike, + dtype: DtypeArg | None = None, + freq: Frequency | None = None, + copy: bool = False, + ) -> Self: ... def total_seconds(self) -> int: ... def to_pytimedelta(self) -> Sequence[timedelta]: ... days: int = ... diff --git a/pandas-stubs/core/dtypes/dtypes.pyi b/pandas-stubs/core/dtypes/dtypes.pyi index 73be65dcf..57659933e 100644 --- a/pandas-stubs/core/dtypes/dtypes.pyi +++ b/pandas-stubs/core/dtypes/dtypes.pyi @@ -60,9 +60,12 @@ class PeriodDtype(PandasExtensionDtype): class IntervalDtype(PandasExtensionDtype): def __init__(self, subtype: str | npt.DTypeLike | None = ...) -> None: ... + if sys.version_info >= (3, 11): @property def subtype(self) -> np.dtype | None: ... else: @property def subtype(self) -> np.dtype[Any] | None: ... + +class SparseDtype(ExtensionDtype): ... diff --git a/pandas-stubs/io/excel/_base.pyi b/pandas-stubs/io/excel/_base.pyi index fb676a64c..382b7fb87 100644 --- a/pandas-stubs/io/excel/_base.pyi +++ b/pandas-stubs/io/excel/_base.pyi @@ -304,7 +304,7 @@ class ExcelFile: storage_options: StorageOptions = ..., engine_kwargs: dict[str, Any] | None = ..., ) -> None: ... - def __fspath__(self): ... + def __fspath__(self) -> str: ... @overload def parse( self, diff --git a/pyproject.toml b/pyproject.toml index 6997d49d6..5a5f16b48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -209,12 +209,8 @@ ignore = [ # TODO: remove when window is fully typed "ANN001", "ANN201", "ANN204", "ANN206", ] -"*array*" = [ - # TODO: remove when array is fully typed - "ANN001", "ANN201", "ANN204", "ANN206", -] -"*excel/_base.pyi" = [ - # TODO: remove when excel/_base.pyi is fully typed +"*generic.pyi" = [ + # TODO: remove when generic.pyi is fully typed "ANN001", "ANN201", "ANN204", "ANN206", ] "scripts/*" = [