Skip to content

Commit 67248e0

Browse files
committed
ENH: More array improvements
1 parent ff02650 commit 67248e0

File tree

4 files changed

+107
-10
lines changed

4 files changed

+107
-10
lines changed

pandas-stubs/core/arrays/boolean.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ class BooleanArray(BaseMaskedArray):
4848
def __setitem__(
4949
self,
5050
key: _ArrayKey,
51-
value: _ScalarType | Sequence[bool | NAType | None] | npt.NDArray[np.bool_],
51+
value: _ScalarType
52+
| Sequence[bool | NAType | None]
53+
| npt.NDArray[np.bool_]
54+
| BooleanArray,
5255
) -> None: ...
5356
@overload # type: ignore[override]
5457
def __getitem__(self, item: int) -> bool | NAType: ...

pandas-stubs/core/arrays/string_.pyi

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
from typing import (
2+
Sequence,
3+
Union,
4+
overload,
5+
)
6+
17
import numpy as np
28
import pandas as pd
3-
from pandas.core.arrays import PandasArray
9+
from pandas.core.arrays import (
10+
ExtensionArray,
11+
PandasArray,
12+
)
13+
from typing_extensions import TypeAlias
414

15+
from pandas._libs.missing import NAType
516
from pandas._typing import (
617
npt,
718
type_t,
@@ -18,6 +29,9 @@ class StringDtype(ExtensionDtype):
1829
def construct_array_type(cls) -> type_t[StringArray]: ...
1930
def __from_arrow__(self, array): ...
2031

32+
_ScalarType: TypeAlias = Union[str, NAType, None]
33+
_ArrayKey: TypeAlias = Union[Sequence[int], npt.NDArray[np.integer], slice]
34+
2135
class StringArray(PandasArray):
2236
def __init__(
2337
self,
@@ -26,8 +40,34 @@ class StringArray(PandasArray):
2640
| npt.NDArray[np.object_],
2741
copy: bool = ...,
2842
) -> None: ...
43+
@property
44+
def na_value(self) -> NAType: ...
2945
def __arrow_array__(self, type=...): ...
30-
def __setitem__(self, key, value) -> None: ...
31-
def fillna(self, value=..., method=..., limit=...): ...
32-
def astype(self, dtype, copy: bool = ...): ...
33-
def value_counts(self, dropna: bool = ...): ...
46+
@overload # type: ignore[override]
47+
def __setitem__(self, key: int, value: _ScalarType) -> None: ...
48+
@overload
49+
def __setitem__(
50+
self,
51+
key: _ArrayKey,
52+
value: _ScalarType
53+
| Sequence[str | NAType | None]
54+
| npt.NDArray[np.str_]
55+
| npt.NDArray[np.string_]
56+
| StringArray,
57+
) -> None: ...
58+
@overload # type: ignore[override]
59+
def __getitem__(self, item: int) -> str | NAType: ...
60+
@overload
61+
def __getitem__(self, item: _ArrayKey) -> StringArray: ...
62+
@overload
63+
def astype(self, dtype: npt.DTypeLike, copy: bool = ...) -> np.ndarray: ...
64+
@overload
65+
def astype(self, dtype: ExtensionDtype, copy: bool = ...) -> ExtensionArray: ...
66+
def min(
67+
self, axis: int | None = ..., skipna: bool = ..., **kwargs
68+
) -> str | NAType: ...
69+
def max(
70+
self, axis: int | None = ..., skipna: bool = ..., **kwargs
71+
) -> str | NAType: ...
72+
def value_counts(self, dropna: bool = ...) -> pd.Series[int]: ...
73+
def memory_usage(self, deep: bool = ...) -> int: ...

pandas-stubs/core/arrays/timedeltas.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,3 @@ class TimedeltaArray(DatetimeLikeArrayMixin, TimelikeOps):
6363
nanoseconds: int = ...
6464
@property
6565
def components(self) -> int: ...
66-
67-
def sequence_to_td64ns(data, copy: bool = ..., unit: str = ..., errors: str = ...): ...
68-
def ints_to_td64ns(data, unit: str = ...): ...
69-
def objects_to_td64ns(data, unit: str = ..., errors: str = ...): ...

tests/test_arrays.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,64 @@ def test_timedelta_array() -> None:
499499
check(assert_type(pd.array(tdi), Type[ExtensionArray]), TimedeltaArray)
500500
check(assert_type(pd.array(tds, copy=False), Type[ExtensionArray]), TimedeltaArray)
501501

502+
# check(assert_type(tda.microseconds,npt.NDArray[np.int_]), np.ndarray)
503+
# check(assert_type(tda.nanoseconds,npt.NDArray[np.int_]), np.ndarray)
504+
# check(assert_type(tda.days,npt.NDArray[np.int_]), np.ndarray)
505+
# check(assert_type(tda.seconds,npt.NDArray[np.int_]), np.ndarray)
506+
#
507+
# all
508+
# any
509+
# check(assert_type(tda.argmax(), int), int)
510+
# check(assert_type(tda.argmin(), int), int)
511+
# check(assert_type(argsort, npt.NDArray[npt.intp]), np.ndarray)
512+
# check(assert_type(tda.asi8, npt.NDArray[npt.intp]), np.ndarray)
513+
#
514+
# astype
515+
# ceil
516+
# components
517+
# copy
518+
# delete
519+
# dropna
520+
# dtype
521+
# equals
522+
# factorize
523+
# fillna
524+
# floor
525+
# freq
526+
# freqstr
527+
# inferred_freq
528+
# insert
529+
# isin
530+
# isna
531+
# map
532+
# max
533+
# mean
534+
# median
535+
# min
536+
# nbytes
537+
# ndim
538+
# ravel
539+
# repeat
540+
# reshape
541+
# resolution
542+
# round
543+
# searchsorted
544+
# shape
545+
# shift
546+
# size
547+
# std
548+
# sum
549+
# swapaxes
550+
# take
551+
# check(assert_type(tda.to_numpy(), npt.NDArray[np.timedelta64]), np.ndarray)
552+
# check(assert_type(tda.to_pytimedelta(), npt.NDArray[np.object_]), np.ndarray)
553+
# tsa.tolist()
554+
# check(assert_type(tda.total_seconds(), npt.NDArray[np.float64]),np.ndarray)
555+
# transpose
556+
# unique
557+
# value_counts
558+
# view
559+
502560

503561
def test_sparse_array() -> None:
504562
ints = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

0 commit comments

Comments
 (0)