|
29 | 29 | from pandas._typing import ( |
30 | 30 | ArrayLike, |
31 | 31 | Dtype, |
| 32 | + IntervalClosedType, |
32 | 33 | NpDtype, |
33 | 34 | PositionalIndexer, |
34 | 35 | ScalarIndexer, |
@@ -200,6 +201,11 @@ class IntervalArray(IntervalMixin, ExtensionArray): |
200 | 201 | can_hold_na = True |
201 | 202 | _na_value = _fill_value = np.nan |
202 | 203 |
|
| 204 | + # To make mypy recognize the fields |
| 205 | + _left: np.ndarray |
| 206 | + _right: np.ndarray |
| 207 | + _dtype: IntervalDtype |
| 208 | + |
203 | 209 | # --------------------------------------------------------------------- |
204 | 210 | # Constructors |
205 | 211 |
|
@@ -660,11 +666,7 @@ def __getitem__( |
660 | 666 | if is_scalar(left) and isna(left): |
661 | 667 | return self._fill_value |
662 | 668 | return Interval(left, right, self.closed) |
663 | | - # error: Argument 1 to "ndim" has incompatible type "Union[ndarray, |
664 | | - # ExtensionArray]"; expected "Union[Union[int, float, complex, str, bytes, |
665 | | - # generic], Sequence[Union[int, float, complex, str, bytes, generic]], |
666 | | - # Sequence[Sequence[Any]], _SupportsArray]" |
667 | | - if np.ndim(left) > 1: # type: ignore[arg-type] |
| 669 | + if np.ndim(left) > 1: |
668 | 670 | # GH#30588 multi-dimensional indexer disallowed |
669 | 671 | raise ValueError("multi-dimensional indexing not allowed") |
670 | 672 | return self._shallow_copy(left, right) |
@@ -1368,7 +1370,7 @@ def closed(self): |
1368 | 1370 | ), |
1369 | 1371 | } |
1370 | 1372 | ) |
1371 | | - def set_closed(self: IntervalArrayT, closed) -> IntervalArrayT: |
| 1373 | + def set_closed(self: IntervalArrayT, closed: IntervalClosedType) -> IntervalArrayT: |
1372 | 1374 | if closed not in VALID_CLOSED: |
1373 | 1375 | msg = f"invalid option for 'closed': {closed}" |
1374 | 1376 | raise ValueError(msg) |
@@ -1669,8 +1671,14 @@ def _from_combined(self, combined: np.ndarray) -> IntervalArray: |
1669 | 1671 |
|
1670 | 1672 | dtype = self._left.dtype |
1671 | 1673 | if needs_i8_conversion(dtype): |
1672 | | - new_left = type(self._left)._from_sequence(nc[:, 0], dtype=dtype) |
1673 | | - new_right = type(self._right)._from_sequence(nc[:, 1], dtype=dtype) |
| 1674 | + # error: "Type[ndarray[Any, Any]]" has no attribute "_from_sequence" |
| 1675 | + new_left = type(self._left)._from_sequence( # type: ignore[attr-defined] |
| 1676 | + nc[:, 0], dtype=dtype |
| 1677 | + ) |
| 1678 | + # error: "Type[ndarray[Any, Any]]" has no attribute "_from_sequence" |
| 1679 | + new_right = type(self._right)._from_sequence( # type: ignore[attr-defined] |
| 1680 | + nc[:, 1], dtype=dtype |
| 1681 | + ) |
1674 | 1682 | else: |
1675 | 1683 | new_left = nc[:, 0].view(dtype) |
1676 | 1684 | new_right = nc[:, 1].view(dtype) |
|
0 commit comments