Skip to content

Commit a38eb85

Browse files
committed
reduce np.double
1 parent 688cebd commit a38eb85

File tree

6 files changed

+38
-29
lines changed

6 files changed

+38
-29
lines changed

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ np_ndarray: TypeAlias = np.ndarray[ShapeT, np.dtype[GenericT]]
859859
# Numpy arrays with known shape (Do not use as argument types, only as return types)
860860
np_1darray: TypeAlias = np.ndarray[tuple[int], np.dtype[GenericT]]
861861
np_1darray_int64: TypeAlias = np_1darray[np.int64]
862+
np_1darray_float: TypeAlias = np_1darray[np.floating]
862863

863864
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[GenericT]]
864865

pandas-stubs/core/resample.pyi

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

1414
import numpy as np
15-
from numpy import typing as npt
1615
from pandas.core.frame import DataFrame
1716
from pandas.core.groupby.generic import SeriesGroupBy
1817
from pandas.core.groupby.groupby import BaseGroupBy
@@ -29,6 +28,7 @@ from pandas._typing import (
2928
Scalar,
3029
TimeGrouperOrigin,
3130
TimestampConvention,
31+
np_ndarray_float,
3232
)
3333

3434
_FrameGroupByFunc: TypeAlias = (
@@ -165,7 +165,7 @@ class Resampler(BaseGroupBy[NDFrameT]):
165165
@final
166166
def quantile(
167167
self,
168-
q: float | list[float] | npt.NDArray[np.double] | Series[float] = 0.5,
168+
q: float | list[float] | np_ndarray_float | Series[float] = 0.5,
169169
**kwargs: Any,
170170
) -> NDFrameT: ...
171171

pandas-stubs/core/reshape/tile.pyi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from typing import (
66
)
77

88
import numpy as np
9+
from numpy import typing as npt
910
from pandas import (
1011
Categorical,
1112
CategoricalDtype,
@@ -21,9 +22,9 @@ from pandas._typing import (
2122
IntervalT,
2223
Label,
2324
np_1darray,
25+
np_1darray_float,
2426
np_ndarray_anyint,
2527
np_ndarray_float,
26-
npt,
2728
)
2829

2930
@overload
@@ -38,7 +39,7 @@ def cut(
3839
include_lowest: bool = ...,
3940
duplicates: Literal["raise", "drop"] = ...,
4041
ordered: bool = ...,
41-
) -> tuple[np_1darray[np.intp], np_1darray[np.double]]: ...
42+
) -> tuple[np_1darray[np.intp], np_1darray_float]: ...
4243
@overload
4344
def cut(
4445
x: Index | npt.NDArray[Any] | Sequence[int] | Sequence[float],
@@ -96,7 +97,7 @@ def cut(
9697
include_lowest: bool = ...,
9798
duplicates: Literal["raise", "drop"] = ...,
9899
ordered: bool = ...,
99-
) -> tuple[Series, np_1darray[np.double]]: ...
100+
) -> tuple[Series, np_1darray_float]: ...
100101
@overload
101102
def cut(
102103
x: Series,
@@ -122,7 +123,7 @@ def cut(
122123
include_lowest: bool = ...,
123124
duplicates: Literal["raise", "drop"] = ...,
124125
ordered: bool = ...,
125-
) -> tuple[Categorical, np_1darray[np.double]]: ...
126+
) -> tuple[Categorical, np_1darray_float]: ...
126127
@overload
127128
def cut(
128129
x: Index | npt.NDArray[Any] | Sequence[int] | Sequence[float],
@@ -258,7 +259,7 @@ def qcut(
258259
precision: int = 3,
259260
duplicates: Literal["raise", "drop"] = "raise",
260261
# double when there are nan's
261-
) -> tuple[np_1darray[np.intp | np.double], np_1darray[np.double]]: ...
262+
) -> tuple[np_1darray[np.intp | np.double], np_1darray_float]: ...
262263
@overload
263264
def qcut(
264265
x: Series[int] | Series[float],
@@ -268,7 +269,7 @@ def qcut(
268269
retbins: Literal[True],
269270
precision: int = 3,
270271
duplicates: Literal["raise", "drop"] = "raise",
271-
) -> tuple[Series, np_1darray[np.double]]: ...
272+
) -> tuple[Series, np_1darray_float]: ...
272273
@overload
273274
def qcut(
274275
x: (
@@ -284,4 +285,4 @@ def qcut(
284285
retbins: Literal[True],
285286
precision: int = 3,
286287
duplicates: Literal["raise", "drop"] = "raise",
287-
) -> tuple[Categorical, np_1darray[np.double]]: ...
288+
) -> tuple[Categorical, np_1darray_float]: ...

pandas-stubs/plotting/_core.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ from pandas._typing import (
2727
HashableT1,
2828
HashableT2,
2929
HashableT3,
30+
np_ndarray_float,
3031
npt,
3132
)
3233

@@ -340,7 +341,7 @@ class PlotAccessor:
340341
| Callable[[gaussian_kde], float]
341342
| None
342343
) = ...,
343-
ind: npt.NDArray[np.double] | int | None = ...,
344+
ind: np_ndarray_float | int | None = ...,
344345
*,
345346
subplots: Literal[False] | None = ...,
346347
**kwargs: Any,
@@ -354,7 +355,7 @@ class PlotAccessor:
354355
| Callable[[gaussian_kde], float]
355356
| None
356357
) = ...,
357-
ind: npt.NDArray[np.double] | int | None = ...,
358+
ind: np_ndarray_float | int | None = ...,
358359
*,
359360
subplots: Literal[True],
360361
**kwargs: Any,

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
UIntDtypeArg as UIntDtypeArg,
4646
VoidDtypeArg as VoidDtypeArg,
4747
np_1darray as np_1darray,
48+
np_1darray_float as np_1darray_float,
4849
np_1darray_int64 as np_1darray_int64,
4950
np_2darray as np_2darray,
5051
np_ndarray as np_ndarray,
@@ -57,6 +58,7 @@
5758
# Separately define here so pytest works
5859
np_1darray: TypeAlias = np.ndarray[tuple[int], np.dtype[_G]]
5960
np_1darray_int64: TypeAlias = np_1darray[np.int64]
61+
np_1darray_float: TypeAlias = np_1darray[np.floating]
6062
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_G]]
6163
np_ndarray: TypeAlias = np.ndarray[_S, np.dtype[_G]]
6264
np_ndarray_bool: TypeAlias = npt.NDArray[np.bool_]

