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 @@ -118,6 +118,8 @@ Bug Fixes
By `Emmanuel Ferdman <https://github.com/emmanuel-ferdman>`_.
- :func:`combine_by_coords` no longer returns an empty dataset when a generator is passed as ``data_objects`` (:issue:`10114`, :pull:`11265`).
By `Amartya Anand <https://github.com/SurfyPenguin>`_.
- Fix h5netcdf backend module detection and ros3 tests (:issue:`11243`, :pull:`11274`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ def ds(self):

def open_store_variable(self, name, var):
import h5netcdf.core
import h5py

dimensions = var.dimensions
data = indexing.LazilyIndexedArray(H5NetCDFArrayWrapper(name, self))
Expand Down Expand Up @@ -306,6 +305,7 @@ def open_store_variable(self, name, var):
encoding["source"] = self._filename
encoding["original_shape"] = data.shape

h5py = var._root._h5py
vlen_dtype = h5py.check_dtype(vlen=var.dtype)
if vlen_dtype is str:
encoding["dtype"] = str
Expand Down
8 changes: 6 additions & 2 deletions xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ def _importorskip_h5netcdf_ros3(has_h5netcdf: bool):
not has_h5netcdf, reason="requires h5netcdf"
)

import h5py
has_h5py, _ = _importorskip("h5py")
if has_h5py:
import h5py

h5py_with_ros3 = h5py.get_config().ros3
h5py_with_ros3 = h5py.get_config().ros3
else:
h5py_with_ros3 = has_h5py

return h5py_with_ros3, pytest.mark.skipif(
not h5py_with_ros3,
Expand Down
27 changes: 22 additions & 5 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5422,29 +5422,46 @@ def test_memoryview_write_netcdf4_read_h5netcdf() -> None:
@requires_h5netcdf_ros3
class TestH5NetCDFDataRos3Driver(TestCommon):
engine: T_NetcdfEngine = "h5netcdf"
test_remote_dataset: str = "https://archive.unidata.ucar.edu/software/netcdf/examples/OMI-Aura_L2-example.nc"
test_remote_dataset: str = "https://dandiarchive.s3.amazonaws.com/ros3test.hdf5"

@property
def ros3_kwargs(self) -> dict:
from h5py import version as h5ver

return (
{} if h5ver.hdf5_version_tuple < (2, 0, 0) else {"aws_region": b"us-east-2"}
)

@pytest.mark.filterwarnings("ignore:Duplicate dimension names")
def test_get_variable_list(self) -> None:
with open_dataset(
self.test_remote_dataset,
engine="h5netcdf",
backend_kwargs={"driver": "ros3"},
backend_kwargs={
"driver": "ros3",
"driver_kwds": self.ros3_kwargs,
"phony_dims": "access",
},
) as actual:
assert "Temperature" in list(actual)
assert "mydataset" in list(actual)

@pytest.mark.filterwarnings("ignore:Duplicate dimension names")
def test_get_variable_list_empty_driver_kwds(self) -> None:
driver_kwds = {
"secret_id": b"",
"secret_key": b"",
}
backend_kwargs = {"driver": "ros3", "driver_kwds": driver_kwds}
driver_kwds.update(self.ros3_kwargs)
backend_kwargs = {
"driver": "ros3",
"driver_kwds": driver_kwds,
"phony_dims": "access",
}

with open_dataset(
self.test_remote_dataset, engine="h5netcdf", backend_kwargs=backend_kwargs
) as actual:
assert "Temperature" in list(actual)
assert "mydataset" in list(actual)


@pytest.fixture(params=["scipy", "netcdf4", "h5netcdf", "zarr"])
Expand Down