Skip to content

Commit 8291144

Browse files
authored
Merge pull request #95 from csiro-coasts/remove-shorthand-imports
Remove shorthand imports
2 parents b3df998 + b700fac commit 8291144

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1054
-1047
lines changed

docs/developing/grass.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from functools import cached_property
44
from typing import Optional, Tuple, Dict
55

6-
import numpy as np
7-
import xarray as xr
6+
import numpy
7+
import xarray
88
from shapely.geometry import Polygon
99
from shapely.geometry.base import BaseGeometry
1010

@@ -32,7 +32,7 @@ class Grass(Convention[GrassGridKind, GrassIndex]):
3232
default_grid_kind = GrassGridKind.blade
3333

3434
@classmethod
35-
def check_dataset(cls, dataset: xr.Dataset) -> Optional[int]:
35+
def check_dataset(cls, dataset: xarray.Dataset) -> Optional[int]:
3636
# A Grass dataset is recognised by the 'Conventions' global attribute
3737
if dataset.attrs['Conventions'] == 'Grass 1.0':
3838
return Specificity.HIGH
@@ -61,7 +61,7 @@ def unravel_index(
6161
return (grid_kind, warp, weft)
6262

6363
def get_grid_kind_and_size(
64-
self, data_array: xr.DataArray,
64+
self, data_array: xarray.DataArray,
6565
) -> Tuple[GrassGridKind, int]:
6666
"""
6767
For the given DataArray from this Dataset,
@@ -75,7 +75,7 @@ def get_grid_kind_and_size(
7575
raise ValueError(
7676
"DataArray does not appear to be either a blade or meadow grid")
7777

78-
def make_linear(self, data_array: xr.DataArray) -> xr.DataArray:
78+
def make_linear(self, data_array: xarray.DataArray) -> xarray.DataArray:
7979
"""
8080
Make the given DataArray linear in its grid dimensions.
8181
"""
@@ -95,12 +95,12 @@ def selector_for_index(self, index: GrassIndex) -> Dict[str, int]:
9595
return {'warp': warp, 'weft': weft}
9696

9797
@cached_property
98-
def polygons(self) -> np.ndarray:
98+
def polygons(self) -> numpy.ndarray:
9999
def make_polygon_for_cell(warp: int, weft: int) -> Polygon:
100100
# Implementation left as an exercise for the reader
101101
return Polygon(...)
102102

103-
return np.array([
103+
return numpy.array([
104104
make_polygon_for_cell(warp, weft)
105105
for warp in range(self.dataset.dimensions['warp'])
106106
for weft in range(self.dataset.dimensions['weft'])
@@ -110,7 +110,7 @@ def make_clip_mask(
110110
self,
111111
clip_geometry: BaseGeometry,
112112
buffer: int = 0,
113-
) -> xr.Dataset:
113+
) -> xarray.Dataset:
114114
# Find all the blades that intersect the clip geometry
115115
intersecting_blades = [
116116
item
@@ -143,14 +143,14 @@ def make_clip_mask(
143143
keep_meadows = blur_mask(keep_meadows, size=buffer)
144144

145145
# Make a dataset out of these masks
146-
return xr.Dataset(
146+
return xarray.Dataset(
147147
data_vars={
148-
'blades': xr.DataArray(data=keep_blades, dims=['weft', 'warp']),
149-
'meadows': xr.DataArray(data=keep_meadows, dims=['warp', 'weft']),
148+
'blades': xarray.DataArray(data=keep_blades, dims=['weft', 'warp']),
149+
'meadows': xarray.DataArray(data=keep_meadows, dims=['warp', 'weft']),
150150
},
151151
)
152152

153-
def apply_clip_mask(self, clip_mask: xr.Dataset, work_dir: Pathish) -> xr.Dataset:
153+
def apply_clip_mask(self, clip_mask: xarray.Dataset, work_dir: Pathish) -> xarray.Dataset:
154154
# You're on your own, here.
155155
# This depends entirely on how the mask and datasets interact.
156156
pass

docs/developing/sea_surface_temperature.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pathlib
55

66
import emsarray
7-
import xarray as xr
7+
import xarray
88
from emsarray.cli import console_entrypoint
99
from emsarray.cli.utils import geometry_argument
1010
from shapely.geometry.base import BaseGeometry
@@ -64,8 +64,8 @@ def main(options: argparse.Namespace) -> None:
6464

6565

6666
def calculate_mean_sea_surface_temperature(
67-
dataset: xr.Dataset,
68-
temperature: xr.DataArray,
67+
dataset: xarray.Dataset,
68+
temperature: xarray.DataArray,
6969
geometry: BaseGeometry,
7070
) -> float:
7171
"""

docs/releases/development.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ Next release (in development)
1717
* Fix various small issues with the docs.
1818
Use newer version of ``sphinx-book-theme`` for documentation
1919
(:pr:`91`).
20+
* Remove shorthand imports such as ``import xarray as xr``
21+
(:pr:`95`).

src/emsarray/accessors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import logging
44

5-
import xarray as xr
5+
import xarray
66

77
from .conventions import Convention, get_dataset_convention
88
from .state import State
99

1010
logger = logging.getLogger(__name__)
1111

1212

13-
@xr.register_dataset_accessor("ems")
14-
def ems_accessor(dataset: xr.Dataset) -> Convention:
13+
@xarray.register_dataset_accessor("ems")
14+
def ems_accessor(dataset: xarray.Dataset) -> Convention:
1515
"""Provides the ``.ems`` attribute on xarray Datasets.
1616
This will make a :class:`~emsarray.conventions.Convention` instance for the dataset,
1717
using the correct :class:`~emsarray.conventions.Convention` subclass depending on the file type.
@@ -33,4 +33,4 @@ def ems_accessor(dataset: xr.Dataset) -> Convention:
3333
return convention
3434

3535

36-
xr.register_dataset_accessor(State.accessor_name)(State)
36+
xarray.register_dataset_accessor(State.accessor_name)(State)

src/emsarray/cli/commands/export_geometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import Callable, Dict
55

6-
import xarray as xr
6+
import xarray
77

88
import emsarray
99
from emsarray.cli import BaseCommand, CommandException
@@ -12,7 +12,7 @@
1212

1313
logger = logging.getLogger(__name__)
1414

15-
Writer = Callable[[xr.Dataset, Pathish], None]
15+
Writer = Callable[[xarray.Dataset, Pathish], None]
1616
format_writers: Dict[str, Writer] = {
1717
'geojson': geometry.write_geojson,
1818
'shapefile': geometry.write_shapefile,

src/emsarray/cli/commands/extract_points.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from pathlib import Path
44

5-
import pandas as pd
5+
import pandas
66

77
import emsarray
88
from emsarray.cli import BaseCommand, CommandException
@@ -64,7 +64,7 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
6464
def handle(self, options: argparse.Namespace) -> None:
6565
logger.info("Extracting points from %r", str(options.input_path))
6666
dataset = emsarray.open_dataset(options.input_path)
67-
dataframe = pd.read_csv(options.points)
67+
dataframe = pandas.read_csv(options.points)
6868

6969
try:
7070
point_data = point_extraction.extract_dataframe(

src/emsarray/compat/shapely.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22
from typing import Generic, Iterable, Tuple, TypeVar, Union, cast
33

4-
import numpy as np
4+
import numpy
55
import shapely
66
from packaging.version import parse
77
from shapely.errors import ShapelyDeprecationWarning
@@ -23,16 +23,16 @@ class SpatialIndex(Generic[T]):
2323
This also handles the version differences in STRtree between
2424
shapely ~= 1.8.x and shapely >= 2.0.0
2525
"""
26-
items: np.ndarray
26+
items: numpy.ndarray
2727
index: STRtree
2828

29-
dtype: np.dtype = np.dtype([('geom', np.object_), ('data', np.object_)])
29+
dtype: numpy.dtype = numpy.dtype([('geom', numpy.object_), ('data', numpy.object_)])
3030

3131
def __init__(
3232
self,
33-
items: Union[np.ndarray, Iterable[Tuple[BaseGeometry, T]]],
33+
items: Union[numpy.ndarray, Iterable[Tuple[BaseGeometry, T]]],
3434
):
35-
self.items = np.array(items, dtype=self.dtype)
35+
self.items = numpy.array(items, dtype=self.dtype)
3636

3737
if shapely_version >= v2:
3838
self.index = STRtree(self.items['geom'])
@@ -46,19 +46,19 @@ def __init__(
4646
def query(
4747
self,
4848
geom: BaseGeometry,
49-
) -> np.ndarray:
49+
) -> numpy.ndarray:
5050
if shapely_version >= v2:
5151
indices = self.index.query(geom)
5252
else:
5353
indices = self.index._query(geom)
54-
return cast(np.ndarray, self.items.take(indices))
54+
return cast(numpy.ndarray, self.items.take(indices))
5555

5656
def nearest(
5757
self,
5858
geom: BaseGeometry,
59-
) -> np.ndarray:
59+
) -> numpy.ndarray:
6060
if shapely_version >= v2:
6161
indices = self.index.nearest(geom)
6262
else:
6363
indices = self.index._nearest(geom)
64-
return cast(np.ndarray, self.items.take(indices))
64+
return cast(numpy.ndarray, self.items.take(indices))

0 commit comments

Comments
 (0)