Skip to content

Commit a9c601c

Browse files
committed
other cases
1 parent 5a28b37 commit a9c601c

File tree

10 files changed

+39
-39
lines changed

10 files changed

+39
-39
lines changed

pandas-stubs/_typing.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ if TYPE_CHECKING: # noqa: PYI002
10801080
| Interval[int | float | Timestamp | Timedelta],
10811081
)
10821082
GroupByObjectNonScalar: TypeAlias = (
1083-
tuple
1083+
tuple[_HashableTa, ...]
10841084
| list[_HashableTa]
10851085
| Function
10861086
| list[Function]

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14011401
group_keys: _bool = ...,
14021402
observed: _bool | _NoDefaultDoNotUse = ...,
14031403
dropna: _bool = ...,
1404-
) -> DataFrameGroupBy[tuple, Literal[True]]: ...
1404+
) -> DataFrameGroupBy[tuple[Hashable, ...], Literal[True]]: ...
14051405
@overload
14061406
def groupby( # type: ignore[overload-overlap]
14071407
self,
@@ -1412,7 +1412,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14121412
group_keys: _bool = ...,
14131413
observed: _bool | _NoDefaultDoNotUse = ...,
14141414
dropna: _bool = ...,
1415-
) -> DataFrameGroupBy[tuple, Literal[False]]: ...
1415+
) -> DataFrameGroupBy[tuple[Hashable, ...], Literal[False]]: ...
14161416
@overload
14171417
def groupby( # pyright: ignore reportOverlappingOverload
14181418
self,

pandas-stubs/core/groupby/indexing.pyi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ _GroupByT = TypeVar("_GroupByT", bound=groupby.GroupBy[Any])
1717

1818
class GroupByIndexingMixin: ...
1919

20-
class GroupByPositionalSelector:
21-
groupby_object: groupby.GroupBy
22-
def __getitem__(self, arg: PositionalIndexer | tuple) -> DataFrame | Series: ...
23-
2420
class GroupByNthSelector(Generic[_GroupByT]):
2521
groupby_object: _GroupByT
2622

2723
def __call__(
2824
self,
29-
n: PositionalIndexer | tuple,
25+
n: PositionalIndexer | tuple[int, ...],
3026
dropna: Literal["any", "all"] | None = ...,
3127
) -> DataFrame | Series: ...
32-
def __getitem__(self, n: PositionalIndexer | tuple) -> DataFrame | Series: ...
28+
def __getitem__(
29+
self, n: PositionalIndexer | tuple[int, ...]
30+
) -> DataFrame | Series: ...

pandas-stubs/core/indexes/multi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class MultiIndex(Index):
135135
@overload
136136
def __getitem__( # pyright: ignore[reportIncompatibleMethodOverride] # ty: ignore[invalid-method-override]
137137
self, key: int
138-
) -> tuple: ...
138+
) -> tuple[Hashable, ...]: ...
139139
def append(self, other): ...
140140
def repeat(self, repeats, axis=...): ...
141141
def drop(self, codes, level: Level | None = None, errors: str = "raise") -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

pandas-stubs/core/series.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
845845
group_keys: _bool = ...,
846846
observed: _bool | _NoDefaultDoNotUse = ...,
847847
dropna: _bool = ...,
848-
) -> SeriesGroupBy[S1, tuple]: ...
848+
) -> SeriesGroupBy[S1, tuple[Hashable, ...]]: ...
849849
@overload
850850
def groupby(
851851
self,
@@ -1171,7 +1171,7 @@ class Series(IndexOpsMixin[S1], ElementOpsMixin[S1], NDFrame):
11711171
..., Scalar | Sequence | set | Mapping | NAType | frozenset | None
11721172
],
11731173
convertDType: _bool = ...,
1174-
args: tuple = ...,
1174+
args: tuple[Any, ...] = ...,
11751175
**kwargs: Any,
11761176
) -> Series: ...
11771177
@overload

pandas-stubs/io/parquet.pyi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from typing import Any
1+
from collections.abc import Sequence
2+
from typing import (
3+
Any,
4+
TypeAlias,
5+
)
26

37
from pandas import DataFrame
48

