Skip to content

Commit 2ee3412

Browse files
committed
enable reportMissingTypeArgument
1 parent 0f17f86 commit 2ee3412

File tree

23 files changed

+183
-119
lines changed

23 files changed

+183
-119
lines changed

pandas-stubs/_libs/interval.pyi

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

2727
_OrderableScalarT = TypeVar("_OrderableScalarT", bound=int | float)
2828
_OrderableTimesT = TypeVar("_OrderableTimesT", bound=Timestamp | Timedelta)
29-
_OrderableT = TypeVar("_OrderableT", bound=int | float | Timestamp | Timedelta)
29+
_OrderableT = TypeVar(
30+
"_OrderableT", bound=int | float | Timestamp | Timedelta, default=Any
31+
)
3032

3133
@type_check_only
3234
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/frame.pyi

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ from pandas.core.indexing import (
5858
_LocIndexer,
5959
)
6060
from pandas.core.reshape.pivot import (
61-
_PivotAggFunc,
61+
_PivotAggFuncTypes,
6262
_PivotTableColumnsTypes,
6363
_PivotTableIndexTypes,
6464
_PivotTableValuesTypes,
@@ -178,7 +178,7 @@ from pandas.plotting import PlotAccessor
178178
from pandas.plotting._core import _BoxPlotT
179179

180180
_T_MUTABLE_MAPPING_co = TypeVar(
181-
"_T_MUTABLE_MAPPING_co", bound=MutableMapping, covariant=True
181+
"_T_MUTABLE_MAPPING_co", bound=MutableMapping[Any, Any], covariant=True
182182
)
183183

184184
class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
@@ -340,28 +340,23 @@ class _AtIndexerFrame(_AtIndexer):
340340
value: Scalar | NAType | NaTType | None,
341341
) -> None: ...
342342

343-
# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
344-
if sys.version_info >= (3, 12):
345-
class _GetItemHack:
346-
@overload
347-
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
343+
class _GetItemHack:
344+
@overload
345+
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
346+
# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
347+
if sys.version_info >= (3, 12):
348348
@overload
349349
def __getitem__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
350350
self, key: Iterable[Hashable] | slice
351351
) -> Self: ...
352-
@overload
353-
def __getitem__(self, key: Hashable) -> Series: ...
354-
355-
else:
356-
class _GetItemHack:
357-
@overload
358-
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
352+
else:
359353
@overload
360354
def __getitem__( # pyright: ignore[reportOverlappingOverload]
361355
self, key: Iterable[Hashable] | slice
362356
) -> Self: ...
363-
@overload
364-
def __getitem__(self, key: Hashable) -> Series: ...
357+
358+
@overload
359+
def __getitem__(self, key: Hashable) -> Series: ...
365360

