Description
focal_stats() doesn't validate stats_funcs before it dispatches to a backend, so two bad inputs fail in confusing ways:
- An unknown stat name (e.g.
stats_funcs=['mena']) falls through to a backend mapper dict lookup and surfaces as a bare KeyError. Nothing tells you which names are valid.
- A bare string instead of a list (e.g.
stats_funcs='mean') gets iterated character by character, so the first lookup is for 'm' and it dies there.
The dispatch happens around xrspatial/focal.py:1115 in _focal_stats_cpu and the other backend helpers.
Expected behavior
Validate stats_funcs up front, before dispatch:
- An unknown stat name raises a
ValueError that lists the valid options.
- A bare string is accepted as a single stat name (wrapped into a one-element list).
Steps to reproduce
import numpy as np, xarray as xr
from xrspatial.convolution import circle_kernel
from xrspatial.focal import focal_stats
agg = xr.DataArray(np.ones((5, 5), dtype=float))
kernel = circle_kernel(1, 1, 1)
focal_stats(agg, kernel, stats_funcs=['mena']) # raw KeyError
focal_stats(agg, kernel, stats_funcs='mean') # KeyError on 'm'
Description
focal_stats()doesn't validatestats_funcsbefore it dispatches to a backend, so two bad inputs fail in confusing ways:stats_funcs=['mena']) falls through to a backend mapper dict lookup and surfaces as a bareKeyError. Nothing tells you which names are valid.stats_funcs='mean') gets iterated character by character, so the first lookup is for'm'and it dies there.The dispatch happens around
xrspatial/focal.py:1115in_focal_stats_cpuand the other backend helpers.Expected behavior
Validate
stats_funcsup front, before dispatch:ValueErrorthat lists the valid options.Steps to reproduce