Skip to content

Commit 23b82e2

Browse files
committed
enable reportMissingTypeArgument
1 parent 4a101db commit 23b82e2

28 files changed

+261
-171
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: 51 additions & 41 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]):
@@ -361,28 +361,23 @@ class _AtIndexerFrame(_AtIndexer):
361361
),
362362
) -> None: ...
363363

364-
# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
365-
if sys.version_info >= (3, 12):
366-
class _GetItemHack:
367-
@overload
368-
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
364+
class _GetItemHack:
365+
@overload
366+
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
367+
# With mypy 1.14.1 and python 3.12, the second overload needs a type-ignore statement
368+
if sys.version_info >= (3, 12):
369369
@overload
370370
def __getitem__( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
371371
self, key: Iterable[Hashable] | slice
372372
) -> Self: ...
373-
@overload
374-
def __getitem__(self, key: Hashable) -> Series: ...
375-
376-
else:
377-
class _GetItemHack:
378-
@overload
379-
def __getitem__(self, key: Scalar | tuple[Hashable, ...]) -> Series: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
373+
else:
380374
@overload
381375
def __getitem__( # pyright: ignore[reportOverlappingOverload]
382376
self, key: Iterable[Hashable] | slice
383377
) -> Self: ...
384-
@overload
385-
def __getitem__(self, key: Hashable) -> Series: ...
378+
379+
@overload
380+
def __getitem__(self, key: Hashable) -> Series: ...
386381

