Skip to content

Commit 58050bc

Browse files
committed
Merge remote-tracking branch 'upstream/main' into typevar-default
2 parents 3a95013 + 32fdfe4 commit 58050bc

File tree

23 files changed

+283
-156
lines changed

23 files changed

+283
-156
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
- name: Run mypy on 'tests' (using the local stubs) and on the local stubs
3636
run: poetry run poe mypy
3737

38+
- name: Run ty on 'pandas-stubs' (using the local stubs) and on the local stubs
39+
run: poetry run poe ty
40+
3841
- name: Run pyright on 'tests' (using the local stubs) and on the local stubs
3942
run: poetry run poe pyright
4043

pandas-stubs/_config/config.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ class DisplayUnicode(DictWrapper):
4848
east_asian_width: bool
4949

5050
class Display(DictWrapper):
51-
chop_threshold: int | None
52-
colheader_justify: str
51+
chop_threshold: float | None
52+
colheader_justify: Literal["left", "right"]
5353
date_dayfirst: bool
5454
date_yearfirst: bool
5555
encoding: str
5656
expand_frame_repr: bool
5757
float_format: Callable[[float], str] | None
5858
html: DisplayHTML
59-
large_repr: str
59+
large_repr: Literal["truncate", "info"]
6060
latex: DisplayLaTeX
6161
max_categories: int
62-
max_columns: int
63-
max_colwidth: int
64-
max_dir_items: int
62+
max_columns: int | None
63+
max_colwidth: int | None
64+
max_dir_items: int | None
6565
max_info_columns: int
6666
max_info_rows: int
67-
max_rows: int
68-
max_seq_items: int
69-
memory_usage: bool
70-
min_rows: int
67+
max_rows: int | None
68+
max_seq_items: int | None
69+
memory_usage: bool | Literal["deep"] | None
70+
min_rows: int | None
7171
multi_sparse: bool
7272
notebook_repr_html: bool
7373
pprint_nest_depth: int
7474
precision: int
75-
show_dimensions: str
75+
show_dimensions: bool | Literal["truncate"]
7676
unicode: DisplayUnicode
7777
width: int
7878

pandas-stubs/_typing.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ from typing import (
1818
Protocol,
1919
SupportsIndex,
2020
TypedDict,
21+
Union,
2122
overload,
2223
)
2324

@@ -463,6 +464,10 @@ VoidDtypeArg: TypeAlias = (
463464
| Literal["V", "void", "void0"]
464465
)
465466

