Skip to content

Commit

Permalink
Expand user dir paths (~) in open_mfdataset and to_zarr. (#4795)
Browse files Browse the repository at this point in the history
* Normalize wildcard paths in open_mfdataset.

* Document normalized mfdataset paths in what's new.

* Also normalize paths in to_zarr.
  • Loading branch information
juseg authored Jan 15, 2021
1 parent 800ccb3 commit 84df75d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Bug fixes
- Add ``missing_dims`` parameter to transpose (:issue:`4647`, :pull:`4767`). By `Daniel Mesejo <https://github.com/mesejo>`_.
- Resolve intervals before appending other metadata to labels when plotting (:issue:`4322`, :pull:`4794`).
By `Justus Magin <https://github.com/keewis>`_.
- Expand user directory paths (e.g. ``~/``) in :py:func:`open_mfdataset` and
:py:meth:`Dataset.to_zarr` (:issue:`4783`, :pull:`4795`).
By `Julien Seguinot <https://github.com/juseg>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
14 changes: 6 additions & 8 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def open_mfdataset(
paths
)
)
paths = sorted(glob(paths))
paths = sorted(glob(_normalize_path(paths)))
else:
paths = [str(p) if isinstance(p, Path) else p for p in paths]

Expand Down Expand Up @@ -1386,10 +1386,11 @@ def to_zarr(
See `Dataset.to_zarr` for full API docs.
"""
if isinstance(store, Path):
store = str(store)
if isinstance(chunk_store, Path):
chunk_store = str(store)

# expand str and Path arguments
store = _normalize_path(store)
chunk_store = _normalize_path(chunk_store)

if encoding is None:
encoding = {}

Expand Down Expand Up @@ -1419,9 +1420,6 @@ def to_zarr(
"compute=False before writing data."
)

if isinstance(store, Path):
store = str(store)

# validate Dataset keys, DataArray names, and attr keys/values
_validate_dataset_names(dataset)
_validate_attrs(dataset)
Expand Down

0 comments on commit 84df75d

Please sign in to comment.