@@ -10,13 +14,15 @@ from pandas._typing import (
1014
StorageOptions,
1115
)
1216

17+
_Filter: TypeAlias = tuple[str, str, Any]
18+
1319
def read_parquet(
1420
path: FilePath | ReadBuffer[bytes],
1521
engine: ParquetEngine = "auto",
1622
columns: list[str] | None = None,
1723
storage_options: StorageOptions = None,
1824
dtype_backend: DtypeBackend = "numpy_nullable",
1925
filesystem: Any = None,
20-
filters: list[tuple] | list[list[tuple]] | None = None,
26+
filters: Sequence[_Filter] | Sequence[Sequence[_Filter]] | None = None,
2127
**kwargs: Any,
2228
) -> DataFrame: ...

tests/indexes/test_indexes.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -964,10 +964,7 @@ def test_getitem() -> None:
964964

965965
iints = pd.interval_range(dt.datetime(2000, 1, 1), dt.datetime(2010, 1, 1), 5)
966966
check(
967-
assert_type(
968-
iints,
969-
"pd.IntervalIndex[pd.Interval[pd.Timestamp]]",
970-
),
967+
assert_type(iints, "pd.IntervalIndex[pd.Interval[pd.Timestamp]]"),
971968
pd.IntervalIndex,
972969
pd.Interval,
973970
)
@@ -980,10 +977,7 @@ def test_getitem() -> None:
980977

981978
iintd = pd.interval_range(pd.Timedelta("1D"), pd.Timedelta("10D"))
982979
check(
983-
assert_type(
984-
iintd,
985-
"pd.IntervalIndex[pd.Interval[pd.Timedelta]]",
986-
),
980+
assert_type(iintd, "pd.IntervalIndex[pd.Interval[pd.Timedelta]]"),
987981
pd.IntervalIndex,
988982
pd.Interval,
989983
)
@@ -1005,7 +999,7 @@ def test_getitem() -> None:
1005999

10061000
mi = pd.MultiIndex.from_product([["a", "b"], ["c", "d"]], names=["ab", "cd"])
10071001
check(assert_type(mi, pd.MultiIndex), pd.MultiIndex)
1008-
check(assert_type(mi[0], tuple), tuple)
1002+
check(assert_type(mi[0], tuple[Hashable, ...]), tuple, str)
10091003
check(assert_type(mi[[0, 2]], pd.MultiIndex), pd.MultiIndex, tuple)
10101004

10111005
i0 = pd.Index(["a", "b", "c"])

tests/series/test_series.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,14 @@ def test_groupby_result() -> None:
10151015
multi_index = pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0)], names=["a", "b"])
10161016
s = pd.Series([0, 1, 2], index=multi_index, dtype=int)
10171017
iterator = s.groupby(["a", "b"]).__iter__()
1018-
assert_type(iterator, Iterator[tuple[tuple, "pd.Series[int]"]])
1018+
assert_type(iterator, Iterator[tuple[tuple[Hashable, ...], "pd.Series[int]"]])
10191019
index, value = next(iterator)
1020-
assert_type((index, value), tuple[tuple, "pd.Series[int]"])
1020+
assert_type((index, value), tuple[tuple[Hashable, ...], "pd.Series[int]"])
10211021

10221022
if PD_LTE_23:
1023-
check(assert_type(index, tuple), tuple, np.integer)
1023+
check(assert_type(index, tuple[Hashable, ...]), tuple, np.integer)
10241024
else:
1025-
check(assert_type(index, tuple), tuple, int)
1025+
check(assert_type(index, tuple[Hashable, ...]), tuple, int)
10261026

10271027
check(assert_type(value, "pd.Series[int]"), pd.Series, np.integer)
10281028

@@ -1037,11 +1037,11 @@ def test_groupby_result() -> None:
10371037
# GH 674
10381038
# grouping by pd.MultiIndex should always resolve to a tuple as well
10391039
iterator3 = s.groupby(multi_index).__iter__()
1040-
assert_type(iterator3, Iterator[tuple[tuple, "pd.Series[int]"]])
1040+
assert_type(iterator3, Iterator[tuple[tuple[Hashable, ...], "pd.Series[int]"]])
10411041
index3, value3 = next(iterator3)
1042-
assert_type((index3, value3), tuple[tuple, "pd.Series[int]"])
1042+
assert_type((index3, value3), tuple[tuple[Hashable, ...], "pd.Series[int]"])
10431043

