Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

User directories (~) not expanded by open_mfdataset(). #4783

Closed
juseg opened this issue Jan 8, 2021 · 0 comments · Fixed by #4795
Closed

User directories (~) not expanded by open_mfdataset(). #4783

juseg opened this issue Jan 8, 2021 · 0 comments · Fixed by #4795

Comments

@juseg
Copy link
Contributor

juseg commented Jan 8, 2021

What happened:

Hi. Perhaps a trivially minor issue, but I have noticed that open_dataset and to_netcdf expand user directories (~), while open_mfdataset does so on file lists, but not on patterns or single files.

What you expected to happen:

I would expect consistent behaviour across all file reading and writing methods.

Minimal Complete Verifiable Example:

>>> import xarray as xr
>>> xr.Dataset().to_netcdf('~/dataset.nc')  # works
>>> xr.open_dataset('~/dataset.nc')         # works
>>> xr.open_mfdataset(['~/dataset.nc'])     # works
>>> xr.open_mfdataset('~/dataset.nc')       # error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/xarray/backends/api.py", line 891, in open_mfdataset
    raise OSError("no files to open")
OSError: no files to open

Anything else we need to know?:

This is done by private method _normalize_paths, which is called in open_dataset and to_netcdf but not open_mfdataset.

def _normalize_path(path):
if isinstance(path, Path):
path = str(path)
if isinstance(path, str) and not is_remote_uri(path):
path = os.path.abspath(os.path.expanduser(path))
return path

Environment:

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.9.1 (default, Dec 13 2020, 11:55:53)
[GCC 10.2.0]
python-bits: 64
OS: Linux
OS-release: 5.4.80-2-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.utf8
LOCALE: en_GB.UTF-8
libhdf5: 1.12.0
libnetcdf: 4.7.4

xarray: 0.16.1
pandas: 1.1.5
numpy: 1.19.4
scipy: 1.5.4
netCDF4: 1.5.4
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.2.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.30.0
distributed: None
matplotlib: 3.3.3
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 51.0.0
pip: 20.2.2
conda: None
pytest: 6.1.2
IPython: 7.19.0
sphinx: 3.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant