99 TYPE_CHECKING ,
1010 Any ,
1111 Callable ,
12- Optional ,
1312 Sequence ,
14- Tuple ,
15- Type ,
1613 TypeVar ,
1714 Union ,
1815 cast ,
@@ -156,25 +153,25 @@ class DatetimeLikeArrayMixin(OpsMixin, NDArrayBackedExtensionArray):
156153 """
157154
158155 # _infer_matches -> which infer_dtype strings are close enough to our own
159- _infer_matches : Tuple [str , ...]
156+ _infer_matches : tuple [str , ...]
160157 _is_recognized_dtype : Callable [[DtypeObj ], bool ]
161- _recognized_scalars : Tuple [ Type , ...]
158+ _recognized_scalars : tuple [ type , ...]
162159 _ndarray : np .ndarray
163160
164- def __init__ (self , data , dtype : Optional [ Dtype ] = None , freq = None , copy = False ):
161+ def __init__ (self , data , dtype : Dtype | None = None , freq = None , copy = False ):
165162 raise AbstractMethodError (self )
166163
167164 @classmethod
168165 def _simple_new (
169- cls : Type [DatetimeLikeArrayT ],
166+ cls : type [DatetimeLikeArrayT ],
170167 values : np .ndarray ,
171- freq : Optional [ BaseOffset ] = None ,
172- dtype : Optional [ Dtype ] = None ,
168+ freq : BaseOffset | None = None ,
169+ dtype : Dtype | None = None ,
173170 ) -> DatetimeLikeArrayT :
174171 raise AbstractMethodError (cls )
175172
176173 @property
177- def _scalar_type (self ) -> Type [DatetimeLikeScalar ]:
174+ def _scalar_type (self ) -> type [DatetimeLikeScalar ]:
178175 """
179176 The scalar associated with this datelike
180177
@@ -206,7 +203,7 @@ def _scalar_from_string(self, value: str) -> DTScalarOrNaT:
206203
207204 def _unbox_scalar (
208205 self , value : DTScalarOrNaT , setitem : bool = False
209- ) -> Union [ np .int64 , np .datetime64 , np .timedelta64 ] :
206+ ) -> np .int64 | np .datetime64 | np .timedelta64 :
210207 """
211208 Unbox the integer value of a scalar `value`.
212209
@@ -334,15 +331,15 @@ def _formatter(self, boxed: bool = False):
334331 # ----------------------------------------------------------------
335332 # Array-Like / EA-Interface Methods
336333
337- def __array__ (self , dtype : Optional [ NpDtype ] = None ) -> np .ndarray :
334+ def __array__ (self , dtype : NpDtype | None = None ) -> np .ndarray :
338335 # used for Timedelta/DatetimeArray, overwritten by PeriodArray
339336 if is_object_dtype (dtype ):
340337 return np .array (list (self ), dtype = object )
341338 return self ._ndarray
342339
343340 def __getitem__ (
344- self , key : Union [ int , slice , np .ndarray ]
345- ) -> Union [ DatetimeLikeArrayMixin , DTScalarOrNaT ] :
341+ self , key : int | slice | np .ndarray
342+ ) -> DatetimeLikeArrayMixin | DTScalarOrNaT :
346343 """
347344 This getitem defers to the underlying array, which by-definition can
348345 only handle list-likes, slices, and integer scalars
@@ -354,7 +351,7 @@ def __getitem__(
354351 result ._freq = self ._get_getitem_freq (key )
355352 return result
356353
357- def _get_getitem_freq (self , key ) -> Optional [ BaseOffset ] :
354+ def _get_getitem_freq (self , key ) -> BaseOffset | None :
358355 """
359356 Find the `freq` attribute to assign to the result of a __getitem__ lookup.
360357 """
@@ -386,8 +383,8 @@ def _get_getitem_freq(self, key) -> Optional[BaseOffset]:
386383 # ndarray]"
387384 def __setitem__ ( # type: ignore[override]
388385 self ,
389- key : Union [ int , Sequence [int ], Sequence [bool ], slice ] ,
390- value : Union [ NaTType , Any , Sequence [Any ] ],
386+ key : int | Sequence [int ] | Sequence [bool ] | slice ,
387+ value : NaTType | Any | Sequence [Any ],
391388 ) -> None :
392389 # I'm fudging the types a bit here. "Any" above really depends
393390 # on type(self). For PeriodArray, it's Period (or stuff coercible
@@ -469,10 +466,10 @@ def view(self, dtype: Literal["m8[ns]"]) -> TimedeltaArray:
469466 ...
470467
471468 @overload
472- def view (self , dtype : Optional [ Dtype ] = ...) -> ArrayLike :
469+ def view (self , dtype : Dtype | None = ...) -> ArrayLike :
473470 ...
474471
475- def view (self , dtype : Optional [ Dtype ] = None ) -> ArrayLike :
472+ def view (self , dtype : Dtype | None = None ) -> ArrayLike :
476473 # We handle datetime64, datetime64tz, timedelta64, and period
477474 # dtypes here. Everything else we pass through to the underlying
478475 # ndarray.
@@ -509,7 +506,7 @@ def view(self, dtype: Optional[Dtype] = None) -> ArrayLike:
509506
510507 @classmethod
511508 def _concat_same_type (
512- cls : Type [DatetimeLikeArrayT ],
509+ cls : type [DatetimeLikeArrayT ],
513510 to_concat : Sequence [DatetimeLikeArrayT ],
514511 axis : int = 0 ,
515512 ) -> DatetimeLikeArrayT :
@@ -545,7 +542,7 @@ def _values_for_factorize(self):
545542
546543 @classmethod
547544 def _from_factorized (
548- cls : Type [DatetimeLikeArrayT ], values , original : DatetimeLikeArrayT
545+ cls : type [DatetimeLikeArrayT ], values , original : DatetimeLikeArrayT
549546 ) -> DatetimeLikeArrayT :
550547 return cls (values , dtype = original .dtype )
551548
@@ -789,7 +786,7 @@ def _validate_setitem_value(self, value):
789786
790787 def _unbox (
791788 self , other , setitem : bool = False
792- ) -> Union [ np .int64 , np .datetime64 , np .timedelta64 , np .ndarray ] :
789+ ) -> np .int64 | np .datetime64 | np .timedelta64 | np .ndarray :
793790 """
794791 Unbox either a scalar with _unbox_scalar or an instance of our own type.
795792 """
@@ -939,7 +936,7 @@ def freq(self, value):
939936 self ._freq = value
940937
941938 @property
942- def freqstr (self ) -> Optional [ str ] :
939+ def freqstr (self ) -> str | None :
943940 """
944941 Return the frequency object as a string if its set, otherwise None.
945942 """
@@ -948,7 +945,7 @@ def freqstr(self) -> Optional[str]:
948945 return self .freq .freqstr
949946
950947 @property # NB: override with cache_readonly in immutable subclasses
951- def inferred_freq (self ) -> Optional [ str ] :
948+ def inferred_freq (self ) -> str | None :
952949 """
953950 Tries to return a string representing a frequency guess,
954951 generated by infer_freq. Returns None if it can't autodetect the
@@ -962,7 +959,7 @@ def inferred_freq(self) -> Optional[str]:
962959 return None
963960
964961 @property # NB: override with cache_readonly in immutable subclasses
965- def _resolution_obj (self ) -> Optional [ Resolution ] :
962+ def _resolution_obj (self ) -> Resolution | None :
966963 freqstr = self .freqstr
967964 if freqstr is None :
968965 return None
@@ -1020,7 +1017,7 @@ def _validate_frequency(cls, index, freq, **kwargs):
10201017
10211018 @classmethod
10221019 def _generate_range (
1023- cls : Type [DatetimeLikeArrayT ], start , end , periods , freq , * args , ** kwargs
1020+ cls : type [DatetimeLikeArrayT ], start , end , periods , freq , * args , ** kwargs
10241021 ) -> DatetimeLikeArrayT :
10251022 raise AbstractMethodError (cls )
10261023
@@ -1443,7 +1440,7 @@ def __isub__(self, other):
14431440 # --------------------------------------------------------------
14441441 # Reductions
14451442
1446- def min (self , * , axis : Optional [ int ] = None , skipna : bool = True , ** kwargs ):
1443+ def min (self , * , axis : int | None = None , skipna : bool = True , ** kwargs ):
14471444 """
14481445 Return the minimum value of the Array or minimum along
14491446 an axis.
@@ -1472,7 +1469,7 @@ def min(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs):
14721469 result = nanops .nanmin (self ._ndarray , axis = axis , skipna = skipna )
14731470 return self ._wrap_reduction_result (axis , result )
14741471
1475- def max (self , * , axis : Optional [ int ] = None , skipna : bool = True , ** kwargs ):
1472+ def max (self , * , axis : int | None = None , skipna : bool = True , ** kwargs ):
14761473 """
14771474 Return the maximum value of the Array or maximum along
14781475 an axis.
@@ -1503,7 +1500,7 @@ def max(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs):
15031500 result = nanops .nanmax (self ._ndarray , axis = axis , skipna = skipna )
15041501 return self ._wrap_reduction_result (axis , result )
15051502
1506- def mean (self , * , skipna : bool = True , axis : Optional [ int ] = 0 ):
1503+ def mean (self , * , skipna : bool = True , axis : int | None = 0 ):
15071504 """
15081505 Return the mean value of the Array.
15091506
@@ -1542,7 +1539,7 @@ def mean(self, *, skipna: bool = True, axis: Optional[int] = 0):
15421539 )
15431540 return self ._wrap_reduction_result (axis , result )
15441541
1545- def median (self , * , axis : Optional [ int ] = None , skipna : bool = True , ** kwargs ):
1542+ def median (self , * , axis : int | None = None , skipna : bool = True , ** kwargs ):
15461543 nv .validate_median ((), kwargs )
15471544
15481545 if axis is not None and abs (axis ) >= self .ndim :
@@ -1752,11 +1749,11 @@ def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
17521749 # --------------------------------------------------------------
17531750 # Reductions
17541751
1755- def any (self , * , axis : Optional [ int ] = None , skipna : bool = True ):
1752+ def any (self , * , axis : int | None = None , skipna : bool = True ):
17561753 # GH#34479 discussion of desired behavior long-term
17571754 return nanops .nanany (self ._ndarray , axis = axis , skipna = skipna , mask = self .isna ())
17581755
1759- def all (self , * , axis : Optional [ int ] = None , skipna : bool = True ):
1756+ def all (self , * , axis : int | None = None , skipna : bool = True ):
17601757 # GH#34479 discussion of desired behavior long-term
17611758 return nanops .nanall (self ._ndarray , axis = axis , skipna = skipna , mask = self .isna ())
17621759
0 commit comments