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
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"orcid": "https://orcid.org/0000-0002-6799-9109",
"affiliation": "Bureau of Meteorology, Australia",
"name": "Holmes, Ryan"
},
{
"orcid": "https://orcid.org/0009-0001-4486-0120",
"affiliation": "Independent researcher, Vietnam",
"name": "Bogacheva, Jenya"
}


Expand Down
33 changes: 16 additions & 17 deletions packages/utils/tests/data/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,36 @@

from pyearthtools.utils.data import converter

SIMPLE_DATA_ARRAY = xr.DataArray([1, 2, 3, 4, 5])
SIMPLE_DATA_ARRAY = xr.DataArray([1, 2, 3, 4, 5], dims=("x",), coords={"x": [0, 1, 2, 3, 4]}, name="Entry")
SIMPLE_DATA_SET = xr.Dataset({"Entry": SIMPLE_DATA_ARRAY})


def test_NumpyConverter():
"""
This test provides coverage, but does not test for
correctness
Checks conversion from xarray to numpy and back
"""

# This round-trips convert and unconvert
nc = converter.NumpyConverter()
_np_array1 = nc.convert_from_xarray(SIMPLE_DATA_ARRAY)

# FIXME
# xr_da1 = nc.convert_to_xarray(np_array1)
nc_da = converter.NumpyConverter()
_ = nc_da.convert_from_xarray(SIMPLE_DATA_ARRAY)

# Test conversion from xarray works
nc = converter.NumpyConverter()
_np_array2 = nc.convert_from_xarray(SIMPLE_DATA_SET)
np_array = nc.convert_from_xarray(SIMPLE_DATA_SET)
xr_ds = nc.convert_to_xarray(np_array)
assert isinstance(xr_ds, xr.Dataset)
assert "Entry" in xr_ds
xr.testing.assert_identical(xr_ds["Entry"], SIMPLE_DATA_ARRAY)


def test_DaskConverter():
"""
This test provides coverage, but does not test for
correctness
Checks conversion from xarray to dask and back
"""

dc = converter.DaskConverter()

_da_array1 = dc.convert_from_xarray(SIMPLE_DATA_ARRAY)

# FIXME
# xr_da1 = dc.convert_to_xarray(da_array1)
da_array = dc.convert_from_xarray(SIMPLE_DATA_SET)
da_array = da_array.compute()
xr_ds = dc.convert_to_xarray(da_array)
assert isinstance(xr_ds, xr.Dataset)
assert "Entry" in xr_ds
xr.testing.assert_identical(xr_ds["Entry"], SIMPLE_DATA_ARRAY)