467+
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
468+
DtypeArg: TypeAlias = Dtype | Mapping[Hashable, Dtype]
469+
DtypeObj: TypeAlias = np.dtype[np.generic] | ExtensionDtype
470+
466471
AstypeArg: TypeAlias = (
467472
BooleanDtypeArg
468473
| IntDtypeArg
@@ -479,10 +484,6 @@ AstypeArg: TypeAlias = (
479484
| DtypeObj
480485
)
481486

482-
# DtypeArg specifies all allowable dtypes in a functions its dtype argument
483-
DtypeArg: TypeAlias = Dtype | Mapping[Hashable, Dtype]
484-
DtypeObj: TypeAlias = np.dtype[np.generic] | ExtensionDtype
485-
486487
# converters
487488
ConvertersArg: TypeAlias = Mapping[Hashable, Callable[[Dtype], Dtype]]
488489

@@ -513,7 +514,8 @@ IndexKeyFunc: TypeAlias = Callable[[Index], Index | AnyArrayLike] | None
513514

514515
# types of `func` kwarg for DataFrame.aggregate and Series.aggregate
515516
# More specific than what is in pandas
516-
AggFuncTypeBase: TypeAlias = Callable | str | np.ufunc
517+
# following Union is here to make it ty compliant https://github.com/astral-sh/ty/issues/591
518+
AggFuncTypeBase: TypeAlias = Union[Callable, str, np.ufunc] # noqa: UP007
517519
AggFuncTypeDictSeries: TypeAlias = Mapping[HashableT, AggFuncTypeBase]
518520
AggFuncTypeDictFrame: TypeAlias = Mapping[
519521
HashableT, AggFuncTypeBase | list[AggFuncTypeBase]
@@ -993,7 +995,7 @@ TimeZones: TypeAlias = str | tzinfo | None | int
993995

994996
# Evaluates to a DataFrame column in DataFrame.assign context.
995997
IntoColumn: TypeAlias = (
996-
AnyArrayLike | Scalar | Callable[[DataFrame], AnyArrayLike | Scalar]
998+
AnyArrayLike | Scalar | Callable[[DataFrame], AnyArrayLike | Scalar] | None
997999
)
9981000

9991001
DatetimeLike: TypeAlias = datetime.datetime | np.datetime64 | Timestamp

pandas-stubs/core/arrays/datetimes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import tzinfo
1+
from datetime import tzinfo as _tzinfo
22

33
import numpy as np
44
from pandas.core.arrays.datetimelike import (
@@ -28,7 +28,7 @@ class DatetimeArray(DatetimeLikeArrayMixin, TimelikeOps, DatelikeOps):
2828
@tz.setter
2929
def tz(self, value) -> None: ...
3030
@property
31-
def tzinfo(self) -> tzinfo | None: ...
31+
def tzinfo(self) -> _tzinfo | None: ...
3232
@property
3333
def is_normalized(self): ...
3434
def __array__(self, dtype=...) -> np.ndarray: ...

pandas-stubs/core/frame.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from builtins import (
2+
bool as _bool,
3+
str as _str,
4+
)
15
from collections.abc import (
26
Callable,
37
Hashable,
@@ -160,9 +164,6 @@ from pandas._typing import (
160164
from pandas.io.formats.style import Styler
161165
from pandas.plotting import PlotAccessor
162166

163-
_str = str
164-
_bool = bool
165-
166167
class _iLocIndexerFrame(_iLocIndexer, Generic[_T]):
167168
@overload
168169
def __getitem__(self, idx: tuple[int, int]) -> Scalar: ...
@@ -2150,7 +2151,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
21502151
def reindex_like(
21512152
self,
21522153
other: DataFrame,
2153-
method: _str | FillnaOptions | Literal["nearest"] | None = ...,
2154+
method: FillnaOptions | Literal["nearest"] | None = ...,
21542155
copy: _bool = ...,
21552156
limit: int | None = ...,
21562157
tolerance: Scalar | AnyArrayLike | Sequence[Scalar] = ...,

pandas-stubs/core/generic.pyi

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from builtins import (
2+
bool as _bool,
3+
str as _str,
4+
)
15
from collections.abc import (
26
Callable,
37
Hashable,
@@ -60,17 +64,14 @@ from pandas._typing import (
6064
from pandas.io.pytables import HDFStore
6165
from pandas.io.sql import SQLTable
6266

63-
_bool = bool
64-
_str = str
65-
6667
class NDFrame(indexing.IndexingMixin):
6768
__hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
6869

6970
def set_flags(
7071
self,
7172
*,
72-
copy: bool = ...,
73-
allows_duplicate_labels: bool | None = ...,
73+
copy: _bool = ...,
74+
allows_duplicate_labels: _bool | None = ...,
7475
) -> Self: ...
7576
@property
7677
def attrs(self) -> dict[Hashable | None, Any]: ...

pandas-stubs/core/groupby/groupby.pyi

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ from pandas._typing import (
7575

7676
from pandas.plotting import PlotAccessor
7777

78-
_GroupByT = TypeVar("_GroupByT", bound=GroupBy)
79-
8078
_KeysArgType: TypeAlias = (
8179
Hashable
8280
| list[Hashable]
@@ -91,67 +89,6 @@ _ResamplerGroupBy: TypeAlias = (
9189
| TimedeltaIndexResamplerGroupby[NDFrameT]
9290
)
9391

94-
# GroupByPlot does not really inherit from PlotAccessor but it delegates
95-
# to it using __call__ and __getattr__. We lie here to avoid repeating the
96-
# whole stub of PlotAccessor
97-
@final
98-
class GroupByPlot(PlotAccessor, Generic[_GroupByT]):
99-
def __init__(self, groupby: _GroupByT) -> None: ...
100-
# The following methods are inherited from the fake parent class PlotAccessor
101-
# def __call__(self, *args, **kwargs): ...
102-
# def __getattr__(self, name: str): ...
103-
104-
class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
105-
axis: AxisInt
106-
grouper: ops.BaseGrouper
107-
keys: _KeysArgType | None
108-
level: IndexLabel | None
109-
group_keys: bool
110-
@final
111-
def __len__(self) -> int: ...
112-
@final
113-
def __repr__(self) -> str: ... # noqa: PYI029 __repr__ here is final
114-
@final
115-
@property
116-
def groups(self) -> dict[Hashable, Index]: ...
117-
@final
118-
@property
119-
def ngroups(self) -> int: ...
120-
@final
121-
@property
122-
def indices(self) -> dict[Hashable, Index | npt.NDArray[np.int_] | list[int]]: ...
123-
@overload
124-
def pipe(
125-
self,
126-
func: Callable[Concatenate[Self, P], T],
127-
*args: P.args,
128-
**kwargs: P.kwargs,
129-
) -> T: ...
130-
@overload
131-
def pipe(
132-
self,
133-
func: tuple[Callable[..., T], str],
134-
*args: Any,
135-
**kwargs: Any,
136-
) -> T: ...
137-
@final
138-
def get_group(self, name, obj: NDFrameT | None = ...) -> NDFrameT: ...
139-
@final
140-
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ...
141-
@overload
142-
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
143-
@overload
144-
def __getitem__(
145-
self: BaseGroupBy[DataFrame], key: Iterable[Hashable]
146-
) -> generic.DataFrameGroupBy: ...
147-
@overload
148-
def __getitem__(
149-
self: BaseGroupBy[Series[S1]],
150-
idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...],
151-
) -> generic.SeriesGroupBy: ...
152-
@overload
153-
def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ...
154-
15592
class GroupBy(BaseGroupBy[NDFrameT]):
15693
as_index: bool
15794
sort: bool
@@ -393,3 +330,66 @@ class GroupBy(BaseGroupBy[NDFrameT]):
393330
weights: Sequence | Series | None = ...,
394331
random_state: RandomState | None = ...,
395332
) -> NDFrameT: ...
333+
334+
_GroupByT = TypeVar("_GroupByT", bound=GroupBy)
335+
336+
# GroupByPlot does not really inherit from PlotAccessor but it delegates
337+
# to it using __call__ and __getattr__. We lie here to avoid repeating the
338+
# whole stub of PlotAccessor
339+
@final
340+
class GroupByPlot(PlotAccessor, Generic[_GroupByT]):
341+
def __init__(self, groupby: _GroupByT) -> None: ...
342+
# The following methods are inherited from the fake parent class PlotAccessor
343+
# def __call__(self, *args, **kwargs): ...
344+
# def __getattr__(self, name: str): ...
345+
346+
class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin):
347+
axis: AxisInt
348+
grouper: ops.BaseGrouper
349+
keys: _KeysArgType | None
350+
level: IndexLabel | None
351+
group_keys: bool
352+
@final
353+
def __len__(self) -> int: ...
354+
@final
355+
def __repr__(self) -> str: ... # noqa: PYI029 __repr__ here is final
356+
@final
357+
@property
358+
def groups(self) -> dict[Hashable, Index]: ...
359+
@final
360+
@property
361+
def ngroups(self) -> int: ...
362+
@final
363+
@property
364+
def indices(self) -> dict[Hashable, Index | npt.NDArray[np.int_] | list[int]]: ...
365+
@overload
366+
def pipe(
367+
self,
368+
func: Callable[Concatenate[Self, P], T],
369+
*args: P.args,
370+
**kwargs: P.kwargs,
371+
) -> T: ...
372+
@overload
373+
def pipe(
374+
self,
375+
func: tuple[Callable[..., T], str],
376+
*args: Any,
377+
**kwargs: Any,
378+
) -> T: ...
379+
@final
380+
def get_group(self, name, obj: NDFrameT | None = ...) -> NDFrameT: ...
381+
@final
382+
def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ...
383+
@overload
384+
def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
385+
@overload
386+
def __getitem__(
387+
self: BaseGroupBy[DataFrame], key: Iterable[Hashable]
388+
) -> generic.DataFrameGroupBy: ...
389+
@overload
390+
def __getitem__(
391+
self: BaseGroupBy[Series[S1]],
392+
idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...],
393+
) -> generic.SeriesGroupBy: ...
394+
@overload
395+
def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ...

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime as dt
22
from datetime import (
33
timedelta,
4-
tzinfo,
4+
tzinfo as _tzinfo,
55
)
66
from typing import (
77
Generic,
@@ -119,7 +119,7 @@ class _FreqProperty(Generic[_DTFreqReturnType]):
119119

120120
class _TZProperty:
121121
@property
122-
def tz(self) -> tzinfo | None: ...
122+
def tz(self) -> _tzinfo | None: ...
123123

124124
class _DatetimeObjectOps(
125125
_FreqProperty[_DTFreqReturnType], _TZProperty, Generic[_DTFreqReturnType]
@@ -416,7 +416,7 @@ class DatetimeIndexProperties(
416416
@property
417417
def is_normalized(self) -> bool: ...
418418
@property
419-
def tzinfo(self) -> tzinfo | None: ...
419+
def tzinfo(self) -> _tzinfo | None: ...
420420
def to_pydatetime(self) -> npt.NDArray[np.object_]: ...
421421
def std(
422422
self, axis: int | None = ..., ddof: int = ..., skipna: bool = ...

pandas-stubs/core/indexes/base.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str as _str
12
from collections.abc import (
23
Callable,
34
Hashable,
@@ -66,8 +67,6 @@ from pandas._typing import (
6667

6768
class InvalidIndexError(Exception): ...
6869

69-
_str = str
70-
7170
class Index(IndexOpsMixin[S1]):
7271
__hash__: ClassVar[None] # type: ignore[assignment]
7372
# overloads with additional dtypes
@@ -272,10 +271,10 @@ class Index(IndexOpsMixin[S1]):
272271
Self,
273272
MultiIndex,
274273
np_ndarray_bool,
275-
Index[list[str]],
274+
Index[list[_str]],
276275
Index[int],
277276
Index[bytes],
278-
Index[str],
277+
Index[_str],
279278
Index[type[object]],
280279
]: ...
281280
def is_(self, other) -> bool: ...
@@ -478,7 +477,7 @@ class Index(IndexOpsMixin[S1]):
478477
UnknownIndex: TypeAlias = Index[Any]
479478

480479
def ensure_index_from_sequences(
481-
sequences: Sequence[Sequence[Dtype]], names: list[str] = ...
480+
sequences: Sequence[Sequence[Dtype]], names: list[_str] = ...
482481
) -> Index: ...
483482
def ensure_index(index_like: Sequence | Index, copy: bool = ...) -> Index: ...
484483
def maybe_extract_name(name, obj, cls) -> Label: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from collections.abc import (
55
from datetime import (
66
datetime,
77
timedelta,
8-
tzinfo,
8+
tzinfo as _tzinfo,
99
)
1010
from typing import overload
1111

@@ -85,7 +85,7 @@ class DatetimeIndex(DatetimeTimedeltaMixin[Timestamp], DatetimeIndexProperties):
8585
def to_julian_date(self) -> Index[float]: ...
8686
def isocalendar(self) -> DataFrame: ...
8787
@property
88-
def tzinfo(self) -> tzinfo | None: ...
88+
def tzinfo(self) -> _tzinfo | None: ...
8989
@property
9090
def dtype(self) -> np.dtype | DatetimeTZDtype: ...
9191
def shift(self, periods: int = ..., freq=...) -> Self: ...

0 commit comments

Comments
 (0)