Skip to content

Commit 4a101db

Browse files
authored
TYP: np.dtype[Any] for py310 (#1553)
np.dtype for py310
1 parent b753e72 commit 4a101db

File tree

12 files changed

+115
-31
lines changed

12 files changed

+115
-31
lines changed

pandas-stubs/core/arrays/base.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import (
22
Iterator,
33
Sequence,
44
)
5+
import sys
56
from typing import (
67
Any,
78
Literal,
@@ -55,8 +56,13 @@ class ExtensionArray:
5556
def ndim(self) -> int: ...
5657
@property
5758
def nbytes(self) -> int: ...
58-
@overload
59-
def astype(self, dtype: np.dtype, copy: bool = True) -> np_1darray: ...
59+
if sys.version_info >= (3, 11):
60+
@overload
61+
def astype(self, dtype: np.dtype, copy: bool = True) -> np_1darray: ...
62+
else:
63+
@overload
64+
def astype(self, dtype: np.dtype[Any], copy: bool = True) -> np_1darray: ...
65+
6066
@overload
6167
def astype(self, dtype: ExtensionDtype, copy: bool = True) -> ExtensionArray: ...
6268
@overload

pandas-stubs/core/arrays/datetimes.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from datetime import tzinfo as _tzinfo
2+
import sys
3+
from typing import Any
24

35
import numpy as np
46
from pandas.core.arrays.datetimelike import (
@@ -19,8 +21,13 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
1921
__array_priority__: int = ...
2022
def __init__(self, values, dtype=..., freq=..., copy: bool = ...) -> None: ...
2123
# ignore in dtype() is from the pandas source
22-
@property
23-
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
24+
if sys.version_info >= (3, 11):
25+
@property
26+
def dtype(self) -> np.dtype | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
27+
else:
28+
@property
29+
def dtype(self) -> np.dtype[Any] | DatetimeTZDtype: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
30+
2431
@property
2532
def tz(self): ...
2633
@tz.setter

pandas-stubs/core/arrays/numpy_.pyi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
from typing import Any
3+
14
import numpy as np
25
from numpy.lib.mixins import NDArrayOperatorsMixin
36
from pandas.core.arrays.base import (
@@ -8,8 +11,13 @@ from pandas.core.arrays.base import (
811
from pandas.core.dtypes.dtypes import ExtensionDtype
912

1013
class PandasDtype(ExtensionDtype):
11-
@property
12-
def numpy_dtype(self) -> np.dtype: ...
14+
if sys.version_info >= (3, 11):
15+
@property
16+
def numpy_dtype(self) -> np.dtype: ...
17+
else:
18+
@property
19+
def numpy_dtype(self) -> np.dtype[Any]: ...
20+
1321
@property
1422
def itemsize(self) -> int: ...
1523

pandas-stubs/core/computation/ops.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from typing import Any
23

34
import numpy as np
@@ -75,8 +76,12 @@ class UnaryOp(Op):
7576
func = ...
7677
def __init__(self, op: str, operand) -> None: ...
7778
def __call__(self, env): ...
78-
@property
79-
def return_type(self) -> np.dtype: ...
79+
if sys.version_info >= (3, 11):
80+
@property
81+
def return_type(self) -> np.dtype: ...
82+
else:
83+
@property
84+
def return_type(self) -> np.dtype[Any]: ...
8085

8186
class MathCall(Op):
8287
func = ...

pandas-stubs/core/construction.pyi

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from collections.abc import Sequence
2-
from typing import overload
2+
import sys
3+
from typing import (
4+
Any,
5+
overload,
6+
)
37

48
import numpy as np
59
from pandas.core.arrays.base import ExtensionArray
@@ -40,9 +44,19 @@ def array(
4044
dtype: PandasFloatDtypeArg | None = None,
4145
copy: bool = True,
4246
) -> FloatingArray: ...
43-
@overload
44-
def array(
45-
data: Sequence[object],
46-
dtype: str | np.dtype | ExtensionDtype | None = None,
47-
copy: bool = True,
48-
) -> ExtensionArray: ...
47+
48+
if sys.version_info >= (3, 11):
49+
@overload
50+
def array(
51+
data: Sequence[object],
52+
dtype: str | np.dtype | ExtensionDtype | None = None,
53+
copy: bool = True,
54+
) -> ExtensionArray: ...
55+
56+
else:
57+
@overload
58+
def array(
59+
data: Sequence[object],
60+
dtype: str | np.dtype[Any] | ExtensionDtype | None = None,
61+
copy: bool = True,
62+
) -> ExtensionArray: ...

pandas-stubs/core/dtypes/dtypes.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime as dt
2+
import sys
23
from typing import (
34
Any,
45
Literal,
@@ -59,5 +60,9 @@ class PeriodDtype(PandasExtensionDtype):
5960

6061
class IntervalDtype(PandasExtensionDtype):
6162
def __init__(self, subtype: str | npt.DTypeLike | None = ...) -> None: ...
62-
@property
63-
def subtype(self) -> np.dtype | None: ...
63+
if sys.version_info >= (3, 11):
64+
@property
65+
def subtype(self) -> np.dtype | None: ...
66+
else:
67+
@property
68+
def subtype(self) -> np.dtype[Any] | None: ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from datetime import (
1010
timedelta,
1111
)
1212
from pathlib import Path
13+
import sys
1314
from typing import (
1415
Any,
1516
ClassVar,
@@ -371,9 +372,15 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
371372
@final
372373
def is_(self, other: Any) -> bool: ...
373374
def __len__(self) -> int: ...
374-
def __array__(
375-
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
376-
) -> np_1darray: ...
375+
if sys.version_info >= (3, 11):
376+
def __array__(
377+
self, dtype: _str | np.dtype = ..., copy: bool | None = ...
378+
) -> np_1darray: ...
379+
else:
380+
def __array__(
381+
self, dtype: _str | np.dtype[Any] = ..., copy: bool | None = ...
382+
) -> np_1darray: ...
383+
377384
@property
378385
def dtype(self) -> DtypeObj: ...
379386
@final

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ from datetime import (
88
timedelta,
99
tzinfo as _tzinfo,
1010
)
11+
import sys
1112
from typing import (
13+
Any,
1214
final,
1315
overload,
1416
)
@@ -103,8 +105,13 @@ class DatetimeIndex(
103105
def isocalendar(self) -> DataFrame: ...
104106
@property
105107
def tzinfo(self) -> _tzinfo | None: ...
106-
@property
107-
def dtype(self) -> np.dtype | DatetimeTZDtype: ...
108+
if sys.version_info >= (3, 11):
109+
@property
110+
def dtype(self) -> np.dtype | DatetimeTZDtype: ...
111+
else:
112+
@property
113+
def dtype(self) -> np.dtype[Any] | DatetimeTZDtype: ...
114+
108115
def shift(
109116
self, periods: int = 1, freq: Frequency | timedelta | None = None
110117
) -> Self: ...

pandas-stubs/core/indexes/multi.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from collections.abc import (
55
Mapping,
66
Sequence,
77
)
8+
import sys
89
from typing import (
910
Any,
1011
overload,
@@ -116,8 +117,13 @@ class MultiIndex(Index):
116117
self, names: SequenceNotStr[Hashable] = ..., deep: bool = False
117118
) -> Self: ...
118119
def view(self, cls: NumpyNotTimeDtypeArg | NumpyTimedeltaDtypeArg | NumpyTimestampDtypeArg | type[np_ndarray] | None = None) -> MultiIndex: ... # type: ignore[override] # pyrefly: ignore[bad-override] # pyright: ignore[reportIncompatibleMethodOverride]
119-
@property
120-
def dtype(self) -> np.dtype: ...
120+
if sys.version_info >= (3, 11):
121+
@property
122+
def dtype(self) -> np.dtype: ...
123+
else:
124+
@property
125+
def dtype(self) -> np.dtype[Any]: ...
126+
121127
@property
122128
def dtypes(self) -> pd.Series[Dtype]: ...
123129
def memory_usage(self, deep: bool = False) -> int: ...

pandas-stubs/core/indexes/range.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections.abc import (
22
Hashable,
33
Sequence,
44
)
5+
import sys
56
from typing import (
67
Any,
78
overload,
@@ -50,8 +51,13 @@ class RangeIndex(_IndexSubclassBase[int, np.int64]):
5051
@property
5152
def nbytes(self) -> int: ...
5253
def memory_usage(self, deep: bool = ...) -> int: ...
53-
@property
54-
def dtype(self) -> np.dtype: ...
54+
if sys.version_info >= (3, 11):
55+
@property
56+
def dtype(self) -> np.dtype: ...
57+
else:
58+
@property
59+
def dtype(self) -> np.dtype[Any]: ...
60+
5561
@property
5662
def is_unique(self) -> bool: ...
5763
@property

0 commit comments

Comments
 (0)