diff --git a/.gitignore b/.gitignore index a22ac7f..1d42d73 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ htmlcov dist .direnv +.venv diff --git a/tests/test_xstac.py b/tests/test_xstac.py index c806611..096c8d8 100644 --- a/tests/test_xstac.py +++ b/tests/test_xstac.py @@ -1,3 +1,4 @@ +import json import pyproj import pytest import pystac @@ -164,3 +165,10 @@ def test_disable_infer_temporal_extent(ds, item_template): # del item_template["properties"]["datetime"] result = xarray_to_stac(ds, item_template, temporal_dimension=False) assert "start_datetime" not in result.properties + + +def test_fixup_numpy_attrs_by_default(ds, item_template): + ds.prcp.attrs["values"] = np.zeros(2) + result = xarray_to_stac(ds, item_template, temporal_dimension=False) + assert result.properties["cube:variables"]["prcp"]["attrs"]["values"] == [0.0, 0.0] + json.dumps(result.to_dict()) diff --git a/xstac/_xstac.py b/xstac/_xstac.py index 91cfcd0..f9ce280 100644 --- a/xstac/_xstac.py +++ b/xstac/_xstac.py @@ -339,6 +339,8 @@ def xarray_to_stac( **additional_dimensions: A dictionary with keys ``extent``, ``values``, ``step``. """ + ds = fix_attrs(ds) + temporal_dimension = maybe_use_cf_standard_axis( temporal_dimension, "temporal_dimension", ds )