tests/test_pandas.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
TYPE_CHECKING_INVALID_USAGE,
3434
check,
3535
np_1darray,
36+
np_1darray_float,
3637
np_2darray,
3738
np_ndarray_bool,
3839
pytest_warns_bounded,
@@ -1030,14 +1031,14 @@ def test_cut() -> None:
10301031
[1, 2, 3, 4, 5, 6, 7, 8], 4, labels=["1", "2", "3", "4"], retbins=True
10311032
)
10321033
check(assert_type(d0, pd.Categorical), pd.Categorical)
1033-
check(assert_type(d1, np_1darray[np.double]), np_1darray[np.double])
1034+
check(assert_type(d1, np_1darray_float), np_1darray[Any], np.floating)
10341035
check(
10351036
assert_type(e0, np_1darray[np.intp]),
10361037
np_1darray[np.intp],
10371038
)
1038-
check(assert_type(e1, np_1darray[np.double]), np_1darray[np.double])
1039+
check(assert_type(e1, np_1darray_float), np_1darray[Any], np.floating)
10391040
check(assert_type(f0, pd.Categorical), pd.Categorical)
1040-
check(assert_type(f1, np_1darray[np.double]), np_1darray[np.double])
1041+
check(assert_type(f1, np_1darray_float), np_1darray[Any], np.floating)
10411042

