Skip to content

Commit 9644b4b

Browse files
authored
Fix 196 test-suite warnings (#1148) (#1157)
Source fixes: - classify.py: use .item() instead of float() on 0-d dask arrays (NumPy deprecation) - zonal.py: pass numpy array instead of list to _crop/_trim (Numba reflected list deprecation) - preview.py, zonal.py: suppress RuntimeWarning in all-NaN nanmax/nanmin calls - rasterize.py, test_zonal.py: suppress RuntimeWarning for NaN-to-int cast Pytest filters (setup.cfg): - pyproj CRS.to_dict() to_proj4 UserWarning - cost_distance/surface_distance iterative Dijkstra UserWarning - proximity memory-guard ResourceWarning - kriging OptimizeWarning - matplotlib/pyparsing PyparsingDeprecationWarning - pytest_asyncio AbstractEventLoopPolicy DeprecationWarning - Numba NumbaPendingDeprecationWarning
1 parent 10b7f41 commit 9644b4b

File tree

6 files changed

+31
-8
lines changed

6 files changed

+31
-8
lines changed

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ max-line-length = 100
9090
[tool:pytest]
9191
filterwarnings =
9292
ignore::numba.core.errors.NumbaPerformanceWarning
93+
ignore::numba.core.errors.NumbaPendingDeprecationWarning
94+
ignore:You will likely lose important projection information:UserWarning:pyproj
95+
ignore:cost_distance. max_cost is infinite:UserWarning:xrspatial
96+
ignore:surface_distance. max_distance is infinite:UserWarning:xrspatial
97+
ignore:proximity. target coordinates exceed:ResourceWarning:xrspatial
98+
ignore:Covariance of the parameters could not be estimated:scipy.optimize.OptimizeWarning
99+
ignore:'oneOf' deprecated:DeprecationWarning:matplotlib
100+
ignore:'parseString' deprecated:DeprecationWarning:matplotlib
101+
ignore:'resetCache' deprecated:DeprecationWarning:matplotlib
102+
ignore:'enablePackrat' deprecated:DeprecationWarning:matplotlib
103+
ignore:'asyncio.AbstractEventLoopPolicy' is deprecated:DeprecationWarning:pytest_asyncio
93104

94105
[isort]
95106
line_length = 100

xrspatial/classify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ def _run_box_plot(agg, hinge, module):
13821382
q3_l = da.percentile(finite_data, 75)
13831383
max_l = da.nanmax(data_clean)
13841384
q1, q2, q3, max_v = dask.compute(q1_l, q2_l, q3_l, max_l)
1385-
q1, q2, q3, max_v = float(q1), float(q2), float(q3), float(max_v)
1385+
q1, q2, q3, max_v = q1.item(), q2.item(), q3.item(), max_v.item()
13861386
else:
13871387
q1 = float(np.percentile(finite_data, 25))
13881388
q2 = float(np.percentile(finite_data, 50))
@@ -1411,7 +1411,7 @@ def _run_dask_cupy_box_plot(agg, hinge):
14111411
q3_l = da.percentile(finite_data, 75)
14121412
max_l = da.nanmax(data_clean)
14131413
q1, q2, q3, max_v = dask.compute(q1_l, q2_l, q3_l, max_l)
1414-
q1, q2, q3, max_v = float(q1), float(q2), float(q3), float(max_v)
1414+
q1, q2, q3, max_v = q1.item(), q2.item(), q3.item(), max_v.item()
14151415

14161416
iqr = q3 - q1
14171417
raw_bins = [q1 - hinge * iqr, q1, q2, q3, q3 + hinge * iqr, max_v]

xrspatial/preview.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def _is_all_nan(block):
4545
return bool(cupy.isnan(cupy.nanmax(block)))
4646
except ImportError:
4747
pass
48-
with np.errstate(invalid='ignore'):
48+
import warnings
49+
with np.errstate(invalid='ignore'), warnings.catch_warnings():
50+
warnings.simplefilter('ignore', RuntimeWarning)
4951
return bool(np.isnan(np.nanmax(block)))
5052

5153

xrspatial/rasterize.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,10 @@ def _run_numpy(geometries, props_array, bounds, height, width, fill, dtype,
10361036
_burn_points_cpu(out, written, prows, pcols, pt_idx,
10371037
point_props, merge_fn)
10381038

1039-
return out.astype(dtype)
1039+
import warnings
1040+
with warnings.catch_warnings():
1041+
warnings.simplefilter('ignore', RuntimeWarning)
1042+
return out.astype(dtype)
10401043

10411044

10421045
# ---------------------------------------------------------------------------

xrspatial/tests/test_zonal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1871,7 +1871,11 @@ def test_crosstab_gdf(self):
18711871
def test_apply_gdf(self):
18721872
values, gdf, zones_raster = self._zones_raster_and_gdf()
18731873
# rasterize produces float zones; apply needs int zones
1874-
zones_int = zones_raster.copy(data=zones_raster.values.astype(int))
1874+
import warnings
1875+
with warnings.catch_warnings():
1876+
warnings.simplefilter('ignore', RuntimeWarning)
1877+
zones_int = zones_raster.copy(
1878+
data=zones_raster.values.astype(int))
18751879
fn = lambda x: x * 2
18761880
expected = apply(zones_int, values, fn)
18771881
result = apply(gdf, values, fn, column='zone_id',

xrspatial/zonal.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ def _nanreduce_preserve_allnan(blocks, func):
208208
``np.nansum`` returns 0 for all-NaN input; we want NaN so that zones
209209
with no valid values propagate NaN, consistent with the numpy backend.
210210
"""
211-
result = func(blocks, axis=0)
211+
import warnings
212+
with warnings.catch_warnings():
213+
warnings.simplefilter('ignore', RuntimeWarning)
214+
result = func(blocks, axis=0)
212215
all_nan = np.all(np.isnan(blocks), axis=0)
213216
result[all_nan] = np.nan
214217
return result
@@ -2217,7 +2220,7 @@ def trim(
22172220
else:
22182221
if is_cupy_array(data):
22192222
data = data.get()
2220-
top, bottom, left, right = _trim(data, values)
2223+
top, bottom, left, right = _trim(data, np.asarray(values))
22212224

22222225
arr = raster[top: bottom + 1, left: right + 1]
22232226
arr.name = name
@@ -2493,7 +2496,7 @@ def crop(
24932496
else:
24942497
if is_cupy_array(data):
24952498
data = data.get()
2496-
top, bottom, left, right = _crop(data, zones_ids)
2499+
top, bottom, left, right = _crop(data, np.asarray(zones_ids))
24972500

24982501
arr = values[top: bottom + 1, left: right + 1]
24992502
arr.name = name

0 commit comments

Comments
 (0)