Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup attrs #40

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
htmlcov
dist
.direnv
.venv
10 changes: 10 additions & 0 deletions tests/test_xstac.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,13 @@ 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]
try:
import json
json.dumps(result.to_dict())
except Exception:
pytest.fail("Failed to serialize to JSON")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the JSON import to the top and then just do json.dumps(result.to_dict()) in the test? No need to catch the exception. An unhandled one will cause the test to fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

2 changes: 2 additions & 0 deletions xstac/_xstac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Loading