Skip to content

Commit 052b2a8

Browse files
committed
Fix code review findings in benchmark modules (#1137)
- dasymetric.py: add call parens to has_cuda_and_cupy() guard - reproject.py: move import to module level to keep it out of timed methods
1 parent 568fe2d commit 052b2a8

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

benchmarks/benchmarks/dasymetric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setup(self, nx, type):
2828
zdata = da.from_array(zones_np, chunks=(max(1, ny // 2), max(1, nx // 2)))
2929
elif type == "cupy":
3030
from xrspatial.utils import has_cuda_and_cupy
31-
if not has_cuda_and_cupy:
31+
if not has_cuda_and_cupy():
3232
raise NotImplementedError()
3333
import cupy
3434
zdata = cupy.asarray(zones_np)

benchmarks/benchmarks/reproject.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
import numpy as np
2-
import xarray as xr
3-
41
from .common import get_xr_dataarray
52

6-
7-
def _has_pyproj():
8-
try:
9-
import pyproj # noqa: F401
10-
return True
11-
except ImportError:
12-
return False
3+
try:
4+
from xrspatial.reproject import reproject as _reproject
5+
_HAS_PYPROJ = True
6+
except ImportError:
7+
_HAS_PYPROJ = False
138

149

1510
class Reproject:
1611
params = ([100, 300, 1000], ["numpy", "dask"])
1712
param_names = ("nx", "type")
1813

1914
def setup(self, nx, type):
20-
if not _has_pyproj():
15+
if not _HAS_PYPROJ:
2116
raise NotImplementedError("pyproj required")
2217

2318
ny = nx // 2
@@ -26,9 +21,7 @@ def setup(self, nx, type):
2621
self.xr.attrs["crs"] = "EPSG:4326"
2722

2823
def time_reproject_to_mercator(self, nx, type):
29-
from xrspatial.reproject import reproject
30-
reproject(self.xr, "EPSG:3857")
24+
_reproject(self.xr, "EPSG:3857")
3125

3226
def time_reproject_to_utm(self, nx, type):
33-
from xrspatial.reproject import reproject
34-
reproject(self.xr, "EPSG:32610")
27+
_reproject(self.xr, "EPSG:32610")

0 commit comments

Comments
 (0)