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

Preserve lazy nature of Nc4DatasetLike variable data #39

Merged
merged 1 commit into from
Jan 14, 2024
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
2 changes: 1 addition & 1 deletion lib/ncdata/dataset_like.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _maskandscale_inner_to_apparent(self, array):
# N.B. fill-value matches the internal raw (unscaled) values and dtype
fv = self._get_fillvalue()
if fv is not None:
array = np.ma.masked_equal(array, fv)
array = da.ma.masked_equal(array, fv)

is_scaled, scale_factor, add_offset = self._get_scaling()
if is_scaled:
Expand Down
16 changes: 12 additions & 4 deletions tests/integration/example_scripts/ex_iris_xarray_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Showing conversion from Xarray to Iris, and back again.
"""
import iris
import iris.tests as itsts
import dask.array as da
import numpy as np
import xarray as xr

Expand All @@ -27,12 +27,15 @@ def example_from_xr(): # noqa: D103
print("\nCube:")
print(cube)

is_lazy = cube.has_lazy_data()
print("\nCube data still lazy ?", is_lazy)
# It really ought to be!
assert is_lazy

data = cube.core_data()
print("\ncube.core_data():")
print(data)
# match = data is xrds['data'].data
# print('\ncube.core_data() is xrds["data"].data:')
# print(match)

co_auxlons = cube.coord("longitude")
print('\ncube.coord("longitude"):')
print(co_auxlons)
Expand All @@ -47,6 +50,11 @@ def example_from_xr(): # noqa: D103
print("\nxrds2:\n", xrds2)
print("\ntime:\n", xrds2["time"])

is_lazy = isinstance(xrds2["data"].data, da.Array)
print("\nMain data variable still lazy ?", is_lazy)
# It really ought to be!
assert is_lazy

print("\n")
print("============ Array identity checks ... =========")

Expand Down