id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type
783985506,MDExOlB1bGxSZXF1ZXN0NTUzMjUxMzEz,4795,Expand user dir paths (~) in open_mfdataset.,1186928,closed,0,,,3,2021-01-12T07:22:56Z,2021-01-15T17:22:37Z,2021-01-15T17:22:28Z,CONTRIBUTOR,,0,pydata/xarray/pulls/4795,"- [x] Closes #4783
- [ ] Tests added
- [x] Passes `pre-commit run --all-files`
- [x] User visible changes (including notable bug fixes) are documented in `whats-new.rst`
Overriding CI behaviors
By default, the upstream dev CI is disabled on pull request and push events. You can override this behavior per commit by adding a `[test-upstream]` tag to the first line of the commit message. For documentation-only commits, you can skip the CI per commit by adding a `[skip-ci]` tag to the first line of the commit message
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4795/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull
782335748,MDU6SXNzdWU3ODIzMzU3NDg=,4783,User directories (~) not expanded by open_mfdataset().,1186928,closed,0,,,0,2021-01-08T19:08:25Z,2021-01-15T17:22:28Z,2021-01-15T17:22:27Z,CONTRIBUTOR,,,,"**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**:
```python
>>> 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 """", line 1, in
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`.
https://github.com/pydata/xarray/blob/1525fb0b23b8e92420ab428dc3d918a658e92dd4/xarray/backends/api.py#L170-L177
**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
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4783/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue
558140877,MDU6SXNzdWU1NTgxNDA4Nzc=,3735,Contour plot with norm and int or no levels fails.,1186928,closed,0,,,1,2020-01-31T13:45:07Z,2020-05-12T22:47:51Z,2020-05-12T22:47:51Z,CONTRIBUTOR,,,,"#### MCVE Code Sample
```python
import numpy as np
import xarray as xr
import matplotlib as mpl
data = xr.DataArray(np.arange(24).reshape(4, 6))
data.plot.contour(norm=mpl.colors.Normalize(vmin=5, vmax=10))
```
Yields:
```python
Traceback (most recent call last):
File """", line 1, in
File "".../xarray/xarray/plot/plot.py"", line 816, in plotmethod
return newplotfunc(**allargs)
File "".../xarray/xarray/plot/plot.py"", line 694, in newplotfunc
cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs(
File "".../xarray/xarray/plot/utils.py"", line 772, in _process_cmap_cbar_kwargs
cmap_params = _determine_cmap_params(**cmap_kwargs)
File "".../xarray/xarray/plot/utils.py"", line 278, in _determine_cmap_params
cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled)
File "".../xarray/xarray/plot/utils.py"", line 94, in _build_discrete_cmap
n_colors = len(levels) + ext_n - 1
```
#### Expected Output
A plot.
#### Problem Description
I think this has to do with:
https://github.com/pydata/xarray/blob/95e4f6c7a636878c94b892ee8d49866823d0748f/xarray/plot/utils.py#L744
And the line where the code fails:
https://github.com/pydata/xarray/blob/95e4f6c7a636878c94b892ee8d49866823d0748f/xarray/plot/utils.py#L94
There should be an easy fix, I think.
#### Output of ``xr.show_versions()``
INSTALLED VERSIONS
------------------
commit: None
python: 3.8.1 (default, Jan 22 2020, 06:38:00)
[GCC 9.2.0]
python-bits: 64
OS: Linux
OS-release: 4.19.98-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_CH.utf8
LOCALE: fr_CH.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.3
xarray: 0.14.1
pandas: 0.25.3
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.1.1
cfgrib: None
iris: None
bottleneck: None
dask: 2.8.0
distributed: None
matplotlib: 3.1.2
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 44.0.0
pip: 19.3
conda: None
pytest: 5.3.4
IPython: 7.11.1
sphinx: 2.2.1
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3735/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue
520110180,MDExOlB1bGxSZXF1ZXN0MzM4NzU1NzM5,3498,Add option to choose mfdataset attributes source.,1186928,closed,0,,,9,2019-11-08T16:30:33Z,2020-04-05T20:44:43Z,2020-01-11T15:22:56Z,CONTRIBUTOR,,0,pydata/xarray/pulls/3498,"Add a `master_file` keyword arguments to `open_mfdataset` to choose the source of global attributes in a multi-file dataset.
- [x] Closes #2382
- [x] Tests added
- [x] Passes `black . && mypy . && flake8`
- [x] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3498/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull
548413554,MDExOlB1bGxSZXF1ZXN0MzYxNzE4MTAy,3685,Allow binned coordinates on 1D plots y-axis.,1186928,closed,0,,,5,2020-01-11T10:39:13Z,2020-01-23T08:57:07Z,2020-01-22T21:09:39Z,CONTRIBUTOR,,0,pydata/xarray/pulls/3685,"Currently 1D plot functions only allow binned coordinates (of `pd.Interval` type, produced with `groupby_bins`) on the y-axis (issue #3571). This pull request enables plotting intervals on either or both axes of 1D plots.
- [x] Closes #3571
- [x] Tests added
- [x] Passes `black . && mypy . && flake8`
- [x] Fully documented, including `whats-new.rst` for all changes and `api.rst` for new API","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3685/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull
528062816,MDU6SXNzdWU1MjgwNjI4MTY=,3571,Binned coordinates (pd.Interval) not plottable on the y-axis.,1186928,closed,0,,,1,2019-11-25T12:44:40Z,2020-01-22T21:09:39Z,2020-01-22T21:09:39Z,CONTRIBUTOR,,,,"#### Minimal Code Sample
```python
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
# create fake data
data = xr.DataArray(np.random.rand(101)).rename('data')
# group by bins and compute sum
bins = np.linspace(0, 1, 11)
data = data.groupby_bins(data, bins).sum()
# plot group means
data.plot() # works
data.plot(x='data_bins') # works
plt.plot((bins[:-1]+bins[1:])/2, data) # works
# plot with axes transposed
data.plot(y='data_bins') # TypeError
data.plot.line(y='data_bins') # TypeError
plt.plot(data, (bins[:-1]+bins[1:])/2) # workaround
```
#### Expected Output
I would like to plot binned data (produced with `groupby_bins`) with transposed axes, i.e. data on the x-axis, and bins on the y-axis.
#### Problem Description
Attempting to plot using an array of `pd.Interval` on the y-axis yields the following `TypeError`. The error message reports data should be numeric, dates or `pd.Interval`, which they are.
```
Traceback (most recent call last):
File ""./groupbybug.py"", line 19, in
data.plot(y='data_bins') # TypeError
File ""~/.local/lib/python3.7/site-packages/xarray/plot/plot.py"", line 465, in __call__
return plot(self._da, **kwargs)
File ""~/.local/lib/python3.7/site-packages/xarray/plot/plot.py"", line 202, in plot
return plotfunc(darray, **kwargs)
File ""~/.local/lib/python3.7/site-packages/xarray/plot/plot.py"", line 323, in line
_ensure_plottable(xplt_val, yplt_val)
File ""~/.local/lib/python3.7/site-packages/xarray/plot/utils.py"", line 512, in _ensure_plottable
""Plotting requires coordinates to be numeric ""
TypeError: Plotting requires coordinates to be numeric or dates of type np.datetime64, datetime.datetime, cftime.datetime or pd.Interval.
```
#### Output of ``xr.show_versions()``
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.4 (default, Oct 4 2019, 06:57:26)
[GCC 9.2.0]
python-bits: 64
OS: Linux
OS-release: 4.19.84-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_CH.utf8
LOCALE: fr_CH.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.2
xarray: 0.14.1
pandas: 0.25.2
numpy: 1.17.3
scipy: 1.3.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.1.0
cfgrib: None
iris: None
bottleneck: None
dask: 2.5.2
distributed: 0+untagged.1.gd096901.dirty
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 41.2.0
pip: 19.2.3
conda: None
pytest: 5.2.1
IPython: 7.9.0
sphinx: 2.2.1
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3571/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue
354151953,MDU6SXNzdWUzNTQxNTE5NTM=,2382,Add option to choose the source of global attributes in mfdataset.,1186928,closed,0,,,0,2018-08-27T01:45:23Z,2020-01-11T15:22:56Z,2020-01-11T15:22:56Z,CONTRIBUTOR,,,,"#### Code Sample
```python
import numpy as np
import xarray as xr
# prepare fake data
time = np.arange(1000)
data = time**2
# write to multiple netcdf files
for i in range(10):
filename = 'ds{:d}.nc'.format(i)
ds = xr.Dataset({'data': (['time'], data[100*i:100*i+100])},
coords={'time': time[100*i:100*i+100]},
attrs={'history': 'Created ' + filename + '.'})
ds.to_netcdf(filename)
# open as mfdataset
with xr.open_mfdataset('ds?.nc') as ds:
print ds.history
```
#### Problem description
Currently, global attributes of multi-file datasets are taken from the first file in the list.
https://github.com/pydata/xarray/blob/b87b684b36cf5adbe4dca208aed0c69c44fc44c4/xarray/backends/api.py#L649
I think this is a problem in the context of consecutive model runs where history is appended in each subsequent run. When opening the results as mfdataset, history is taken from the first run file all subsequent history is lost.
NetCDF4 has a new keyword argument to set the `master_file` in a `MFDataset` (Unidata/netcdf4-python#835). Would it be possible to add a similar option in xarray?
#### Output of ``xr.show_versions()``
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.65-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_CH.utf8
LOCALE: None.None
xarray: 0.10.8
pandas: 0.23.4
numpy: 1.15.0
scipy: 1.1.0
netCDF4: 1.4.2
h5netcdf: None
h5py: None
Nio: None
zarr: None
bottleneck: None
cyordereddict: None
dask: 0.18.2
distributed: None
matplotlib: 2.2.3
cartopy: 0.15.1
seaborn: None
setuptools: 40.0.0
pip: 18.0
conda: None
pytest: None
IPython: 5.8.0
sphinx: 1.7.6
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2382/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue
353623661,MDU6SXNzdWUzNTM2MjM2NjE=,2381,Plotting norm is superseded by xarray vmin and vmax,1186928,closed,0,,,6,2018-08-24T02:47:17Z,2018-10-08T05:23:35Z,2018-10-08T05:23:35Z,CONTRIBUTOR,,,,"#### Code Sample
```python
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
# prepare array with values between 1e0 and 1e3
da = xr.DataArray(np.logspace(0, 3, 24).reshape(4, 6), dims=('x', 'y'))
# but we want to log-normalize between 1e0 and 1e2
norm = mcolors.LogNorm(1e1, 1e2)
# plot with log norm
da.plot.imshow(norm=norm) # log norm is applied but bounds are replaced
#da.plot.imshow(norm=norm, vmin=norm.vmin, vmax=norm.vmax) # works, but redundant
# show results
plt.show()
```
#### Problem description
When passing a norm argument to imshow etc, the norm is forwarded to matplotlib but its data bounds are replaced with those calculated by xarray.
#### Expected Output
I think that the norm's ``vmin`` and ``vmax`` should take precedence over xarray-generated ``vmin`` and ``vmax``.
#### Output of ``xr.show_versions()``
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.65-1-MANJARO
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_CH.utf8
LOCALE: None.None
xarray: 0.10.8
pandas: 0.23.4
numpy: 1.15.0
scipy: 1.1.0
netCDF4: 1.4.1
h5netcdf: None
h5py: None
Nio: None
zarr: None
bottleneck: None
cyordereddict: None
dask: 0.18.2
distributed: None
matplotlib: 2.2.3
cartopy: 0.15.1
seaborn: None
setuptools: 40.0.0
pip: 18.0
conda: None
pytest: None
IPython: 5.8.0
sphinx: 1.7.6
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2381/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue