Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ensure fsspec storage options are propagated to xr.open_dataset #453

Merged
merged 7 commits into from
Mar 11, 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
1 change: 0 additions & 1 deletion intake_esm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ def to_dataset_dict(
xarray_open_kwargs=xarray_open_kwargs,
xarray_combine_by_coords_kwargs=xarray_combine_by_coords_kwargs,
preprocess=preprocess,
storage_options=storage_options,
requested_variables=self._requested_variables,
)

Expand Down
6 changes: 3 additions & 3 deletions intake_esm/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ESMDataSourceError(Exception):
pass


def _get_xarray_open_kwargs(data_format, xarray_open_kwargs=None):
def _get_xarray_open_kwargs(data_format, xarray_open_kwargs=None, storage_options=None):
xarray_open_kwargs = (xarray_open_kwargs or {}).copy()
_default_open_kwargs = {
'engine': 'zarr' if data_format == 'zarr' else 'netcdf4',
Expand All @@ -30,7 +30,7 @@ def _get_xarray_open_kwargs(data_format, xarray_open_kwargs=None):
xarray_open_kwargs['engine'] == 'zarr'
and 'storage_options' not in xarray_open_kwargs['backend_kwargs']
):
xarray_open_kwargs['backend_kwargs']['storage_options'] = {}
xarray_open_kwargs['backend_kwargs']['storage_options'] = {} or storage_options
return xarray_open_kwargs


Expand Down Expand Up @@ -209,7 +209,7 @@ def _open_dataset(self):
record[self.path_column_name],
record[self.variable_column_name],
xarray_open_kwargs=_get_xarray_open_kwargs(
record['_data_format_'], self.xarray_open_kwargs
record['_data_format_'], self.xarray_open_kwargs, self.storage_options
),
preprocess=self.preprocess,
expand_dims={
Expand Down
6 changes: 6 additions & 0 deletions tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ def test_open_dataset(fpath, expected_time_size):
ds = _common_open(fpath)
assert isinstance(ds, xarray.Dataset)
assert len(ds.time) == expected_time_size


@pytest.mark.parametrize('storage_options', [{'anon': True}, {}])
def test_get_xarray_open_kwargs(storage_options):
xarray_open_kwargs = _get_xarray_open_kwargs('zarr', storage_options=storage_options)
assert xarray_open_kwargs['backend_kwargs']['storage_options'] == storage_options