@@ -26,6 +26,7 @@ class providing the base-class of operations.
26
26
from typing import (
27
27
TYPE_CHECKING ,
28
28
Literal ,
29
+ TypeAlias ,
29
30
TypeVar ,
30
31
Union ,
31
32
cast ,
@@ -449,13 +450,13 @@ def f(self):
449
450
return attr
450
451
451
452
452
- _KeysArgType = Union [
453
- Hashable ,
454
- list [Hashable ],
455
- Callable [[Hashable ], Hashable ],
456
- list [Callable [[Hashable ], Hashable ]],
457
- Mapping [Hashable , Hashable ],
458
- ]
453
+ _KeysArgType : TypeAlias = (
454
+ Hashable
455
+ | list [Hashable ]
456
+ | Callable [[Hashable ], Hashable ]
457
+ | list [Callable [[Hashable ], Hashable ]]
458
+ | Mapping [Hashable , Hashable ]
459
+ )
459
460
460
461
461
462
class BaseGroupBy (PandasObject , SelectionMixin [NDFrameT ], GroupByIndexingMixin ):
@@ -957,9 +958,8 @@ def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]:
957
958
level = self .level
958
959
result = self ._grouper .get_iterator (self ._selected_obj )
959
960
# mypy: Argument 1 to "len" has incompatible type "Hashable"; expected "Sized"
960
- if (
961
- (is_list_like (level ) and len (level ) == 1 ) # type: ignore[arg-type]
962
- or (isinstance (keys , list ) and len (keys ) == 1 )
961
+ if (is_list_like (level ) and len (level ) == 1 ) or ( # type: ignore[arg-type]
962
+ isinstance (keys , list ) and len (keys ) == 1
963
963
):
964
964
# GH#42795 - when keys is a list, return tuples even when length is 1
965
965
result = (((key ,), group ) for key , group in result )
0 commit comments