366361
_AstypeArgExt: TypeAlias = (
367362
AstypeArg
@@ -562,16 +557,29 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
562557
coerce_float: bool = False,
563558
nrows: int | None = None,
564559
) -> Self: ...
565-
def to_records(
566-
self,
567-
index: _bool = True,
568-
column_dtypes: (
569-
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
570-
) = None,
571-
index_dtypes: (
572-
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
573-
) = None,
574-
) -> np.recarray: ...
560+
if sys.version_info >= (3, 11):
561+
def to_records(
562+
self,
563+
index: _bool = True,
564+
column_dtypes: (
565+
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
566+
) = None,
567+
index_dtypes: (
568+
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
569+
) = None,
570+
) -> np.recarray: ...
571+
else:
572+
def to_records(
573+
self,
574+
index: _bool = True,
575+
column_dtypes: (
576+
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
577+
) = None,
578+
index_dtypes: (
579+
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
580+
) = None,
581+
) -> np.recarray[Any, Any]: ...
582+
575583
@overload
576584
def to_stata(
577585
self,
@@ -1360,7 +1368,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13601368
dropna: _bool = ...,
13611369
) -> DataFrameGroupBy[Period, Literal[False]]: ...
13621370
@overload
1363-
def groupby( # pyright: ignore reportOverlappingOverload
1371+
def groupby(
13641372
self,
13651373
by: IntervalIndex[IntervalT],
13661374
level: IndexLabel | None = ...,
@@ -1373,7 +1381,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13731381
@overload
13741382
def groupby(
13751383
self,
1376-
by: IntervalIndex[IntervalT],
1384+
by: IntervalIndex,
13771385
level: IndexLabel | None = ...,
13781386
as_index: Literal[False] = False,
13791387
sort: _bool = ...,
@@ -1459,9 +1467,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14591467
values: _PivotTableValuesTypes = None,
14601468
index: _PivotTableIndexTypes = None,
14611469
columns: _PivotTableColumnsTypes = None,
1462-
aggfunc: (
1463-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
1464-
) = "mean",
1470+
aggfunc: _PivotAggFuncTypes[Scalar] = "mean",
14651471
fill_value: Scalar | None = None,
14661472
margins: _bool = False,
14671473
dropna: _bool = True,
@@ -2842,8 +2848,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
28422848
def __rfloordiv__(
28432849
self, other: float | DataFrame | Series[int] | Series[float] | Sequence[float]
28442850
) -> Self: ...
2845-
def __truediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
2846-
def __rtruediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
2851+
def __truediv__(
2852+
self, other: float | DataFrame | Series | Sequence[Any]
2853+
) -> Self: ...
2854+
def __rtruediv__(
2855+
self, other: float | DataFrame | Series | Sequence[Any]
2856+
) -> Self: ...
28472857
@final
28482858
def __bool__(self) -> NoReturn: ...
28492859

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from datetime import (
55
tzinfo as _tzinfo,
66
)
77
from typing import (
8+
Any,
89
Generic,
910
Literal,
1011
TypeVar,
@@ -377,7 +378,7 @@ class PeriodProperties(
377378
Series[Timestamp], Series[int], Series[str], DatetimeArray, PeriodArray
378379
],
379380
_DatetimeFieldOps[Series[int]],
380-
_IsLeapYearProperty,
381+
_IsLeapYearProperty[_DTBoolOpsReturnType],
381382
_FreqProperty[BaseOffset],
382383
): ...
383384
class CombinedDatetimelikeProperties(
@@ -393,7 +394,9 @@ class CombinedDatetimelikeProperties(
393394
Series[Period],
394395
],
395396
_TimedeltaPropertiesNoRounding[Series[int], Series[float]],
396-
_PeriodProperties,
397+
_PeriodProperties[
398+
Series[Timestamp], Series[int], Series[str], DatetimeArray, PeriodArray
399+
],
397400
): ...
398401

399402
@type_check_only
@@ -458,7 +461,7 @@ class DtDescriptor:
458461
@overload
459462
def __get__(
460463
self, instance: Series[Period], owner: type[Series]
461-
) -> PeriodProperties: ...
464+
) -> PeriodProperties[Any]: ...
462465

463466
@type_check_only
464467
class ArrayDescriptor:

pandas-stubs/core/indexes/interval.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ class IntervalIndex(ExtensionIndex[IntervalT, np.object_], IntervalMixin):
243243
def __contains__(self, key: IntervalT) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
244244
@overload
245245
def __contains__(self, key: object) -> Literal[False]: ...
246-
def astype(self, dtype: DtypeArg, copy: bool = True) -> IntervalIndex: ...
246+
def astype( # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
247+
self, dtype: DtypeArg, copy: bool = True
248+
) -> IntervalIndex: ...
247249
@property
248250
def inferred_type(self) -> str: ...
249251
def memory_usage(self, deep: bool = False) -> int: ...

pandas-stubs/core/indexes/period.pyi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections.abc import Hashable
22
import datetime
33
from typing import (
4-
Any,
54
overload,
65
)
76

@@ -30,7 +29,7 @@ from pandas._typing import (
3029
class PeriodIndex(DatetimeIndexOpsMixin[pd.Period, np.object_], PeriodIndexFieldOps):
3130
def __new__(
3231
cls,
33-
data: AxesData[Any] | None = None,
32+
data: AxesData | None = None,
3433
freq: Frequency | None = None,
3534
dtype: Dtype | None = None,
3635
copy: bool = False,

pandas-stubs/core/reshape/pivot.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ _PivotTableColumnsTypes: TypeAlias = (
6161
_PivotTableValuesTypes: TypeAlias = Label | Sequence[Hashable] | None
6262

6363
_ExtendedAnyArrayLike: TypeAlias = AnyArrayLike | ArrayLike
64-
_Values: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike
64+
_CrossTabValues: TypeAlias = SequenceNotStr[Any] | _ExtendedAnyArrayLike
6565

6666
@overload
6767
def pivot_table(
@@ -118,9 +118,9 @@ def pivot(
118118
) -> DataFrame: ...
119119
@overload
120120
def crosstab(
121-
index: _Values | list[_Values],
122-
columns: _Values | list[_Values],
123-
values: _Values,
121+
index: _CrossTabValues | list[_CrossTabValues],
122+
columns: _CrossTabValues | list[_CrossTabValues],
123+
values: _CrossTabValues,
124124
rownames: SequenceNotStr[Hashable] | None = None,
125125
colnames: SequenceNotStr[Hashable] | None = None,
126126
*,
@@ -132,8 +132,8 @@ def crosstab(
132132
) -> DataFrame: ...
133133
@overload
134134
def crosstab(
135-
index: _Values | list[_Values],
136-
columns: _Values | list[_Values],
135+
index: _CrossTabValues | list[_CrossTabValues],
136+
columns: _CrossTabValues | list[_CrossTabValues],
137137
values: None = None,
138138
rownames: SequenceNotStr[Hashable] | None = None,
139139
colnames: SequenceNotStr[Hashable] | None = None,

0 commit comments

Comments
 (0)