From e378dbc0553dc84c953550fa678028c6299a330f Mon Sep 17 00:00:00 2001 From: Julien Seguinot Date: Tue, 12 Jan 2021 08:17:32 +0100 Subject: [PATCH 1/3] Normalize wildcard paths in open_mfdataset. --- xarray/backends/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/backends/api.py b/xarray/backends/api.py index faa7e6cf3d3..637cb11ba1a 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -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] From 32bf3c5d10b6d1f6b0fb4859a4e96b13b6379d73 Mon Sep 17 00:00:00 2001 From: Julien Seguinot Date: Tue, 12 Jan 2021 08:44:09 +0100 Subject: [PATCH 2/3] Document normalized mfdataset paths in what's new. --- doc/whats-new.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c969453b108..5d2047d8283 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -68,6 +68,9 @@ Bug fixes By `Alessandro Amici `_ - Limit number of data rows when printing large datasets. (:issue:`4736`, :pull:`4750`). By `Jimmy Westling `_. - Add ``missing_dims`` parameter to transpose (:issue:`4647`, :pull:`4767`). By `Daniel Mesejo `_. +- Expand user directory paths (for instance ``~/`` on unix) in + :py:func:`open_mfdataset` (:issue:`4783`, :pull:`4795`). + By `Julien Seguinot `_. Documentation ~~~~~~~~~~~~~ From 34ffcc365e64f49364dcbeeaf0efd35cba7f116e Mon Sep 17 00:00:00 2001 From: Julien Seguinot Date: Thu, 14 Jan 2021 07:26:48 +0100 Subject: [PATCH 3/3] Also normalize paths in to_zarr. --- doc/whats-new.rst | 6 +++--- xarray/backends/api.py | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 4c24a7f7931..51b16d65a62 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -73,11 +73,11 @@ Bug fixes (:issue:`2658` and :issue:`4543`) by `Mathias Hauser `_. - Limit number of data rows when printing large datasets. (:issue:`4736`, :pull:`4750`). By `Jimmy Westling `_. - Add ``missing_dims`` parameter to transpose (:issue:`4647`, :pull:`4767`). By `Daniel Mesejo `_. -- Expand user directory paths (for instance ``~/`` on unix) in - :py:func:`open_mfdataset` (:issue:`4783`, :pull:`4795`). - By `Julien Seguinot `_. - Resolve intervals before appending other metadata to labels when plotting (:issue:`4322`, :pull:`4794`). By `Justus Magin `_. +- Expand user directory paths (e.g. ``~/``) in :py:func:`open_mfdataset` and + :py:meth:`Dataset.to_zarr` (:issue:`4783`, :pull:`4795`). + By `Julien Seguinot `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 637cb11ba1a..4958062a262 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -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 = {} @@ -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)