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
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Bug fixes
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- do not cast `_FillValue`/`missing_value` in `CFMaskCoder` if `_Unsigned` is provided
(:issue:`8844`, :pull:`8852`).
- Adapt handling of copy keyword argument in scipy backend for numpy >= 2.0dev
(:issue:`8844`, :pull:`8851`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.

Documentation
Expand Down
10 changes: 10 additions & 0 deletions xarray/backends/scipy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Frozen,
FrozenDict,
close_on_error,
module_available,
try_read_magic_number_from_file_or_path,
)
from xarray.core.variable import Variable
Expand All @@ -39,6 +40,9 @@
from xarray.core.dataset import Dataset


HAS_NUMPY_2_0 = module_available("numpy", minversion="2.0.0.dev0")


def _decode_string(s):
if isinstance(s, bytes):
return s.decode("utf-8", "replace")
Expand Down Expand Up @@ -76,6 +80,12 @@ def __getitem__(self, key):
# with the netCDF4 library by ensuring we can safely read arrays even
# after closing associated files.
copy = self.datastore.ds.use_mmap

# adapt handling of copy-kwarg to numpy 2.0
# see https://github.com/numpy/numpy/issues/25916
# and https://github.com/numpy/numpy/pull/25922
copy = None if HAS_NUMPY_2_0 and copy is False else copy

return np.array(data, dtype=self.dtype, copy=copy)

def __setitem__(self, key, value):
Expand Down