Skip to content

Commit d715868

Browse files
author
Mateusz
committed
TYP: Fix core/groupby/generic.py lexsort attr-defined type ignore
GH37715
1 parent dafa5dd commit d715868

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pandas/core/groupby/generic.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from functools import partial
1212
from textwrap import dedent
1313
from typing import (
14+
TYPE_CHECKING,
1415
Any,
1516
Callable,
1617
Hashable,
@@ -89,6 +90,9 @@
8990

9091
from pandas.plotting import boxplot_frame_groupby
9192

93+
if TYPE_CHECKING:
94+
from pandas import Interval
95+
9296
# TODO(typing) the return value on this callable should be any *scalar*.
9397
AggScalar = Union[str, Callable[..., Any]]
9498
# TODO: validate types on ScalarResult and move to _typing
@@ -650,12 +654,9 @@ def value_counts(
650654

651655
if is_interval_dtype(lab.dtype):
652656
# TODO: should we do this inside II?
657+
lab_interval = cast(Interval, lab)
653658

654-
# error: "ndarray" has no attribute "left"
655-
# error: "ndarray" has no attribute "right"
656-
sorter = np.lexsort(
657-
(lab.left, lab.right, ids) # type: ignore[attr-defined]
658-
)
659+
sorter = np.lexsort((lab_interval.left, lab_interval.right, ids))
659660
else:
660661
sorter = np.lexsort((lab, ids))
661662

0 commit comments

Comments
 (0)