Skip to content

Commit 836681a

Browse files
author
Taher Chegini
committed
MNT: Rename types based on python's convention. [skip ci]
1 parent e3c9479 commit 836681a

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/pygeoutils/pygeoutils.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@
3636
)
3737

3838
BOX_ORD = "(west, south, east, north)"
39-
NUMBER = Union[int, float, np.number] # pyright: ignore[reportMissingTypeArgument]
4039
if TYPE_CHECKING:
4140
from collections.abc import Generator, Iterable
4241

4342
from numpy.typing import NDArray
43+
from pyproj import CRS
4444
from rasterio.io import DatasetReader
4545

46-
GTYPE = Union[Polygon, MultiPolygon, tuple[float, float, float, float]]
47-
GDFTYPE = TypeVar("GDFTYPE", gpd.GeoDataFrame, gpd.GeoSeries)
48-
XD = TypeVar("XD", xr.Dataset, xr.DataArray)
49-
CRSTYPE = Union[int, str, pyproj.CRS]
50-
51-
FloatArray = NDArray[np.float64]
46+
CRSType = int | str | CRS
47+
GeoType = Polygon | MultiPolygon | tuple[float, float, float, float]
48+
GeoDFType = TypeVar("GeoDFType", gpd.GeoDataFrame, gpd.GeoSeries)
49+
DataArray = TypeVar("DataArray", xr.Dataset, xr.DataArray)
50+
Number = Union[int, float, np.number] # pyright: ignore[reportMissingTypeArgument]
5251

5352
__all__ = [
5453
"arcgis2geojson",
@@ -103,8 +102,8 @@ def _gdf_from_features(
103102

104103
def json2geodf(
105104
content: list[dict[str, Any]] | dict[str, Any],
106-
in_crs: CRSTYPE | None = 4326,
107-
crs: CRSTYPE | None = 4326,
105+
in_crs: CRSType | None = 4326,
106+
crs: CRSType | None = 4326,
108107
) -> gpd.GeoDataFrame:
109108
"""Create GeoDataFrame from (Geo)JSON.
110109
@@ -153,13 +152,13 @@ def json2geodf(
153152

154153

155154
def xarray_geomask(
156-
ds: XD,
157-
geometry: GTYPE,
158-
crs: CRSTYPE,
155+
ds: DataArray,
156+
geometry: GeoType,
157+
crs: CRSType,
159158
all_touched: bool = False,
160159
drop: bool = True,
161160
from_disk: bool = False,
162-
) -> XD:
161+
) -> DataArray:
163162
"""Mask a ``xarray.Dataset`` based on a geometry.
164163
165164
Parameters
@@ -217,8 +216,8 @@ def _to_dataset(
217216
var_name: str,
218217
driver: str | None,
219218
dtypes: dict[str, np.dtype], # pyright: ignore[reportMissingTypeArgument]
220-
nodata_dict: dict[str, NUMBER],
221-
nodata: NUMBER | None,
219+
nodata_dict: dict[str, Number],
220+
nodata: Number | None,
222221
) -> xr.DataArray:
223222
with MemoryFile() as memfile:
224223
memfile.write(resp)
@@ -236,12 +235,12 @@ def _to_dataset(
236235

237236
def gtiff2xarray(
238237
r_dict: dict[str, bytes],
239-
geometry: GTYPE | None = None,
240-
geo_crs: CRSTYPE | None = None,
238+
geometry: GeoType | None = None,
239+
geo_crs: CRSType | None = None,
241240
ds_dims: tuple[str, str] | None = None,
242241
driver: str | None = None,
243242
all_touched: bool = False,
244-
nodata: NUMBER | None = None,
243+
nodata: Number | None = None,
245244
drop: bool = True,
246245
) -> xr.DataArray | xr.Dataset:
247246
"""Convert (Geo)Tiff byte responses to ``xarray.Dataset``.
@@ -296,7 +295,7 @@ def gtiff2xarray(
296295

297296
attrs = utils.get_gtiff_attrs(r_dict[key1], ds_dims, driver, nodata)
298297
dtypes: dict[str, np.dtype] = {} # pyright: ignore[reportMissingTypeArgument]
299-
nodata_dict: dict[str, NUMBER] = {}
298+
nodata_dict: dict[str, Number] = {}
300299

301300
ds = xr.merge(
302301
_to_dataset(resp, var_name[lyr], driver, dtypes, nodata_dict, nodata)
@@ -421,11 +420,11 @@ def xarray2geodf(
421420

422421

423422
def geodf2xarray(
424-
geodf: GDFTYPE,
423+
geodf: GeoDFType,
425424
resolution: float,
426425
attr_col: str | None = None,
427426
fill: float = 0,
428-
projected_crs: CRSTYPE = 5070,
427+
projected_crs: CRSType = 5070,
429428
) -> xr.Dataset:
430429
"""Rasterize a ``geopandas.GeoDataFrame`` to ``xarray.DataArray``.
431430
@@ -521,7 +520,7 @@ def sample_window(
521520
indexes: int | list[int] | None = None,
522521
masked: bool = False,
523522
resampling: int = 1,
524-
) -> Generator[FloatArray, None, None]:
523+
) -> Generator[NDArray[np.float64], None, None]:
525524
"""Interpolate pixel values at given coordinates by interpolation.
526525
527526
.. note::

src/pygeoutils/smoothing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import warnings
66
from dataclasses import dataclass
7-
from typing import TYPE_CHECKING, TypeVar, Union, cast
7+
from typing import TYPE_CHECKING, TypeVar, cast
88

99
import numpy as np
1010
import scipy.interpolate as sci
@@ -21,11 +21,11 @@
2121

2222
if TYPE_CHECKING:
2323
import geopandas as gpd
24-
import pyproj
2524
from numpy.typing import NDArray
25+
from pyproj import CRS
2626

27-
GDFTYPE = TypeVar("GDFTYPE", gpd.GeoDataFrame, gpd.GeoSeries)
28-
CRSTYPE = Union[int, str, pyproj.CRS]
27+
CRSType = int | str | CRS
28+
GeoDFType = TypeVar("GeoDFType", gpd.GeoDataFrame, gpd.GeoSeries)
2929
FloatArray = NDArray[np.floating]
3030

3131
__all__ = [
@@ -303,7 +303,7 @@ class GeoSpline:
303303

304304
def __init__(
305305
self,
306-
points: GDFTYPE | NDArray[Point], # pyright: ignore[reportInvalidTypeForm]
306+
points: GeoDFType | NDArray[Point], # pyright: ignore[reportInvalidTypeForm]
307307
n_pts: int,
308308
degree: int = 3,
309309
smoothing: float | None = None,

0 commit comments

Comments
 (0)