1044-
check(assert_type(index3, tuple), tuple, int)
1044+
check(assert_type(index3, tuple[Hashable, ...]), tuple, int)
10451045
check(assert_type(value3, "pd.Series[int]"), pd.Series, np.integer)
10461046

10471047
# Explicit by=None

tests/test_frame.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,8 @@ def test_groupby_series_methods() -> None:
29592959
check(assert_type(gb.nlargest(), pd.Series), pd.Series)
29602960
check(assert_type(gb.nsmallest(), pd.Series), pd.Series)
29612961
check(assert_type(gb.nth(0), pd.DataFrame | pd.Series), pd.Series)
2962+
check(assert_type(gb.nth[0, 1, 2], pd.DataFrame | pd.Series), pd.Series)
2963+
check(assert_type(gb.nth((0, 1, 2)), pd.DataFrame | pd.Series), pd.Series)
29622964

29632965

29642966
def test_dataframe_pct_change() -> None:
@@ -3591,14 +3593,14 @@ def test_groupby_result() -> None:
35913593
# GH 142
35923594
df = pd.DataFrame({"a": [0, 1, 2], "b": [4, 5, 6], "c": [7, 8, 9]})
35933595
iterator = df.groupby(["a", "b"]).__iter__()
3594-
assert_type(iterator, Iterator[tuple[tuple, pd.DataFrame]])
3596+
assert_type(iterator, Iterator[tuple[tuple[Hashable, ...], pd.DataFrame]])
35953597
index, value = next(iterator)
3596-
assert_type((index, value), tuple[tuple, pd.DataFrame])
3598+
assert_type((index, value), tuple[tuple[Hashable, ...], pd.DataFrame])
35973599

35983600
if PD_LTE_23:
3599-
check(assert_type(index, tuple), tuple, np.integer)
3601+
check(assert_type(index, tuple[Hashable, ...]), tuple, np.integer)
36003602
else:
3601-
check(assert_type(index, tuple), tuple, int)
3603+
check(assert_type(index, tuple[Hashable, ...]), tuple, int)
36023604

36033605
check(assert_type(value, pd.DataFrame), pd.DataFrame)
36043606

@@ -3614,11 +3616,11 @@ def test_groupby_result() -> None:
36143616
# grouping by pd.MultiIndex should always resolve to a tuple as well
36153617
multi_index = pd.MultiIndex.from_frame(df[["a", "b"]])
36163618
iterator3 = df.groupby(multi_index).__iter__()
3617-
assert_type(iterator3, Iterator[tuple[tuple, pd.DataFrame]])
3619+
assert_type(iterator3, Iterator[tuple[tuple[Hashable, ...], pd.DataFrame]])
36183620
index3, value3 = next(iterator3)
3619-
assert_type((index3, value3), tuple[tuple, pd.DataFrame])
3621+
assert_type((index3, value3), tuple[tuple[Hashable, ...], pd.DataFrame])
36203622

3621-
check(assert_type(index3, tuple), tuple, int)
3623+
check(assert_type(index3, tuple[Hashable, ...]), tuple, int)
36223624
check(assert_type(value3, pd.DataFrame), pd.DataFrame)
36233625

36243626
# Want to make sure these cases are differentiated

tests/test_pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,8 +1712,8 @@ def m2(x: pd.Series) -> int:
17121712
assert_type(pd.crosstab(a, b, colnames=["a"], rownames=["b"]), pd.DataFrame),
17131713
pd.DataFrame,
17141714
)
1715-
rownames: list[tuple] = [("b", 1)]
1716-
colnames: list[tuple] = [("a",)]
1715+
rownames: list[tuple[str, int]] = [("b", 1)]
1716+
colnames: list[tuple[str]] = [("a",)]
17171717
check(
17181718
assert_type(
17191719
pd.crosstab(a, b, colnames=colnames, rownames=rownames),

0 commit comments

Comments
 (0)