Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pandas-stubs/core/arrays/boolean.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from collections.abc import Sequence
from typing import Any

import numpy as np
from pandas.core.arrays.integer import IntegerArray
Expand All @@ -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): ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are now in the BaseMaskedArray class with the correct overloads.

def all(self, *, skipna: bool = ..., **kwargs: Any): ...
def dtype(self) -> BooleanDtype: ...
def __and__(
self,
other: (
Expand Down
19 changes: 19 additions & 0 deletions pandas-stubs/core/arrays/masked.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from collections.abc import Iterator
from typing import (
Any,
Literal,
overload,
)

from pandas.core.arrays import ExtensionArray as ExtensionArray
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.missing import NAType
from pandas._typing import (
AxisInt,
DtypeArg,
NpDtype,
Scalar,
Expand Down Expand Up @@ -42,3 +45,19 @@ class BaseMaskedArray(ExtensionArray):
def isna(self) -> np_1darray_bool: ...
@property
def nbytes(self) -> int: ...
@overload
def any(
self, *, skipna: Literal[True] = True, axis: AxisInt | None = 0, **kwargs: Any
) -> bool: ...
@overload
def any(
self, *, skipna: bool, axis: AxisInt | None = 0, **kwargs: Any
) -> bool | NAType: ...
@overload
def all(
self, *, skipna: Literal[True] = True, axis: AxisInt | None = 0, **kwargs: Any
) -> bool: ...
@overload
def all(
self, *, skipna: bool, axis: AxisInt | None = 0, **kwargs: Any
) -> bool | NAType: ...
4 changes: 0 additions & 4 deletions pandas-stubs/core/arrays/sparse/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions pandas-stubs/core/arrays/sparse/accessor.pyi

This file was deleted.

110 changes: 77 additions & 33 deletions pandas-stubs/core/arrays/sparse/array.pyi
Original file line number Diff line number Diff line change
@@ -1,62 +1,97 @@
from collections.abc import (
Callable,
Hashable,
)
from enum import Enum
import sys
from typing import (
Any,
Literal,
Protocol,
final,
overload,
type_check_only,
)

import numpy as np
from pandas.core.arrays import ExtensionArray
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.sparse import SparseIndex
from pandas._typing import (
AnyArrayLike,
Axis,
AxisInt,
NpDtype,
Scalar,
ScalarIndexer,
SequenceIndexer,
np_1darray,
np_ndarray,
np_ndarray_int,
)

from pandas.core.dtypes.dtypes import SparseDtype

@type_check_only
class _SparseMatrixLike(Protocol):
@property
def shape(self, /) -> tuple[int, int]: ...

@final
class ellipsis(Enum):
Ellipsis = "..."

class SparseArray(ExtensionArray):
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 from_spmatrix(cls, data: _SparseMatrixLike) -> Self: ...
def __array__(
self, dtype: NpDtype | None = None, copy: bool | None = None
) -> np_1darray: ...
def __setitem__(self, key, value) -> None: ...
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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: ...
@property
def kind(self) -> str: ...
def kind(self) -> Literal["integer", "block"]: ...
@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): ...
def isna(self) -> Self: ...
def shift(self, periods: int = 1, fill_value: Hashable = None) -> Self: ...
def unique(self) -> Self: ...
def value_counts(self, dropna: bool = True) -> Series[int]: ...
@overload
def __getitem__( # pyrefly: ignore[bad-param-name-override]
self, key: ScalarIndexer
Expand All @@ -65,15 +100,24 @@ class SparseArray(ExtensionArray):
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): ...
def copy(self) -> Self: ...
def map(
self, mapper: dict[Any, Any] | Series[Any] | Callable[..., Any]
) -> Self: ...
def to_dense(self) -> np_ndarray: ...
def nonzero(self) -> tuple[np_ndarray_int]: ...
def all(self, axis: Axis | None = None, *args: Any, **kwargs: Any) -> bool: ...
def any(self, axis: AxisInt = 0, *args: Any, **kwargs: Any) -> bool: ...
def sum(
self,
axis: AxisInt = 0,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at the source code and it had more args than in the current stubs.

min_count: int = 0,
skipna: bool = True,
*args: Any,
**kwargs: Any,
) -> Scalar: ...
def cumsum(self, axis: AxisInt = 0, *args: Any, **kwargs: Any) -> Self: ...
def mean(self, axis: AxisInt = 0, *args: Any, **kwargs: Any) -> Self: ...
@property
def T(self): ...
def __abs__(self): ...
def T(self) -> Self: ...
def __abs__(self) -> Self: ...
2 changes: 2 additions & 0 deletions pandas-stubs/core/dtypes/dtypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ class IntervalDtype(PandasExtensionDtype):
else:
@property
def subtype(self) -> np.dtype[Any] | None: ...

class SparseDtype(ExtensionDtype): ...
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,6 @@ ignore = [
# TODO: remove when window is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
]
"*arrays/sparse/*" = [
# TODO: remove when array is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
]
"*arrays/boolean.pyi" = [
# TODO: remove when boolean array is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
]
"*arrays/categorical.pyi" = [
# TODO: remove when categorical array is fully typed
"ANN001", "ANN201", "ANN204", "ANN206",
Expand Down