Skip to content

Commit 0e5ff0f

Browse files
committed
enable reportMissingTypeArgument
1 parent d54943e commit 0e5ff0f

39 files changed

+376
-202
lines changed

pandas-stubs/_libs/interval.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ VALID_CLOSED: frozenset[str]
2525

2626
_OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float)
2727
_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta)
28-
_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta)
28+
_OrderableT = TypeVar(
29+
"_OrderableT", bound=int | float | Timestamp | Timedelta, default=Any
30+
)
2931

3032
@type_check_only
3133
class _LengthDescriptor:

pandas-stubs/_typing.pyi

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ from pandas.tseries.offsets import (
7676
P = ParamSpec("P")
7777

7878
HashableT = TypeVar("HashableT", bound=Hashable)
79+
HashableT0 = TypeVar("HashableT0", bound=Hashable, default=Any)
7980
HashableT1 = TypeVar("HashableT1", bound=Hashable)
8081
HashableT2 = TypeVar("HashableT2", bound=Hashable)
8182
HashableT3 = TypeVar("HashableT3", bound=Hashable)
@@ -774,7 +775,7 @@ XMLParsers: TypeAlias = Literal["lxml", "etree"]
774775
HTMLFlavors: TypeAlias = Literal["lxml", "html5lib", "bs4"]
775776

776777
# Interval closed type
777-
IntervalT = TypeVar("IntervalT", bound=Interval)
778+
IntervalT = TypeVar("IntervalT", bound=Interval, default=Interval)
778779
IntervalLeftRight: TypeAlias = Literal["left", "right"]
779780
IntervalClosedType: TypeAlias = IntervalLeftRight | Literal["both", "neither"]
780781

@@ -872,7 +873,11 @@ ExcelWriterMergeCells: TypeAlias = bool | Literal["columns"]
872873

873874
# read_csv: usecols
874875
UsecolsArgType: TypeAlias = (
875-
SequenceNotStr[Hashable] | range | AnyArrayLike | Callable[[HashableT], bool] | None
876+
SequenceNotStr[Hashable]
877+
| range
878+
| AnyArrayLike
879+
| Callable[[HashableT0], bool]
880+
| None
876881
)
877882

878883
# maintain the sub-type of any hashable sequence
@@ -918,6 +923,7 @@ PyArrowNotStrDtypeArg: TypeAlias = (
918923
StrLike: TypeAlias = str | np.str_
919924

920925
ScalarT = TypeVar("ScalarT", bound=Scalar)
926+
ScalarT0 = TypeVar("ScalarT0", bound=Scalar, default=Scalar)
921927
# Refine the definitions below in 3.9 to use the specialized type.
922928
np_num: TypeAlias = np.bool | np.integer | np.floating | np.complexfloating
923929
np_ndarray_intp: TypeAlias = npt.NDArray[np.intp]
@@ -959,7 +965,10 @@ np_1darray_dt: TypeAlias = np_1darray[np.datetime64]
959965
np_1darray_td: TypeAlias = np_1darray[np.timedelta64]
960966
np_2darray: TypeAlias = np.ndarray[tuple[int, int], np.dtype[GenericT]]
961967

962-
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
968+
if sys.version_info >= (3, 11):
969+
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray)
970+
else:
971+
NDArrayT = TypeVar("NDArrayT", bound=np.ndarray[Any, Any])
963972

964973
DtypeNp = TypeVar("DtypeNp", bound=np.dtype[np.generic])
965974
KeysArgType: TypeAlias = Any
@@ -969,7 +978,7 @@ ListLikeExceptSeriesAndStr: TypeAlias = (
969978
)
970979
ListLikeU: TypeAlias = Sequence[Any] | np_1darray | Series | Index
971980
ListLikeHashable: TypeAlias = (
972-
MutableSequence[HashableT] | np_1darray | tuple[HashableT, ...] | range
981+
MutableSequence[HashableT0] | np_1darray | tuple[HashableT0, ...] | range
973982
)
974983

975984
class SupportsDType(Protocol[GenericT_co]):
@@ -1010,8 +1019,9 @@ SeriesDType: TypeAlias = (
10101019
| datetime.datetime # includes pd.Timestamp
10111020
| datetime.timedelta # includes pd.Timedelta
10121021
)
1022+
S0 = TypeVar("S0", bound=SeriesDType, default=Any)
10131023
S1 = TypeVar("S1", bound=SeriesDType, default=Any)
1014-
# Like S1, but without `default=Any`.
1024+
# Like S0 and S1, but without `default=Any`.
10151025
S2 = TypeVar("S2", bound=SeriesDType)
10161026
S2_contra = TypeVar("S2_contra", bound=SeriesDType, contravariant=True)
10171027
S2_NDT_contra = TypeVar(
@@ -1045,14 +1055,14 @@ IndexingInt: TypeAlias = (
10451055
)
10461056

10471057
# AxesData is used for data for Index
1048-
AxesData: TypeAlias = Mapping[S3, Any] | Axes | KeysView[S3]
1058+
AxesData: TypeAlias = Mapping[S0, Any] | Axes | KeysView[S0]
10491059

10501060
# Any plain Python or numpy function
10511061
Function: TypeAlias = np.ufunc | Callable[..., Any]
10521062
# Use a distinct HashableT in shared types to avoid conflicts with
10531063
# shared HashableT and HashableT#. This one can be used if the identical
10541064
# type is need in a function that uses GroupByObjectNonScalar
1055-
_HashableTa = TypeVar("_HashableTa", bound=Hashable)
1065+
_HashableTa = TypeVar("_HashableTa", bound=Hashable, default=Any)
10561066
if TYPE_CHECKING: # noqa: PYI002
10571067
ByT = TypeVar(
10581068
"ByT",
@@ -1070,7 +1080,7 @@ if TYPE_CHECKING: # noqa: PYI002
10701080
| Scalar
10711081
| Period
10721082
| Interval[int | float | Timestamp | Timedelta]
1073-
| tuple,
1083+
| tuple[Any, ...],
10741084
)
10751085
# Use a distinct SeriesByT when using groupby with Series of known dtype.
10761086
# Essentially, an intersection between Series S1 TypeVar, and ByT TypeVar
@@ -1088,21 +1098,23 @@ if TYPE_CHECKING: # noqa: PYI002
10881098
| Period
10891099
| Interval[int | float | Timestamp | Timedelta],
10901100
)
1091-
GroupByObjectNonScalar: TypeAlias = (
1092-
tuple[_HashableTa, ...]
1093-
| list[_HashableTa]
1094-
| Function
1095-
| list[Function]
1096-
| list[Series]
1097-
| np_ndarray
1098-
| list[np_ndarray]
1099-
| Mapping[Label, Any]
1100-
| list[Mapping[Label, Any]]
1101-
| list[Index]
1102-
| Grouper
1103-
| list[Grouper]
1104-
)
1105-
GroupByObject: TypeAlias = Scalar | Index | GroupByObjectNonScalar | Series
1101+
GroupByObjectNonScalar: TypeAlias = (
1102+
tuple[_HashableTa, ...]
1103+
| list[_HashableTa]
1104+
| Function
1105+
| list[Function]
1106+
| list[Series]
1107+
| np_ndarray
1108+
| list[np_ndarray]
1109+
| Mapping[Label, Any]
1110+
| list[Mapping[Label, Any]]
1111+
| list[Index]
1112+
| Grouper
1113+
| list[Grouper]
1114+
)
1115+
GroupByObject: TypeAlias = (
1116+
Scalar | Index | GroupByObjectNonScalar[_HashableTa] | Series
1117+
)
11061118

11071119
StataDateFormat: TypeAlias = Literal[
11081120
"tc",
@@ -1125,10 +1137,10 @@ StataDateFormat: TypeAlias = Literal[
11251137
# `DataFrame.replace` also accepts mappings of these.
11261138
ReplaceValue: TypeAlias = (
11271139
Scalar
1128-
| Pattern
1140+
| Pattern[Any]
11291141
| NAType
1130-
| Sequence[Scalar | Pattern]
1131-
| Mapping[HashableT, ScalarT]
1142+
| Sequence[Scalar | Pattern[Any]]
1143+
| Mapping[HashableT0, ScalarT0]
11321144
| Series
11331145
| None
11341146
)

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: ...

0 commit comments

Comments
 (0)