99from typing import (
1010 TYPE_CHECKING ,
1111 Literal ,
12- Union ,
12+ TypeAlias ,
1313 overload ,
1414)
1515
109109 )
110110
111111
112- IntervalSide = Union [ TimeArrayLike , np .ndarray ]
113- IntervalOrNA = Union [ Interval , float ]
112+ _IntervalSide : TypeAlias = TimeArrayLike | np .ndarray
113+ _IntervalOrNA : TypeAlias = Interval | float
114114
115115_interval_shared_docs : dict [str , str ] = {}
116116
@@ -216,8 +216,8 @@ def ndim(self) -> Literal[1]:
216216 return 1
217217
218218 # To make mypy recognize the fields
219- _left : IntervalSide
220- _right : IntervalSide
219+ _left : _IntervalSide
220+ _right : _IntervalSide
221221 _dtype : IntervalDtype
222222
223223 # ---------------------------------------------------------------------
@@ -234,8 +234,8 @@ def __new__(
234234 data = extract_array (data , extract_numpy = True )
235235
236236 if isinstance (data , cls ):
237- left : IntervalSide = data ._left
238- right : IntervalSide = data ._right
237+ left : _IntervalSide = data ._left
238+ right : _IntervalSide = data ._right
239239 closed = closed or data .closed
240240 dtype = IntervalDtype (left .dtype , closed = closed )
241241 else :
@@ -277,8 +277,8 @@ def __new__(
277277 @classmethod
278278 def _simple_new (
279279 cls ,
280- left : IntervalSide ,
281- right : IntervalSide ,
280+ left : _IntervalSide ,
281+ right : _IntervalSide ,
282282 dtype : IntervalDtype ,
283283 ) -> Self :
284284 result = IntervalMixin .__new__ (cls )
@@ -296,7 +296,7 @@ def _ensure_simple_new_inputs(
296296 closed : IntervalClosedType | None = None ,
297297 copy : bool = False ,
298298 dtype : Dtype | None = None ,
299- ) -> tuple [IntervalSide , IntervalSide , IntervalDtype ]:
299+ ) -> tuple [_IntervalSide , _IntervalSide , IntervalDtype ]:
300300 """Ensure correctness of input parameters for cls._simple_new."""
301301 from pandas .core .indexes .base import ensure_index
302302
@@ -704,12 +704,12 @@ def __len__(self) -> int:
704704 return len (self ._left )
705705
706706 @overload
707- def __getitem__ (self , key : ScalarIndexer ) -> IntervalOrNA : ...
707+ def __getitem__ (self , key : ScalarIndexer ) -> _IntervalOrNA : ...
708708
709709 @overload
710710 def __getitem__ (self , key : SequenceIndexer ) -> Self : ...
711711
712- def __getitem__ (self , key : PositionalIndexer ) -> Self | IntervalOrNA :
712+ def __getitem__ (self , key : PositionalIndexer ) -> Self | _IntervalOrNA :
713713 key = check_array_indexer (self , key )
714714 left = self ._left [key ]
715715 right = self ._right [key ]
@@ -858,7 +858,7 @@ def argsort(
858858 ascending = ascending , kind = kind , na_position = na_position , ** kwargs
859859 )
860860
861- def min (self , * , axis : AxisInt | None = None , skipna : bool = True ) -> IntervalOrNA :
861+ def min (self , * , axis : AxisInt | None = None , skipna : bool = True ) -> _IntervalOrNA :
862862 nv .validate_minmax_axis (axis , self .ndim )
863863
864864 if not len (self ):
@@ -875,7 +875,7 @@ def min(self, *, axis: AxisInt | None = None, skipna: bool = True) -> IntervalOr
875875 indexer = obj .argsort ()[0 ]
876876 return obj [indexer ]
877877
878- def max (self , * , axis : AxisInt | None = None , skipna : bool = True ) -> IntervalOrNA :
878+ def max (self , * , axis : AxisInt | None = None , skipna : bool = True ) -> _IntervalOrNA :
879879 nv .validate_minmax_axis (axis , self .ndim )
880880
881881 if not len (self ):
@@ -1016,8 +1016,10 @@ def _concat_same_type(cls, to_concat: Sequence[IntervalArray]) -> Self:
10161016 raise ValueError ("Intervals must all be closed on the same side." )
10171017 closed = closed_set .pop ()
10181018
1019- left : IntervalSide = np .concatenate ([interval .left for interval in to_concat ])
1020- right : IntervalSide = np .concatenate ([interval .right for interval in to_concat ])
1019+ left : _IntervalSide = np .concatenate ([interval .left for interval in to_concat ])
1020+ right : _IntervalSide = np .concatenate (
1021+ [interval .right for interval in to_concat ]
1022+ )
10211023
10221024 left , right , dtype = cls ._ensure_simple_new_inputs (left , right , closed = closed )
10231025
@@ -1952,7 +1954,7 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:
19521954 return isin (self .astype (object ), values .astype (object ))
19531955
19541956 @property
1955- def _combined (self ) -> IntervalSide :
1957+ def _combined (self ) -> _IntervalSide :
19561958 # error: Item "ExtensionArray" of "ExtensionArray | ndarray[Any, Any]"
19571959 # has no attribute "reshape" [union-attr]
19581960 left = self .left ._values .reshape (- 1 , 1 ) # type: ignore[union-attr]
0 commit comments