Skip to content

Commit ed1250e

Browse files
committed
replace npt.NDArray with np_ndarray
1 parent cedafab commit ed1250e

File tree

11 files changed

+32
-41
lines changed

11 files changed

+32
-41
lines changed

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ from pandas._typing import (
6464
TimestampConvertibleTypes,
6565
WindowingEngine,
6666
WindowingEngineKwargs,
67+
np_ndarray_int64,
6768
npt,
6869
)
6970

@@ -357,7 +358,7 @@ class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
357358
def ngroups(self) -> int: ...
358359
@final
359360
@property
360-
def indices(self) -> dict[Hashable, Index | npt.NDArray[np.int_] | list[int]]: ...
361+
def indices(self) -> dict[Hashable, Index | np_ndarray_int64 | list[int]]: ...
361362
@overload
362363
def pipe(
363364
self,

pandas-stubs/core/indexers.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from numpy import typing as npt
44

55
from pandas._typing import (
66
AnyArrayLike,
7+
np_1darray_bool,
78
)
89

910
def check_array_indexer(

pandas-stubs/core/indexes/interval.pyi

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ from pandas._typing import (
2929
np_1darray,
3030
np_ndarray_anyint,
3131
np_ndarray_bool,
32+
np_ndarray_dt,
33+
np_ndarray_int64,
34+
np_ndarray_td,
3235
npt,
3336
)
3437

3538
from pandas.core.dtypes.dtypes import IntervalDtype as IntervalDtype
3639

3740
_EdgesInt: TypeAlias = (
3841
Sequence[int]
39-
| npt.NDArray[np.int64]
42+
| np_ndarray_int64
4043
| npt.NDArray[np.int32]
4144
| npt.NDArray[np.intp]
4245
| pd.Series[int]
@@ -46,16 +49,10 @@ _EdgesFloat: TypeAlias = (
4649
Sequence[float] | npt.NDArray[np.float64] | pd.Series[float] | Index[float]
4750
)
4851
_EdgesTimestamp: TypeAlias = (
49-
Sequence[DatetimeLike]
50-
| npt.NDArray[np.datetime64]
51-
| pd.Series[pd.Timestamp]
52-
| pd.DatetimeIndex
52+
Sequence[DatetimeLike] | np_ndarray_dt | pd.Series[pd.Timestamp] | pd.DatetimeIndex
5353
)
5454
_EdgesTimedelta: TypeAlias = (
55-
Sequence[pd.Timedelta]
56-
| npt.NDArray[np.timedelta64]
57-
| pd.Series[pd.Timedelta]
58-
| pd.TimedeltaIndex
55+
Sequence[pd.Timedelta] | np_ndarray_td | pd.Series[pd.Timedelta] | pd.TimedeltaIndex
5956
)
6057
_TimestampLike: TypeAlias = pd.Timestamp | np.datetime64 | dt.datetime
6158
_TimedeltaLike: TypeAlias = pd.Timedelta | np.timedelta64 | dt.timedelta

pandas-stubs/core/strings/accessor.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ from typing import (
1515
)
1616

1717
import numpy as np
18-
import numpy.typing as npt
1918
import pandas as pd
2019
from pandas import (
2120
DataFrame,
@@ -32,6 +31,7 @@ from pandas._typing import (
3231
Scalar,
3332
T,
3433
np_1darray,
34+
np_ndarray_str,
3535
)
3636

3737
# Used for the result of str.split with expand=True
@@ -67,9 +67,7 @@ class StringMethods(
6767
@overload
6868
def cat(
6969
self,
70-
others: (
71-
Series[str] | Index[str] | pd.DataFrame | npt.NDArray[np.str_] | list[str]
72-
),
70+
others: list[str] | np_ndarray_str | Series[str] | Index[str] | pd.DataFrame,
7371
sep: str | None = None,
7472
na_rep: str | None = None,
7573
join: AlignJoin = "left",

pandas-stubs/core/tools/datetimes.pyi

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ from pandas._typing import (
2626
IgnoreRaise,
2727
RaiseCoerce,
2828
TimestampConvertibleTypes,
29-
npt,
29+
np_ndarray_dt,
30+
np_ndarray_int64,
31+
np_ndarray_str,
3032
)
3133

3234
ArrayConvertible: TypeAlias = list | tuple | AnyArrayLike
@@ -100,9 +102,9 @@ def to_datetime(
100102
Sequence[float | date]
101103
| list[str]
102104
| tuple[float | str | date, ...]
103-
| npt.NDArray[np.datetime64]
104-
| npt.NDArray[np.str_]
105-
| npt.NDArray[np.int_]
105+
| np_ndarray_dt
106+
| np_ndarray_str
107+
| np_ndarray_int64
106108
| Index
107109
| ExtensionArray
108110
),

pandas-stubs/io/formats/style.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ from typing import (
1111
)
1212

1313
from matplotlib.colors import Colormap
14-
import numpy as np
1514
from pandas.core.frame import DataFrame
1615
from pandas.core.series import Series
1716

@@ -31,6 +30,7 @@ from pandas._typing import (
3130
T,
3231
WriteBuffer,
3332
WriteExcelBuffer,
33+
np_ndarray_str,
3434
npt,
3535
)
3636

@@ -245,7 +245,7 @@ class Styler(StylerRenderer):
245245
) -> Styler: ...
246246
def apply_index(
247247
self,
248-
func: Callable[[Series], npt.NDArray[np.str_] | list[str] | Series[str]],
248+
func: Callable[[Series], list[str] | np_ndarray_str | Series[str]],
249249
axis: Axis = ...,
250250
level: Level | list[Level] | None = ...,
251251
**kwargs: Any,

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
np_ndarray_bool as np_ndarray_bool,
5454
np_ndarray_dt as np_ndarray_dt,
5555
np_ndarray_int as np_ndarray_int,
56+
np_ndarray_str as np_ndarray_str,
5657
np_ndarray_td as np_ndarray_td,
5758
)
5859
else:
@@ -69,6 +70,7 @@
6970
np_ndarray_dt: TypeAlias = npt.NDArray[np.datetime64]
7071
np_ndarray_int: TypeAlias = npt.NDArray[np.signedinteger]
7172
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
73+
np_ndarray_str: TypeAlias = npt.NDArray[np.str_]
7274
np_ndarray_td: TypeAlias = npt.NDArray[np.timedelta64]
7375

7476
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING

tests/indexes/test_indexes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
)
1111

1212
import numpy as np
13-
from numpy import typing as npt
1413
import pandas as pd
1514
from pandas.core.arrays.base import ExtensionArray
1615
from pandas.core.arrays.categorical import Categorical
@@ -30,6 +29,7 @@
3029
TYPE_CHECKING_INVALID_USAGE,
3130
check,
3231
np_1darray,
32+
np_ndarray_dt,
3333
pytest_warns_bounded,
3434
)
3535

@@ -647,7 +647,7 @@ def test_interval_index_arrays() -> None:
647647
pd.IntervalIndex,
648648
pd.Interval,
649649
)
650-
left_dt64_arr: npt.NDArray[np.datetime64] = np.array(
650+
left_dt64_arr: np_ndarray_dt = np.array(
651651
[
652652
np.datetime64("2000-01-01"),
653653
np.datetime64("2001-01-01"),
@@ -656,7 +656,7 @@ def test_interval_index_arrays() -> None:
656656
],
657657
dtype="datetime64[ns]",
658658
)
659-
right_dt_arr: npt.NDArray[np.datetime64] = np.array(
659+
right_dt_arr: np_ndarray_dt = np.array(
660660
[
661661
np.datetime64("2001-01-01"),
662662
np.datetime64("2002-01-01"),

tests/scalars/test_scalars.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,7 @@ def test_timedelta_add_sub() -> None:
534534
check(assert_type(td + as_timedelta_index, pd.TimedeltaIndex), pd.TimedeltaIndex)
535535
check(assert_type(td + as_period_index, pd.PeriodIndex), pd.PeriodIndex)
536536
check(assert_type(td + as_datetime_index, pd.DatetimeIndex), pd.DatetimeIndex)
537-
check(
538-
assert_type(td + as_ndarray_td64, np_ndarray_td), np_ndarray_td, np.timedelta64
539-
)
537+
check(assert_type(td + as_ndarray_td64, np_ndarray_td), np_ndarray, np.timedelta64)
540538
check(assert_type(td + as_ndarray_dt64, np_ndarray_dt), np_ndarray, np.datetime64)
541539
check(assert_type(td + as_nat, NaTType), NaTType)
542540

@@ -586,9 +584,7 @@ def test_timedelta_add_sub() -> None:
586584
check(assert_type(td - as_dt_timedelta, pd.Timedelta), pd.Timedelta)
587585
check(assert_type(td - as_timedelta64, pd.Timedelta), pd.Timedelta)
588586
check(assert_type(td - as_timedelta_index, pd.TimedeltaIndex), pd.TimedeltaIndex)
589-
check(
590-
assert_type(td - as_ndarray_td64, np_ndarray_td), np_ndarray_td, np.timedelta64
591-
)
587+
check(assert_type(td - as_ndarray_td64, np_ndarray_td), np_ndarray, np.timedelta64)
592588
check(assert_type(td - as_nat, NaTType), NaTType)
593589
check(assert_type(as_period - td, pd.Period), pd.Period)
594590
check(assert_type(as_timestamp - td, pd.Timestamp), pd.Timestamp)
@@ -1093,14 +1089,10 @@ def test_timestamp_add_sub() -> None:
10931089
)
10941090

10951091
check(
1096-
assert_type(ts + as_np_ndarray_td64, np_ndarray_dt),
1097-
np_ndarray_dt,
1098-
np.datetime64,
1092+
assert_type(ts + as_np_ndarray_td64, np_ndarray_dt), np_ndarray, np.datetime64
10991093
)
11001094
check(
1101-
assert_type(as_np_ndarray_td64 + ts, np_ndarray_dt),
1102-
np_ndarray_dt,
1103-
np.datetime64,
1095+
assert_type(as_np_ndarray_td64 + ts, np_ndarray_dt), np_ndarray, np.datetime64
11041096
)
11051097

11061098
# Reverse order is not possible for all of these
@@ -1114,9 +1106,7 @@ def test_timestamp_add_sub() -> None:
11141106
pd.Timestamp,
11151107
)
11161108
check(
1117-
assert_type(ts - as_np_ndarray_td64, np_ndarray_dt),
1118-
np_ndarray_dt,
1119-
np.datetime64,
1109+
assert_type(ts - as_np_ndarray_td64, np_ndarray_dt), np_ndarray, np.datetime64
11201110
)
11211111

11221112

tests/test_styler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
)
1010
from jinja2.loaders import PackageLoader
1111
import numpy as np
12-
import numpy.typing as npt
1312
from pandas import (
1413
DataFrame,
1514
Index,
@@ -24,6 +23,7 @@
2423
PD_LTE_23,
2524
check,
2625
ensure_clean,
26+
np_ndarray_str,
2727
)
2828

2929
from pandas.io.formats.style import Styler
@@ -64,7 +64,7 @@ def highlight_max(x: Series[int], /, color: str) -> list[str]:
6464

6565

6666
def test_apply_index() -> None:
67-
def f(s: Series) -> npt.NDArray[np.str_]:
67+
def f(s: Series) -> np_ndarray_str:
6868
return np.asarray(s, dtype=np.str_)
6969

7070
check(assert_type(DF.style.apply_index(f), Styler), Styler)

0 commit comments

Comments
 (0)