Skip to content

Commit 1411474

Browse files
zequihg50kmuehlbauerpre-commit-ci[bot]
authored
Added driver parameter for h5netcdf (#8360)
* added driver for h5netcdf * Update xarray/backends/h5netcdf_.py Co-authored-by: Kai Mühlbauer <[email protected]> * Update xarray/backends/h5netcdf_.py Co-authored-by: Kai Mühlbauer <[email protected]> * Update xarray/backends/h5netcdf_.py Co-authored-by: Kai Mühlbauer <[email protected]> * Update xarray/backends/h5netcdf_.py Co-authored-by: Kai Mühlbauer <[email protected]> * added test for h5netcdf ros3 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * check h5netcdf 1.3.0 available for test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * updated doc/whats-new.rst --------- Co-authored-by: Kai Mühlbauer <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 59378cc commit 1411474

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ New Features
3030
region to write in the original store. Also implement automatic transpose when dimension
3131
order does not match the original store. (:issue:`7702`, :issue:`8421`, :pull:`8434`).
3232
By `Sam Levang <https://github.com/slevang>`_.
33+
- Allow the usage of h5py drivers (eg: ros3) via h5netcdf (:pull:`8360`).
34+
By `Ezequiel Cimadevilla <https://github.com/zequihg50>`_.
3335

3436
Breaking changes
3537
~~~~~~~~~~~~~~~~

xarray/backends/h5netcdf_.py

+9
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def open(
140140
invalid_netcdf=None,
141141
phony_dims=None,
142142
decode_vlen_strings=True,
143+
driver=None,
144+
driver_kwds=None,
143145
):
144146
import h5netcdf
145147

@@ -161,7 +163,10 @@ def open(
161163
kwargs = {
162164
"invalid_netcdf": invalid_netcdf,
163165
"decode_vlen_strings": decode_vlen_strings,
166+
"driver": driver,
164167
}
168+
if driver_kwds is not None:
169+
kwargs.update(driver_kwds)
165170
if phony_dims is not None:
166171
kwargs["phony_dims"] = phony_dims
167172

@@ -397,6 +402,8 @@ def open_dataset( # type: ignore[override] # allow LSP violation, not supporti
397402
invalid_netcdf=None,
398403
phony_dims=None,
399404
decode_vlen_strings=True,
405+
driver=None,
406+
driver_kwds=None,
400407
) -> Dataset:
401408
filename_or_obj = _normalize_path(filename_or_obj)
402409
store = H5NetCDFStore.open(
@@ -407,6 +414,8 @@ def open_dataset( # type: ignore[override] # allow LSP violation, not supporti
407414
invalid_netcdf=invalid_netcdf,
408415
phony_dims=phony_dims,
409416
decode_vlen_strings=decode_vlen_strings,
417+
driver=driver,
418+
driver_kwds=driver_kwds,
410419
)
411420

412421
store_entrypoint = StoreBackendEntrypoint()

xarray/tests/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ def _importorskip(
9494
requires_pandas_version_two = pytest.mark.skipif(
9595
not has_pandas_version_two, reason="requires pandas 2.0.0"
9696
)
97+
has_h5netcdf_ros3 = _importorskip("h5netcdf", "1.3.0")
98+
requires_h5netcdf_ros3 = pytest.mark.skipif(
99+
not has_h5netcdf_ros3[0], reason="requires h5netcdf 1.3.0"
100+
)
97101

98102
# change some global options for tests
99103
set_options(warn_for_unclosed_files=True)

xarray/tests/test_backends.py

+29
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
requires_dask,
7070
requires_fsspec,
7171
requires_h5netcdf,
72+
requires_h5netcdf_ros3,
7273
requires_iris,
7374
requires_netCDF4,
7475
requires_pydap,
@@ -3448,6 +3449,34 @@ def test_write_inconsistent_chunks(self) -> None:
34483449
assert actual["y"].encoding["chunksizes"] == (100, 50)
34493450

34503451

3452+
@requires_h5netcdf_ros3
3453+
class TestH5NetCDFDataRos3Driver(TestCommon):
3454+
engine: T_NetcdfEngine = "h5netcdf"
3455+
test_remote_dataset: str = (
3456+
"https://www.unidata.ucar.edu/software/netcdf/examples/OMI-Aura_L2-example.nc"
3457+
)
3458+
3459+
def test_get_variable_list(self) -> None:
3460+
with open_dataset(
3461+
self.test_remote_dataset,
3462+
engine="h5netcdf",
3463+
backend_kwargs={"driver": "ros3"},
3464+
) as actual:
3465+
assert "Temperature" in list(actual)
3466+
3467+
def test_get_variable_list_empty_driver_kwds(self) -> None:
3468+
driver_kwds = {
3469+
"secret_id": b"",
3470+
"secret_key": b"",
3471+
}
3472+
backend_kwargs = {"driver": "ros3", "driver_kwds": driver_kwds}
3473+
3474+
with open_dataset(
3475+
self.test_remote_dataset, engine="h5netcdf", backend_kwargs=backend_kwargs
3476+
) as actual:
3477+
assert "Temperature" in list(actual)
3478+
3479+
34513480
@pytest.fixture(params=["scipy", "netcdf4", "h5netcdf", "pynio", "zarr"])
34523481
def readengine(request):
34533482
return request.param

0 commit comments

Comments
 (0)