Skip to content

Commit

Permalink
update tests for empty datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
sliu008 committed Jul 1, 2024
1 parent 086e9fb commit 20e0eee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion podaac/subsetter/xarray_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def copy_empty_dataset(dataset: xr.Dataset) -> xr.Dataset:
# Create a dict object where each key is a variable in the dataset and the value is an
# array initialized to the fill value for that variable or NaN if there is no fill value
# attribute for the variable
print("COPy EMPTY Dataset")

empty_data = {k: np.full(v.shape, dataset.variables[k].attrs.get('_FillValue', np.nan), dtype=v.dtype) for k, v in dataset.items()}

# Create a copy of the dataset filled with the empty data. Then select the first index along each
Expand Down
8 changes: 7 additions & 1 deletion tests/test_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ def test_subset_empty_bbox(test_file, data_dir, subset_output_dir, request):

# Ensure all variables are present but empty.
for _, variable in empty_dataset.data_vars.items():
assert np.all(variable.data == variable.attrs.get('_FillValue', np.nan) or np.isnan(variable.data))
try:
assert np.all(variable.data == variable.attrs.get('_FillValue', np.nan) or np.isnan(variable.data))
except Exception as ex:
# if there is no fill value and type is integer then don't raise exception
fill_value = variable.attrs.get('_FillValue', np.nan)
if not (np.isnan(fill_value) and np.issubdtype(variable.dtype, np.integer)):
raise(ex)

assert test_input_dataset.dims.keys() == empty_dataset.dims.keys()

Expand Down

0 comments on commit 20e0eee

Please sign in to comment.