10421043
g = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, precision=1, duplicates="drop")
10431044
h = pd.cut(pd.Series([1, 2, 3, 4, 5, 6, 7, 8]), 4, labels=False, duplicates="raise")
@@ -1072,11 +1073,11 @@ def test_cut() -> None:
10721073
retbins=True,
10731074
)
10741075
check(assert_type(j0, pd.Series), pd.Series)
1075-
check(assert_type(j1, np_1darray[np.double]), np_1darray[np.double])
1076+
check(assert_type(j1, np_1darray_float), np_1darray[Any], np.floating)
10761077
check(assert_type(k0, pd.Series), pd.Series)
1077-
check(assert_type(k1, np_1darray[np.double]), np_1darray[np.double])
1078+
check(assert_type(k1, np_1darray_float), np_1darray[Any], np.floating)
10781079
check(assert_type(l0, pd.Series), pd.Series)
1079-
check(assert_type(l1, np_1darray[np.double]), np_1darray[np.double])
1080+
check(assert_type(l1, np_1darray_float), np_1darray[Any], np.floating)
10801081
check(assert_type(m0, pd.Series), pd.Series)
10811082
check(assert_type(m1, pd.IntervalIndex), pd.IntervalIndex)
10821083

@@ -1149,10 +1150,10 @@ def test_qcut() -> None:
11491150
check(assert_type(c0, pd.Categorical), pd.Categorical)
11501151
check(assert_type(d0, pd.Series), pd.Series)
11511152

1152-
check(assert_type(a1, np_1darray[np.double]), np_1darray[np.double])
1153-
check(assert_type(b1, np_1darray[np.double]), np_1darray[np.double])
1154-
check(assert_type(c1, np_1darray[np.double]), np_1darray[np.double])
1155-
check(assert_type(d1, np_1darray[np.double]), np_1darray[np.double])
1153+
check(assert_type(a1, np_1darray_float), np_1darray[Any], np.floating)
1154+
check(assert_type(b1, np_1darray_float), np_1darray[Any], np.floating)
1155+
check(assert_type(c1, np_1darray_float), np_1darray[Any], np.floating)
1156+
check(assert_type(d1, np_1darray_float), np_1darray[Any], np.floating)
11561157

11571158
e0, e1 = pd.qcut(val_list, [0.25, 0.5, 0.75], retbins=True)
11581159
f0, f1 = pd.qcut(val_arr, np.array([0.25, 0.5, 0.75]), retbins=True)
@@ -1170,16 +1171,19 @@ def test_qcut() -> None:
11701171
check(assert_type(h0, pd.Series), pd.Series)
11711172
check(
11721173
assert_type(i0, np_1darray[np.intp | np.double]),
1173-
np_1darray[np.double], # because of nans
1174+
np_1darray[Any], # because of nans
1175+
np.floating,
1176+
)
1177+
check(
1178+
assert_type(j0, np_1darray[np.intp | np.double]), np_1darray[Any], np.floating
11741179
)
1175-
check(assert_type(j0, np_1darray[np.intp | np.double]), np_1darray[np.double])
11761180

1177-
check(assert_type(e1, np_1darray[np.double]), np_1darray[np.double])
1178-
check(assert_type(f1, np_1darray[np.double]), np_1darray[np.double])
1179-
check(assert_type(g1, np_1darray[np.double]), np_1darray[np.double])
1180-
check(assert_type(h1, np_1darray[np.double]), np_1darray[np.double])
1181-
check(assert_type(i1, np_1darray[np.double]), np_1darray[np.double])
1182-
check(assert_type(j1, np_1darray[np.double]), np_1darray[np.double])
1181+
check(assert_type(e1, np_1darray_float), np_1darray[Any], np.floating)
1182+
check(assert_type(f1, np_1darray_float), np_1darray[Any], np.floating)
1183+
check(assert_type(g1, np_1darray_float), np_1darray[Any], np.floating)
1184+
check(assert_type(h1, np_1darray_float), np_1darray[Any], np.floating)
1185+
check(assert_type(i1, np_1darray_float), np_1darray[Any], np.floating)
1186+
check(assert_type(j1, np_1darray_float), np_1darray[Any], np.floating)
11831187

11841188

11851189
@pytest.mark.xfail(

0 commit comments

Comments
 (0)