Skip to content

Commit c46a97a

Browse files
committed
Optimize mask_and_scale decoder.
Previously we would make two copies of the data in many cases. Now we always make one copy.
1 parent a24c8c7 commit c46a97a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ ban-relative-imports = "all"
305305
"pandas.api.types.is_extension_array_dtype".msg = "Use xarray.core.utils.is_allowed_extension_array{_dtype} instead. Only use the banend API if the incoming data has already been sanitized by xarray"
306306

307307
[tool.pytest.ini_options]
308+
asyncio_default_fixture_loop_scope = "function"
308309
addopts = [
309310
"--strict-config",
310311
"--strict-markers",

xarray/coding/variables.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ def _apply_mask(
125125
dtype: np.typing.DTypeLike | None,
126126
) -> np.ndarray:
127127
"""Mask all matching values in a NumPy arrays."""
128-
data = np.asarray(data, dtype=dtype)
129-
condition = False
130-
for fv in encoded_fill_values:
131-
condition |= data == fv
132-
return np.where(condition, decoded_fill_value, data)
128+
data = np.asarray(data, dtype=dtype, copy=True)
129+
if encoded_fill_values:
130+
condition = False
131+
for fv in encoded_fill_values:
132+
condition |= data == fv
133+
data[condition] = decoded_fill_value
134+
return data
133135

134136

135137
def _is_time_like(units):

0 commit comments

Comments
 (0)