-
-
Notifications
You must be signed in to change notification settings - Fork 153
feat: reduce np.ndarray #1462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: reduce np.ndarray #1462
Changes from 6 commits
d0477e4
b88da43
0023b02
8c1a120
dc85974
1cfd06e
b9af83a
1adbffc
a61b439
bc18e49
e448246
688cebd
a38eb85
cedafab
ed1250e
4070c2d
d779dbe
88b32e0
b71d4cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ from typing import ( | |
| Literal, | ||
| TypeVar, | ||
| overload, | ||
| type_check_only, | ||
| ) | ||
|
|
||
| import numpy as np | ||
|
|
@@ -18,7 +19,6 @@ from pandas._typing import ( | |
| IntervalClosedType, | ||
| IntervalT, | ||
| np_1darray, | ||
| npt, | ||
| ) | ||
|
|
||
| VALID_CLOSED: frozenset[str] | ||
|
|
@@ -27,6 +27,7 @@ _OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float) | |
| _OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta) | ||
| _OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta) | ||
|
|
||
| @type_check_only | ||
| class _LengthDescriptor: | ||
| @overload | ||
| def __get__( | ||
|
|
@@ -36,18 +37,15 @@ class _LengthDescriptor: | |
| def __get__( | ||
| self, instance: Interval[_OrderableTimesT], owner: Any | ||
| ) -> Timedelta: ... | ||
| @overload | ||
| def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ... | ||
|
|
||
| @type_check_only | ||
| class _MidDescriptor: | ||
| @overload | ||
| def __get__(self, instance: Interval[_OrderableScalarT], owner: Any) -> float: ... | ||
| @overload | ||
| def __get__( | ||
| self, instance: Interval[_OrderableTimesT], owner: Any | ||
| ) -> _OrderableTimesT: ... | ||
| @overload | ||
| def __get__(self, instance: IntervalTree, owner: Any) -> np.ndarray: ... | ||
|
|
||
| class IntervalMixin: | ||
| @property | ||
|
|
@@ -68,8 +66,8 @@ class Interval(IntervalMixin, Generic[_OrderableT]): | |
| def right(self: Interval[_OrderableT]) -> _OrderableT: ... | ||
| @property | ||
| def closed(self) -> IntervalClosedType: ... | ||
| mid: _MidDescriptor | ||
| length: _LengthDescriptor | ||
| mid = _MidDescriptor() | ||
| length = _LengthDescriptor() | ||
| def __init__( | ||
| self, | ||
| left: _OrderableT, | ||
|
|
@@ -223,21 +221,4 @@ class Interval(IntervalMixin, Generic[_OrderableT]): | |
| @overload | ||
| def __ne__(self, other: object) -> Literal[True]: ... | ||
|
|
||
| class IntervalTree(IntervalMixin): | ||
| def __init__( | ||
| self, | ||
| left: np.ndarray, | ||
| right: np.ndarray, | ||
| closed: IntervalClosedType = ..., | ||
| leaf_size: int = ..., | ||
| ) -> None: ... | ||
| def get_indexer(self, target) -> npt.NDArray[np.intp]: ... | ||
| def get_indexer_non_unique( | ||
| self, target | ||
| ) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ... | ||
| _na_count: int | ||
| @property | ||
| def is_overlapping(self) -> bool: ... | ||
| @property | ||
| def is_monotonic_increasing(self) -> bool: ... | ||
| def clear_mapping(self) -> None: ... | ||
| class IntervalTree(IntervalMixin): ... | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,65 +5,75 @@ from typing import ( | |
| ) | ||
|
|
||
| import numpy as np | ||
| from pandas import ( | ||
| Categorical, | ||
| CategoricalIndex, | ||
| Index, | ||
| IntervalIndex, | ||
| PeriodIndex, | ||
| Series, | ||
| ) | ||
| from numpy import typing as npt | ||
| from pandas.api.extensions import ExtensionArray | ||
| from pandas.core.arrays.categorical import Categorical | ||
| from pandas.core.indexes.base import Index | ||
| from pandas.core.indexes.category import CategoricalIndex | ||
| from pandas.core.indexes.datetimes import DatetimeIndex | ||
| from pandas.core.indexes.interval import IntervalIndex | ||
| from pandas.core.indexes.period import PeriodIndex | ||
| from pandas.core.series import Series | ||
|
|
||
| from pandas._typing import ( | ||
| T_EXTENSION_ARRAY, | ||
| AnyArrayLike, | ||
| GenericT, | ||
| IntervalT, | ||
| TakeIndexer, | ||
| np_1darray, | ||
| np_ndarray, | ||
| ) | ||
|
|
||
| # These are type: ignored because the Index types overlap due to inheritance but indices | ||
| # with extension types return the same type while standard type return ndarray | ||
|
|
||
| @overload | ||
| def unique( # pyright: ignore[reportOverlappingOverload] | ||
| values: PeriodIndex, | ||
| ) -> PeriodIndex: ... | ||
| @overload | ||
| def unique(values: CategoricalIndex) -> CategoricalIndex: ... # type: ignore[overload-overlap] | ||
| def unique(values: CategoricalIndex) -> CategoricalIndex: ... | ||
| @overload | ||
| def unique(values: IntervalIndex[IntervalT]) -> IntervalIndex[IntervalT]: ... | ||
| @overload | ||
| def unique(values: Index) -> np.ndarray: ... | ||
| def unique(values: PeriodIndex) -> PeriodIndex: ... | ||
| @overload | ||
| def unique(values: DatetimeIndex) -> np_1darray[np.datetime64] | DatetimeIndex: ... | ||
| @overload | ||
| def unique(values: Index) -> np_1darray[Any] | Index: ... | ||
|
||
| @overload | ||
| def unique(values: Categorical) -> Categorical: ... | ||
|
|
||
| # @overload | ||
| # def unique(values: Series[Never]) -> np_1darray[Any] | ExtensionArray: ... | ||
| # TODO: DatetimeArray python/mypy#19952 | ||
| # @overload | ||
| # def unique(values: Series[Timestamp]) -> np_1darray[np.datetime64] | ExtensionArray: ... | ||
| # @overload | ||
| # def unique(values: Series[int]) -> np_1darray[np.integer] | ExtensionArray: ... | ||
| @overload | ||
| def unique(values: Series) -> np.ndarray | ExtensionArray: ... | ||
| def unique(values: Series) -> np_1darray[Any] | ExtensionArray: ... | ||
|
||
| @overload | ||
| def unique(values: np.ndarray) -> np.ndarray: ... | ||
| def unique(values: npt.NDArray[GenericT]) -> np_1darray[GenericT]: ... | ||
| @overload | ||
| def unique(values: ExtensionArray) -> ExtensionArray: ... | ||
| def unique(values: T_EXTENSION_ARRAY) -> T_EXTENSION_ARRAY: ... | ||
| @overload | ||
| def factorize( | ||
| values: np.ndarray, | ||
| values: npt.NDArray[GenericT], | ||
| sort: bool = ..., | ||
| use_na_sentinel: bool = ..., | ||
| size_hint: int | None = ..., | ||
| ) -> tuple[np.ndarray, np.ndarray]: ... | ||
| ) -> tuple[np_1darray[np.int64], np_1darray[GenericT]]: ... | ||
| @overload | ||
| def factorize( | ||
| values: Index | Series, | ||
| sort: bool = ..., | ||
| use_na_sentinel: bool = ..., | ||
| size_hint: int | None = ..., | ||
| ) -> tuple[np_1darray, Index]: ... | ||
| ) -> tuple[np_1darray[np.int64], Index]: ... | ||
| @overload | ||
| def factorize( | ||
| values: Categorical, | ||
| sort: bool = ..., | ||
| use_na_sentinel: bool = ..., | ||
| size_hint: int | None = ..., | ||
| ) -> tuple[np_1darray, Categorical]: ... | ||
| ) -> tuple[np_1darray[np.int64], Categorical]: ... | ||
| def value_counts( | ||
| values: AnyArrayLike | list | tuple, | ||
| sort: bool = True, | ||
|
|
@@ -73,9 +83,9 @@ def value_counts( | |
| dropna: bool = True, | ||
| ) -> Series: ... | ||
| def take( | ||
| arr: np.ndarray | ExtensionArray | Index | Series, | ||
| arr: np_ndarray[Any] | ExtensionArray | Index | Series, | ||
| indices: TakeIndexer, | ||
| axis: Literal[0, 1] = 0, | ||
| allow_fill: bool = False, | ||
| fill_value: Any = None, | ||
| ) -> np_1darray | ExtensionArray: ... | ||
| ) -> np_1darray[Any] | ExtensionArray: ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ from typing import ( | |
| overload, | ||
| ) | ||
|
|
||
| import numpy as np | ||
| from pandas.core.arrays.base import ( | ||
| ExtensionArray, | ||
| ExtensionOpsMixin, | ||
|
|
@@ -65,7 +64,7 @@ class DatetimeLikeArrayMixin(ExtensionOpsMixin, ExtensionArray): | |
| def ravel(self, *args: Any, **kwargs: Any): ... | ||
| def __iter__(self): ... | ||
| @property | ||
| def asi8(self) -> np.ndarray: ... | ||
| def asi8(self) -> np_1darray[Any]: ... | ||
|
||
| @property | ||
| def nbytes(self): ... | ||
| def __array__( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.