Skip to content

Commit

Permalink
Remove typing statements not supported by 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
huard committed Nov 10, 2023
1 parent 5be7f20 commit 76ff3f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions xesmf/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Standard test data for regridding benchmark.
"""

from typing import Any
from typing import Union

import numpy as np
import numpy.typing as npt
import xarray


def wave_smooth( # type: ignore
lon: npt.NDArray[np.floating[Any]] | xarray.DataArray,
lat: npt.NDArray[np.floating[Any]] | xarray.DataArray,
) -> npt.NDArray[np.floating[Any]] | xarray.DataArray:
lon: Union[npt.NDArray, xarray.DataArray],
lat: Union[npt.NDArray, xarray.DataArray],
) -> Union[npt.NDArray, xarray.DataArray]:
"""
Spherical harmonic with low frequency.
Expand Down
14 changes: 7 additions & 7 deletions xesmf/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

import warnings
from typing import Any, Dict, Hashable, List, Literal, Optional, Sequence, Tuple
from typing import Any, Dict, Hashable, List, Literal, Optional, Sequence, Tuple, Union

import cf_xarray as cfxr
import numpy as np
Expand Down Expand Up @@ -270,8 +270,8 @@ def polys_to_ESMFmesh(polys) -> tuple[Mesh, tuple[Literal[1], int]]:
class BaseRegridder(object):
def __init__(
self,
grid_in: Grid | LocStream | Mesh,
grid_out: Grid | LocStream | Mesh,
grid_in: Union[Grid, LocStream, Mesh],
grid_out: Union[Grid, LocStream, Mesh],
method: str,
filename: Optional[str] = None,
reuse_weights: bool = False,
Expand Down Expand Up @@ -492,7 +492,7 @@ def __call__(
keep_attrs: bool = False,
skipna: bool = False,
na_thres: float = 1.0,
output_chunks: Optional[Dict[str, int] | Tuple[int, ...]] = None,
output_chunks: Optional[Union[Dict[str, int], Tuple[int, ...]]] = None,
):
"""
Apply regridding to input data.
Expand Down Expand Up @@ -629,7 +629,7 @@ def regrid_array(
weights: sps.coo_matrix,
skipna: bool = False,
na_thres: float = 1.0,
output_chunks: Optional[Tuple[int, ...] | Dict[str, int]] = None,
output_chunks: Optional[Union[Tuple[int, ...], Dict[str, int]]] = None,
):
"""See __call__()."""
if self.sequence_in:
Expand Down Expand Up @@ -693,7 +693,7 @@ def regrid_dataarray(
keep_attrs: bool = False,
skipna: bool = False,
na_thres: float = 1.0,
output_chunks: Optional[Dict[str, int] | Tuple[int, ...]] = None,
output_chunks: Optional[Union[Dict[str, int], Tuple[int, ...]]] = None,
) -> DataArray | Dataset:
"""See __call__()."""

Expand All @@ -718,7 +718,7 @@ def regrid_dataset(
keep_attrs: bool = False,
skipna: bool = False,
na_thres: float = 1.0,
output_chunks: Optional[Dict[str, int] | Tuple[int, ...]] = None,
output_chunks: Optional[Union[Dict[str, int], Tuple[int, ...]]] = None,
) -> DataArray | Dataset:
"""See __call__()."""

Expand Down
6 changes: 3 additions & 3 deletions xesmf/smm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import warnings
from pathlib import Path
from typing import Any, Tuple
from typing import Any, Dict, Tuple, Union

import numba as nb # type: ignore[import]
import numpy as np
Expand All @@ -13,7 +13,7 @@


def read_weights(
weights: str | Path | xr.Dataset | xr.DataArray | sps.COO | dict[str, Any],
weights: Union[str, Path, xr.Dataset, xr.DataArray, sps.COO, Dict[str, Any]],
n_in: int,
n_out: int,
) -> xr.DataArray:
Expand Down Expand Up @@ -56,7 +56,7 @@ def read_weights(


def _parse_coords_and_values(
indata: str | Path | xr.Dataset | dict[str, Any],
indata: Union[str, Path, xr.Dataset, Dict[str, Any]],
n_in: int,
n_out: int,
) -> xr.DataArray:
Expand Down
10 changes: 4 additions & 6 deletions xesmf/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Any, Generator, List, Literal, Tuple
from typing import Any, Generator, List, Literal, Tuple, Union

import numpy as np
import numpy.typing as npt
Expand All @@ -10,9 +10,7 @@
LAT_CF_ATTRS = {'standard_name': 'latitude', 'units': 'degrees_north'}


def _grid_1d(
start_b: float, end_b: float, step: float
) -> tuple[npt.NDArray[np.floating[Any]], npt.NDArray[np.floating[Any]]]:
def _grid_1d(start_b: float, end_b: float, step: float) -> Tuple[npt.NDArray, npt.NDArray]:
"""
1D grid centers and bounds
Expand Down Expand Up @@ -191,7 +189,7 @@ def grid_global(

def _flatten_poly_list(
polys: List[Polygon],
) -> Generator[tuple[int, Any] | tuple[int, Polygon], Any, None]:
) -> Generator[Union[Tuple[int, Any], Tuple[int, Polygon]], Any, None]:
"""Iterator flattening MultiPolygons."""
for i, poly in enumerate(polys):
if isinstance(poly, MultiPolygon):
Expand Down Expand Up @@ -248,7 +246,7 @@ def simple_tripolar_grid(
nlats: int,
lat_cap: float = 60,
lon_cut: float = -300,
) -> tuple[npt.NDArray[np.floating[Any]], npt.NDArray[Any]]:
) -> Tuple[npt.NDArray, npt.NDArray]:
"""Generate a simple tripolar grid, regular under `lat_cap`.
Parameters
Expand Down

0 comments on commit 76ff3f9

Please sign in to comment.