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

dask: Data.filled #340

Merged
merged 1 commit into from
Mar 10, 2022
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
19 changes: 6 additions & 13 deletions cf/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9815,9 +9815,10 @@ def soften_mask(self):
self._map_blocks(cf_soften_mask, dtype=self.dtype)
self._hardmask = False

@daskified(_DASKIFIED_VERBOSE)
@_inplace_enabled(default=False)
def filled(self, fill_value=None, inplace=False):
"""Replace masked elements with the fill value.
"""Replace masked elements with a fill value.

.. versionadded:: 3.4.0

Expand Down Expand Up @@ -9854,25 +9855,17 @@ def filled(self, fill_value=None, inplace=False):
if fill_value is None:
fill_value = d.get_fill_value(None)
if fill_value is None: # still...
fill_value = default_netCDF_fillvals().get(
d.dtype.str[1:], None
)
fill_value = default_netCDF_fillvals().get(d.dtype.str[1:])
if fill_value is None and d.dtype.kind in ("SU"):
fill_value = default_netCDF_fillvals().get("S1", None)

if fill_value is None: # should not be None by this stage
if fill_value is None:
raise ValueError(
"Can't determine fill value for "
"data type {!r}".format(d.dtype.str)
f"data type {d.dtype.str!r}"
)
# --- End: if

hardmask = d.hardmask
d.hardmask = False

d.where(d.mask, fill_value, inplace=True)

d.hardmask = hardmask
d._map_blocks(np.ma.filled, fill_value=fill_value, dtype=d.dtype)

return d

Expand Down
3 changes: 0 additions & 3 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3628,9 +3628,6 @@ def test_Data_trigonometric_hyperbolic(self):
# self.assertTrue((e.array == c).all())
# self.assertTrue((d1.mask.array == c.mask).all())

@unittest.skipIf(
TEST_DASKIFIED_ONLY, "hits 'TODODASK - use harden_mask/soften_mask'"
)
def test_Data_filled(self):
if self.test_only and inspect.stack()[0][3] not in self.test_only:
return
Expand Down