@@ -26,6 +26,7 @@ class providing the base-class of operations.
2626from typing import (
2727 TYPE_CHECKING ,
2828 Literal ,
29+ TypeAlias ,
2930 TypeVar ,
3031 Union ,
3132 cast ,
@@ -449,13 +450,13 @@ def f(self):
449450 return attr
450451
451452
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+ )
459460
460461
461462class BaseGroupBy (PandasObject , SelectionMixin [NDFrameT ], GroupByIndexingMixin ):
@@ -957,9 +958,8 @@ def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]:
957958 level = self .level
958959 result = self ._grouper .get_iterator (self ._selected_obj )
959960 # 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
963963 ):
964964 # GH#42795 - when keys is a list, return tuples even when length is 1
965965 result = (((key ,), group ) for key , group in result )
0 commit comments