Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions xrspatial/tests/test_zonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,15 @@ def test_stats_return_type_invalid_rejected_for_dataset_2558(
stats(zones=zones, values=ds, return_type='bogus')


def test_stats_empty_dataset_raises_value_error_2637(small_zones_values_2558):
"""An empty Dataset (no data variables) should raise a clear ValueError
instead of leaking an IndexError from the dfs[0] access."""
zones, _ = small_zones_values_2558
empty = xr.Dataset()
with pytest.raises(ValueError, match="no data variables"):
stats(zones=zones, values=empty)


def test_strides_int64_no_overflow_2612():
"""`_strides` must accumulate counts in int64, not int32.

Expand Down
5 changes: 5 additions & 0 deletions xrspatial/zonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,11 @@ def stats(
raise ValueError(
"return_type must be 'pandas.DataFrame' when values is a Dataset"
)
if len(values.data_vars) == 0:
raise ValueError(
"values Dataset has no data variables to compute statistics "
"over. Pass a Dataset with at least one data variable."
)
dfs = []
for var_name in values.data_vars:
df = stats(
Expand Down
Loading