88 TYPE_CHECKING ,
99 Any ,
1010 Callable ,
11- Dict ,
1211 Hashable ,
1312 Iterable ,
1413 Iterator ,
15- List ,
1614 Mapping ,
17- Optional ,
18- Tuple ,
1915 TypeVar ,
20- Union ,
2116 overload ,
2217)
2318
@@ -164,9 +159,7 @@ def __iter__(self: Any) -> Iterator[Any]:
164159 raise TypeError ("iteration over a 0-d array" )
165160 return self ._iter ()
166161
167- def get_axis_num (
168- self , dim : Union [Hashable , Iterable [Hashable ]]
169- ) -> Union [int , Tuple [int , ...]]:
162+ def get_axis_num (self , dim : Hashable | Iterable [Hashable ]) -> int | tuple [int , ...]:
170163 """Return axis number(s) corresponding to dimension(s) in this array.
171164
172165 Parameters
@@ -244,7 +237,7 @@ def __getattr__(self, name: str) -> Any:
244237 with suppress (KeyError ):
245238 return source [name ]
246239 raise AttributeError (
247- "{ !r} object has no attribute {!r}". format ( type ( self ). __name__ , name )
240+ f" { type ( self ). __name__ !r} object has no attribute { name !r} "
248241 )
249242
250243 # This complicated two-method design boosts overall performance of simple operations
@@ -284,37 +277,37 @@ def __setattr__(self, name: str, value: Any) -> None:
284277 "assignment (e.g., `ds['name'] = ...`) instead of assigning variables."
285278 ) from e
286279
287- def __dir__ (self ) -> List [str ]:
280+ def __dir__ (self ) -> list [str ]:
288281 """Provide method name lookup and completion. Only provide 'public'
289282 methods.
290283 """
291- extra_attrs = set (
284+ extra_attrs = {
292285 item
293286 for source in self ._attr_sources
294287 for item in source
295288 if isinstance (item , str )
296- )
289+ }
297290 return sorted (set (dir (type (self ))) | extra_attrs )
298291
299- def _ipython_key_completions_ (self ) -> List [str ]:
292+ def _ipython_key_completions_ (self ) -> list [str ]:
300293 """Provide method for the key-autocompletions in IPython.
301294 See http://ipython.readthedocs.io/en/stable/config/integrating.html#tab-completion
302295 For the details.
303296 """
304- items = set (
297+ items = {
305298 item
306299 for source in self ._item_sources
307300 for item in source
308301 if isinstance (item , str )
309- )
302+ }
310303 return list (items )
311304
312305
313306def get_squeeze_dims (
314307 xarray_obj ,
315- dim : Union [ Hashable , Iterable [Hashable ], None ] = None ,
316- axis : Union [ int , Iterable [int ], None ] = None ,
317- ) -> List [Hashable ]:
308+ dim : Hashable | Iterable [Hashable ] | None = None ,
309+ axis : int | Iterable [int ] | None = None ,
310+ ) -> list [Hashable ]:
318311 """Get a list of dimensions to squeeze out."""
319312 if dim is not None and axis is not None :
320313 raise ValueError ("cannot use both parameters `axis` and `dim`" )
@@ -346,15 +339,15 @@ def get_squeeze_dims(
346339class DataWithCoords (AttrAccessMixin ):
347340 """Shared base class for Dataset and DataArray."""
348341
349- _close : Optional [ Callable [[], None ]]
342+ _close : Callable [[], None ] | None
350343
351344 __slots__ = ("_close" ,)
352345
353346 def squeeze (
354347 self ,
355- dim : Union [ Hashable , Iterable [Hashable ], None ] = None ,
348+ dim : Hashable | Iterable [Hashable ] | None = None ,
356349 drop : bool = False ,
357- axis : Union [ int , Iterable [int ], None ] = None ,
350+ axis : int | Iterable [int ] | None = None ,
358351 ):
359352 """Return a new object with squeezed data.
360353
@@ -416,8 +409,8 @@ def get_index(self, key: Hashable) -> pd.Index:
416409 return pd .Index (range (self .sizes [key ]), name = key )
417410
418411 def _calc_assign_results (
419- self : C , kwargs : Mapping [Any , Union [ T , Callable [[C ], T ] ]]
420- ) -> Dict [Hashable , T ]:
412+ self : C , kwargs : Mapping [Any , T | Callable [[C ], T ]]
413+ ) -> dict [Hashable , T ]:
421414 return {k : v (self ) if callable (v ) else v for k , v in kwargs .items ()}
422415
423416 def assign_coords (self , coords = None , ** coords_kwargs ):
@@ -535,7 +528,7 @@ def assign_attrs(self, *args, **kwargs):
535528
536529 def pipe (
537530 self ,
538- func : Union [ Callable [..., T ], Tuple [Callable [..., T ], str ] ],
531+ func : Callable [..., T ] | tuple [Callable [..., T ], str ],
539532 * args ,
540533 ** kwargs ,
541534 ) -> T :
@@ -802,7 +795,7 @@ def groupby_bins(
802795 },
803796 )
804797
805- def weighted (self : T_DataWithCoords , weights : " DataArray" ) -> Weighted [T_Xarray ]:
798+ def weighted (self : T_DataWithCoords , weights : DataArray ) -> Weighted [T_Xarray ]:
806799 """
807800 Weighted operations.
808801
@@ -825,7 +818,7 @@ def rolling(
825818 self ,
826819 dim : Mapping [Any , int ] = None ,
827820 min_periods : int = None ,
828- center : Union [ bool , Mapping [Any , bool ] ] = False ,
821+ center : bool | Mapping [Any , bool ] = False ,
829822 ** window_kwargs : int ,
830823 ):
831824 """
@@ -940,7 +933,7 @@ def coarsen(
940933 self ,
941934 dim : Mapping [Any , int ] = None ,
942935 boundary : str = "exact" ,
943- side : Union [ str , Mapping [Any , str ] ] = "left" ,
936+ side : str | Mapping [Any , str ] = "left" ,
944937 coord_func : str = "mean" ,
945938 ** window_kwargs : int ,
946939 ):
@@ -1290,7 +1283,7 @@ def where(self, cond, other=dtypes.NA, drop: bool = False):
12901283
12911284 return ops .where_method (self , cond , other )
12921285
1293- def set_close (self , close : Optional [ Callable [[], None ]] ) -> None :
1286+ def set_close (self , close : Callable [[], None ] | None ) -> None :
12941287 """Register the function that releases any resources linked to this object.
12951288
12961289 This method controls how xarray cleans up resources associated
@@ -1523,20 +1516,20 @@ def __getitem__(self, value):
15231516
15241517@overload
15251518def full_like (
1526- other : " Dataset" ,
1519+ other : Dataset ,
15271520 fill_value ,
1528- dtype : Union [ DTypeLike , Mapping [Any , DTypeLike ] ] = None ,
1529- ) -> " Dataset" :
1521+ dtype : DTypeLike | Mapping [Any , DTypeLike ] = None ,
1522+ ) -> Dataset :
15301523 ...
15311524
15321525
15331526@overload
1534- def full_like (other : " DataArray" , fill_value , dtype : DTypeLike = None ) -> " DataArray" :
1527+ def full_like (other : DataArray , fill_value , dtype : DTypeLike = None ) -> DataArray :
15351528 ...
15361529
15371530
15381531@overload
1539- def full_like (other : " Variable" , fill_value , dtype : DTypeLike = None ) -> " Variable" :
1532+ def full_like (other : Variable , fill_value , dtype : DTypeLike = None ) -> Variable :
15401533 ...
15411534
15421535
@@ -1815,9 +1808,9 @@ def ones_like(other, dtype: DTypeLike = None):
18151808
18161809def get_chunksizes (
18171810 variables : Iterable [Variable ],
1818- ) -> Mapping [Any , Tuple [int , ...]]:
1811+ ) -> Mapping [Any , tuple [int , ...]]:
18191812
1820- chunks : Dict [Any , Tuple [int , ...]] = {}
1813+ chunks : dict [Any , tuple [int , ...]] = {}
18211814 for v in variables :
18221815 if hasattr (v .data , "chunks" ):
18231816 for dim , c in v .chunksizes .items ():
0 commit comments