33import enum
44import logging
55import warnings
6- from collections .abc import Hashable , Iterable , Sequence
6+ from collections .abc import Callable , Hashable , Iterable , Sequence
77from functools import cached_property
8- from typing import (
9- TYPE_CHECKING , Any , Callable , Generic , Optional , TypeVar , Union , cast
10- )
8+ from typing import TYPE_CHECKING , Any , Generic , TypeVar , cast
119
1210import numpy
1311import xarray
@@ -166,7 +164,7 @@ def check_validity(cls, dataset: xarray.Dataset) -> None:
166164
167165 @classmethod
168166 @abc .abstractmethod
169- def check_dataset (cls , dataset : xarray .Dataset ) -> Optional [ int ] :
167+ def check_dataset (cls , dataset : xarray .Dataset ) -> int | None :
170168 """
171169 Check if a dataset uses this convention.
172170
@@ -582,7 +580,7 @@ def wind_index(
582580 self ,
583581 linear_index : int ,
584582 * ,
585- grid_kind : Optional [ GridKind ] = None ,
583+ grid_kind : GridKind | None = None ,
586584 ) -> Index :
587585 """Convert a linear index to a conventnion native index.
588586
@@ -635,7 +633,7 @@ def wind_index(
635633 def unravel_index (
636634 self ,
637635 linear_index : int ,
638- grid_kind : Optional [ GridKind ] = None ,
636+ grid_kind : GridKind | None = None ,
639637 ) -> Index :
640638 """An alias for :meth:`Convention.wind_index()`.
641639
@@ -772,7 +770,7 @@ def ravel(
772770 self ,
773771 data_array : xarray .DataArray ,
774772 * ,
775- linear_dimension : Optional [ Hashable ] = None ,
773+ linear_dimension : Hashable | None = None ,
776774 ) -> xarray .DataArray :
777775 """
778776 Flatten the surface dimensions of a :class:`~xarray.DataArray`,
@@ -815,9 +813,9 @@ def wind(
815813 self ,
816814 data_array : xarray .DataArray ,
817815 * ,
818- grid_kind : Optional [ GridKind ] = None ,
819- axis : Optional [ int ] = None ,
820- linear_dimension : Optional [ Hashable ] = None ,
816+ grid_kind : GridKind | None = None ,
817+ axis : int | None = None ,
818+ linear_dimension : Hashable | None = None ,
821819 ) -> xarray .DataArray :
822820 """
823821 Wind a flattened :class:`~xarray.DataArray`
@@ -935,9 +933,9 @@ def data_crs(self) -> 'CRS':
935933 def plot_on_figure (
936934 self ,
937935 figure : 'Figure' ,
938- scalar : Optional [ DataArrayOrName ] = None ,
939- vector : Optional [ tuple [DataArrayOrName , DataArrayOrName ]] = None ,
940- title : Optional [ str ] = None ,
936+ scalar : DataArrayOrName | None = None ,
937+ vector : tuple [DataArrayOrName , DataArrayOrName ] | None = None ,
938+ title : str | None = None ,
941939 ** kwargs : Any ,
942940 ) -> None :
943941 """Plot values for a :class:`~xarray.DataArray`
@@ -1015,10 +1013,10 @@ def plot(self, *args: Any, **kwargs: Any) -> None:
10151013 def animate_on_figure (
10161014 self ,
10171015 figure : 'Figure' ,
1018- scalar : Optional [ DataArrayOrName ] = None ,
1019- vector : Optional [ tuple [DataArrayOrName , DataArrayOrName ]] = None ,
1020- coordinate : Optional [ DataArrayOrName ] = None ,
1021- title : Optional [ Union [ str , Callable [[Any ], str ]]] = None ,
1016+ scalar : DataArrayOrName | None = None ,
1017+ vector : tuple [DataArrayOrName , DataArrayOrName ] | None = None ,
1018+ coordinate : DataArrayOrName | None = None ,
1019+ title : str | Callable [[Any ], str ] | None = None ,
10221020 ** kwargs : Any ,
10231021 ) -> 'FuncAnimation' :
10241022 """
@@ -1115,7 +1113,7 @@ def animate_on_figure(
11151113 @utils .timed_func
11161114 def make_poly_collection (
11171115 self ,
1118- data_array : Optional [ DataArrayOrName ] = None ,
1116+ data_array : DataArrayOrName | None = None ,
11191117 ** kwargs : Any ,
11201118 ) -> 'PolyCollection' :
11211119 """
@@ -1192,7 +1190,7 @@ def make_poly_collection(
11921190
11931191 def make_patch_collection (
11941192 self ,
1195- data_array : Optional [ DataArrayOrName ] = None ,
1193+ data_array : DataArrayOrName | None = None ,
11961194 ** kwargs : Any ,
11971195 ) -> 'PolyCollection' :
11981196 warnings .warn (
@@ -1206,8 +1204,8 @@ def make_patch_collection(
12061204 def make_quiver (
12071205 self ,
12081206 axes : 'Axes' ,
1209- u : Optional [ DataArrayOrName ] = None ,
1210- v : Optional [ DataArrayOrName ] = None ,
1207+ u : DataArrayOrName | None = None ,
1208+ v : DataArrayOrName | None = None ,
12111209 ** kwargs : Any ,
12121210 ) -> 'Quiver' :
12131211 """
@@ -1238,7 +1236,7 @@ def make_quiver(
12381236 # sometimes preferring to fill them in later,
12391237 # so `u` and `v` are optional.
12401238 # If they are not provided, we set default quiver values of `numpy.nan`.
1241- values : Union [ tuple [numpy .ndarray , numpy .ndarray ], tuple [float , float ] ]
1239+ values : tuple [numpy .ndarray , numpy .ndarray ] | tuple [float , float ]
12421240 values = numpy .nan , numpy .nan
12431241
12441242 if u is not None and v is not None :
@@ -1331,7 +1329,7 @@ def mask(self) -> numpy.ndarray:
13311329 return cast (numpy .ndarray , mask )
13321330
13331331 @cached_property
1334- def geometry (self ) -> Union [ Polygon , MultiPolygon ] :
1332+ def geometry (self ) -> Polygon | MultiPolygon :
13351333 """
13361334 A :class:`shapely.Polygon` or :class:`shapely.MultiPolygon` that represents
13371335 the geometry of the entire dataset.
@@ -1438,7 +1436,7 @@ def spatial_index(self) -> SpatialIndex[SpatialIndexItem[Index]]:
14381436 def get_index_for_point (
14391437 self ,
14401438 point : Point ,
1441- ) -> Optional [ SpatialIndexItem [Index ]] :
1439+ ) -> SpatialIndexItem [Index ] | None :
14421440 """
14431441 Find the index for a :class:`~shapely.Point` in the dataset.
14441442
@@ -1761,8 +1759,8 @@ def ocean_floor(self) -> xarray.Dataset:
17611759 def normalize_depth_variables (
17621760 self ,
17631761 * ,
1764- positive_down : Optional [ bool ] = None ,
1765- deep_to_shallow : Optional [ bool ] = None ,
1762+ positive_down : bool | None = None ,
1763+ deep_to_shallow : bool | None = None ,
17661764 ) -> xarray .Dataset :
17671765 """An alias for :func:`emsarray.operations.depth.normalize_depth_variables`"""
17681766 return depth .normalize_depth_variables (
@@ -1895,7 +1893,7 @@ def wind_index(
18951893 self ,
18961894 linear_index : int ,
18971895 * ,
1898- grid_kind : Optional [ GridKind ] = None ,
1896+ grid_kind : GridKind | None = None ,
18991897 ) -> Index :
19001898 if grid_kind is None :
19011899 grid_kind = self .default_grid_kind
@@ -1907,7 +1905,7 @@ def ravel(
19071905 self ,
19081906 data_array : xarray .DataArray ,
19091907 * ,
1910- linear_dimension : Optional [ Hashable ] = None ,
1908+ linear_dimension : Hashable | None = None ,
19111909 ) -> xarray .DataArray :
19121910 kind = self .get_grid_kind (data_array )
19131911 dimensions = self .grid_dimensions [kind ]
@@ -1919,9 +1917,9 @@ def wind(
19191917 self ,
19201918 data_array : xarray .DataArray ,
19211919 * ,
1922- grid_kind : Optional [ GridKind ] = None ,
1923- axis : Optional [ int ] = None ,
1924- linear_dimension : Optional [ Hashable ] = None ,
1920+ grid_kind : GridKind | None = None ,
1921+ axis : int | None = None ,
1922+ linear_dimension : Hashable | None = None ,
19251923 ) -> xarray .DataArray :
19261924 if axis is not None :
19271925 linear_dimension = data_array .dims [axis ]
0 commit comments