387382
_AstypeArgExt: TypeAlias = (
388383
AstypeArg
@@ -484,7 +479,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
484479
self,
485480
orient: str = ...,
486481
*,
487-
into: type[defaultdict],
482+
into: type[defaultdict[Any, Any]],
488483
index: Literal[True] = True,
489484
) -> Never: ...
490485
@overload
@@ -500,7 +495,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
500495
self,
501496
orient: Literal["records"],
502497
*,
503-
into: type[dict] = ...,
498+
into: type[dict[Any, Any]] = ...,
504499
index: Literal[True] = True,
505500
) -> list[dict[Hashable, Any]]: ...
506501
@overload
@@ -516,23 +511,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
516511
self,
517512
orient: Literal["index"],
518513
*,
519-
into: OrderedDict | type[OrderedDict],
514+
into: OrderedDict[Any, Any] | type[OrderedDict[Any, Any]],
520515
index: Literal[True] = True,
521516
) -> OrderedDict[Hashable, dict[Hashable, Any]]: ...
522517
@overload
523518
def to_dict(
524519
self,
525520
orient: Literal["index"],
526521
*,
527-
into: type[MutableMapping],
522+
into: type[MutableMapping[Any, Any]],
528523
index: Literal[True] = True,
529524
) -> MutableMapping[Hashable, dict[Hashable, Any]]: ...
530525
@overload
531526
def to_dict(
532527
self,
533528
orient: Literal["index"],
534529
*,
535-
into: type[dict] = ...,
530+
into: type[dict[Any, Any]] = ...,
536531
index: Literal[True] = True,
537532
) -> dict[Hashable, dict[Hashable, Any]]: ...
538533
@overload
@@ -548,23 +543,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
548543
self,
549544
orient: Literal["dict", "list", "series"] = ...,
550545
*,
551-
into: type[dict] = ...,
546+
into: type[dict[Any, Any]] = ...,
552547
index: Literal[True] = True,
553548
) -> dict[Hashable, Any]: ...
554549
@overload
555550
def to_dict(
556551
self,
557552
orient: Literal["split", "tight"],
558553
*,
559-
into: MutableMapping[Any, Any] | type[MutableMapping],
554+
into: MutableMapping[Any, Any] | type[MutableMapping[Any, Any]],
560555
index: bool = ...,
561556
) -> MutableMapping[str, list[Any]]: ...
562557
@overload
563558
def to_dict(
564559
self,
565560
orient: Literal["split", "tight"],
566561
*,
567-
into: type[dict] = ...,
562+
into: type[dict[Any, Any]] = ...,
568563
index: bool = ...,
569564
) -> dict[str, list[Any]]: ...
570565
@classmethod
@@ -583,16 +578,29 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
583578
coerce_float: bool = False,
584579
nrows: int | None = None,
585580
) -> Self: ...
586-
def to_records(
587-
self,
588-
index: _bool = True,
589-
column_dtypes: (
590-
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
591-
) = None,
592-
index_dtypes: (
593-
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
594-
) = None,
595-
) -> np.recarray: ...
581+
if sys.version_info >= (3, 11):
582+
def to_records(
583+
self,
584+
index: _bool = True,
585+
column_dtypes: (
586+
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
587+
) = None,
588+
index_dtypes: (
589+
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
590+
) = None,
591+
) -> np.recarray: ...
592+
else:
593+
def to_records(
594+
self,
595+
index: _bool = True,
596+
column_dtypes: (
597+
_str | npt.DTypeLike | Mapping[HashableT1, npt.DTypeLike] | None
598+
) = None,
599+
index_dtypes: (
600+
_str | npt.DTypeLike | Mapping[HashableT2, npt.DTypeLike] | None
601+
) = None,
602+
) -> np.recarray[Any, Any]: ...
603+
596604
@overload
597605
def to_stata(
598606
self,
@@ -1381,7 +1389,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13811389
dropna: _bool = ...,
13821390
) -> DataFrameGroupBy[Period, Literal[False]]: ...
13831391
@overload
1384-
def groupby( # pyright: ignore reportOverlappingOverload
1392+
def groupby(
13851393
self,
13861394
by: IntervalIndex[IntervalT],
13871395
level: IndexLabel | None = ...,
@@ -1394,7 +1402,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13941402
@overload
13951403
def groupby(
13961404
self,
1397-
by: IntervalIndex[IntervalT],
1405+
by: IntervalIndex,
13981406
level: IndexLabel | None = ...,
13991407
as_index: Literal[False] = False,
14001408
sort: _bool = ...,
@@ -1480,9 +1488,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14801488
values: _PivotTableValuesTypes = None,
14811489
index: _PivotTableIndexTypes = None,
14821490
columns: _PivotTableColumnsTypes = None,
1483-
aggfunc: (
1484-
_PivotAggFunc | Sequence[_PivotAggFunc] | Mapping[Hashable, _PivotAggFunc]
1485-
) = "mean",
1491+
aggfunc: _PivotAggFuncTypes[Scalar] = "mean",
14861492
fill_value: Scalar | None = None,
14871493
margins: _bool = False,
14881494
dropna: _bool = True,
@@ -2863,8 +2869,12 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
28632869
def __rfloordiv__(
28642870
self, other: float | DataFrame | Series[int] | Series[float] | Sequence[float]
28652871
) -> Self: ...
2866-
def __truediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
2867-
def __rtruediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
2872+
def __truediv__(
2873+
self, other: float | DataFrame | Series | Sequence[Any]
2874+
) -> Self: ...
2875+
def __rtruediv__(
2876+
self, other: float | DataFrame | Series | Sequence[Any]
2877+
) -> Self: ...
28682878
@final
28692879
def __bool__(self) -> NoReturn: ...
28702880

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class GroupBy(BaseGroupBy[NDFrameT]):
338338
random_state: RandomState | None = ...,
339339
) -> NDFrameT: ...
340340

341-
_GroupByT = TypeVar("_GroupByT", bound=GroupBy)
341+
_GroupByT = TypeVar("_GroupByT", bound=GroupBy[Any])
342342

343343
# GroupByPlot does not really inherit from PlotAccessor but it delegates
344344
# to it using __call__ and __getattr__. We lie here to avoid repeating the
@@ -383,15 +383,15 @@ class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
383383
@final
384384
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ...
385385
@overload
386-
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
386+
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy[Any, Any]: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
387387
@overload
388388
def __getitem__(
389389
self: BaseGroupBy[DataFrame], key: Iterable[Hashable]
390-
) -> generic.DataFrameGroupBy: ...
390+
) -> generic.DataFrameGroupBy[Any, Any]: ...
391391
@overload
392392
def __getitem__(
393393
self: BaseGroupBy[Series[S1]],
394394
idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...],
395-
) -> generic.SeriesGroupBy: ...
395+
) -> generic.SeriesGroupBy[Any, Any]: ...
396396
@overload
397397
def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ...

0 commit comments

Comments
 (0)