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 1037814301,I_kwDOAMm_X84928od,5901,Spurious lines of the pcolormesh example,30388627,closed,0,,,9,2021-10-27T20:06:40Z,2024-02-28T19:11:34Z,2024-02-28T19:11:34Z,NONE,,,,"**What happened**: The [example](http://xarray.pydata.org/en/stable/examples/multidimensional-coords.html) of plotting data using pcolormesh has some spurious lines: ![image](https://user-images.githubusercontent.com/30388627/139136728-3873cb79-6fb9-416b-87b5-fa9a61b1b169.png) **What you expected to happen**: No spurious lines. **Minimal Complete Verifiable Example**: ```python %matplotlib inline import numpy as np import pandas as pd import xarray as xr import cartopy.crs as ccrs from matplotlib import pyplot as plt ds = xr.tutorial.open_dataset('rasm').load() plt.figure(figsize=(14,6)) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_global() ds.Tair[0].plot.pcolormesh(ax=ax, transform=ccrs.PlateCarree(), x='xc', y='yc', shading='auto', add_colorbar=False) ax.coastlines() ax.set_ylim([0,90]); ``` **Anything else we need to know?**: [pcolormesh doc](https://matplotlib.org/devdocs/gallery/images_contours_and_fields/pcolormesh_grids.html) **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.10 | packaged by conda-forge | (default, Sep 13 2021, 21:46:58) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.11.0-34-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 0.19.0 pandas: 1.3.3 numpy: 1.21.2 scipy: 1.7.1 netCDF4: 1.5.7 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.5.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2021.10.0 distributed: 2021.10.0 matplotlib: 3.4.3 cartopy: 0.19.0.post1 seaborn: None numbagg: None pint: None setuptools: 58.0.4 pip: 21.2.4 conda: None pytest: None IPython: 7.28.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5901/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1943355490,I_kwDOAMm_X85z1UBi,8308,Different plotting reaults compared to matplotlib,30388627,closed,0,,,4,2023-10-14T15:54:32Z,2023-10-14T20:02:16Z,2023-10-14T20:02:16Z,NONE,,,,"### What happened? I got different results when I tried to plot 2D data [test.npy.zip](https://github.com/pydata/xarray/files/12906635/test.npy.zip) using matplotlib and xarray. ### matplotlib ![image](https://github.com/pydata/xarray/assets/30388627/aca2bd14-33e5-4a2e-9b01-65432c63af47) ### xarray ![image](https://github.com/pydata/xarray/assets/30388627/3a9b0793-34f7-49d1-ac5f-bd07d83a958d) ### What did you expect to happen? Same plot. ### Minimal Complete Verifiable Example ```Python import numpy as np import xarray as xr import matplotlib.pyplot as plt test = np.load('test.npy') plt.imshow(test, vmin=0, vmax=200) plt.colorbar() xr.DataArray(test).plot.imshow(vmin=0, vmax=200) ``` ### MVCE confirmation - [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray. - [X] Complete example — the example is self-contained, including all data and the text of any traceback. - [X] Verifiable example — the example copy & pastes into an IPython prompt or [Binder notebook](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result. - [X] New issue — a search of GitHub Issues suggests this is not a duplicate. - [X] Recent environment — the issue occurs with the latest version of xarray and its dependencies. ### Relevant log output _No response_ ### Anything else we need to know? _No response_ ### Environment
INSTALLED VERSIONS ------------------ commit: None python: 3.10.12 | packaged by conda-forge | (main, Jun 23 2023, 22:41:52) [Clang 15.0.7 ] python-bits: 64 OS: Darwin OS-release: 22.3.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: None LOCALE: (None, 'UTF-8') libhdf5: None libnetcdf: None xarray: 2023.9.0 pandas: 2.1.1 numpy: 1.26.0 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.8.0 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 68.2.2 pip: 23.2.1 conda: None pytest: None mypy: None IPython: 8.16.1 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/8308/reactions"", ""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1279891109,I_kwDOAMm_X85MSZal,6713,Support `skipna` in `.where()`,30388627,closed,0,,,3,2022-06-22T10:04:05Z,2022-06-24T22:52:02Z,2022-06-24T22:52:02Z,NONE,,,,"### Is your feature request related to a problem? Sometimes, the mask used in `.where(mask)` may have nan values. In the current stage, xarray just neglects them. But, it also makes sense that users want to mask data with nan values. ### Describe the solution you'd like This option can be achieved by adding `skipna=bool`. if `skipna=False`, the nan values in mask will be replaced by 0:`mask.fillna(0)`. By default, it's `skipna=True` which is current function. ### Describe alternatives you've considered _No response_ ### Additional context _No response_","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6713/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 596249070,MDU6SXNzdWU1OTYyNDkwNzA=,3954,Concatenate 3D array with 2D array,30388627,open,0,,,5,2020-04-08T01:36:28Z,2022-05-06T16:39:22Z,,NONE,,,,"The 3D array has three dims: z, y and x. The 2D array has two dims: y and x. When I try to concatenate them by expanding the 2D array with z dim, there's something wrong in `_dataset_concat` #### MCVE Code Sample ```python import xarray as xr import numpy as np x = 2 y = 4 z = 3 data = np.arange(x*y*z).reshape(z, x, y) # 3d array with coords a = xr.DataArray(data, dims=['z', 'y', 'x'], coords={'z': np.arange(z)}) # 2d array without coords b = xr.DataArray(np.arange(x*y).reshape(x, y)*1.5, dims=['y', 'x']) # expand 2d to 3d b = b.expand_dims('z') # concat comb = xr.concat([a, b], dim='z') ``` #### Expected Output Same as `np.concatenate`: ``` concat_array = np.concatenate((a, b)) comb = xr.DataArray(concat_array, dims={'z', 'y', 'x'}) ``` ``` array([[[ 0. , 1. , 2. , 3. ], [ 4. , 5. , 6. , 7. ]], [[ 8. , 9. , 10. , 11. ], [12. , 13. , 14. , 15. ]], [[16. , 17. , 18. , 19. ], [20. , 21. , 22. , 23. ]], [[ 0. , 1.5, 3. , 4.5], [ 6. , 7.5, 9. , 10.5]]]) Dimensions without coordinates: z, x, y ``` #### Problem Description ``` comb = xr.concat([a, b], dim='z') File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 135, in concat return f(objs, dim, data_vars, coords, compat, positions, fill_value, join) File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 455, in _dataarray_concat join=join, File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 395, in _dataset_concat raise ValueError(""%r is not present in all datasets."" % k) ValueError: 'z' is not present in all datasets. ``` As suggested by @dcherian, assigning the coordinate label by changing `b = b.expand_dims('z')` to `b = b.expand_dims(z=[3])` makes it work. #### Versions
Output of `xr.show_versions()` INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 21:48:41) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None libhdf5: None libnetcdf: None xarray: 0.15.1 pandas: 1.0.3 numpy: 1.18.1 scipy: 1.4.1 netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.1.1.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.3 cfgrib: None iris: None bottleneck: None dask: 2.10.1 distributed: 2.14.0 matplotlib: 3.2.1 cartopy: 0.17.0 seaborn: 0.10.0 numbagg: None setuptools: 46.1.3.post20200325 pip: 20.0.2 conda: None pytest: None IPython: 7.13.0 sphinx: 2.4.4
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3954/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue 596352097,MDU6SXNzdWU1OTYzNTIwOTc=,3955,Masking and preserving int type,30388627,closed,0,,,5,2020-04-08T06:56:26Z,2022-05-02T19:25:42Z,2022-05-02T19:25:42Z,NONE,,,,"When DataArray is masked by `.where()`, the type is converted to `float64`. But, if we need to use the DataArray ouput from `.where()` in `.isel()`, the dtype should be `int`. (#3949 ) #### MCVE Code Sample ```python import numpy as np import xarray as xr val_arr = xr.DataArray(np.arange(27).reshape(3, 3, 3), dims=['z', 'y', 'x']) z_indices = xr.DataArray(np.array([[1, 0, 2], [0, 0, 1], [-2222, 0, 1]]), dims=['y', 'x']) fill_value = -2222 sub = z_indices.where(z_indices != fill_value) indexed_array = val_arr.isel(z=sub) ``` #### Expected Output ``` array([[ 1, 0, 2], [ 0, 0, 1], [nan, 0, 1]]) ``` #### Problem Description ``` File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\indexing.py"", line 446, in __init__ f""invalid indexer array, does not have integer dtype: {k!r}"" TypeError: invalid indexer array, does not have integer dtype: array([[ 1., 0., 2.], [ 0., 0., 1.], [nan, 0., 1.]]) ``` Currently, pandas [supports NaN values](https://pandas.pydata.org/pandas-docs/version/0.24/whatsnew/v0.24.0.html#optional-integer-na-support). Is this possible for xarray? or another method around? ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3955/reactions"", ""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 1, ""eyes"": 0}",,completed,13221727,issue 630573329,MDU6SXNzdWU2MzA1NzMzMjk=,4121,decode_cf doesn't work for ancillary_variables in attributes,30388627,closed,0,,,4,2020-06-04T07:18:34Z,2022-04-18T15:56:22Z,2022-04-18T15:56:22Z,NONE,,,," Sometimes we have one attribute called `ancillary_variables` which is a list containing several strings. It would be useful to decode them. #### MCVE Code Sample ```python import numpy as np import xarray as xr import pandas as pd temp = 15 + 8 * np.random.randn(2, 2, 3) precip = 10 * np.random.rand(2, 2, 3) temp = xr.DataArray(temp, dims=['x', 'y', 'time']) precip = xr.DataArray(precip, dims=['x', 'y', 'time']) lon = [[-99.83, -99.32], [-99.79, -99.23]] lat = [[42.25, 42.21], [42.63, 42.59]] temp.attrs['ancillary_variables'] = ['precip'] precip.attrs['ancillary_variables'] = ['temp'] ds = xr.Dataset({'temperature': temp, 'precipitation': precip}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': pd.date_range('2014-09-06', periods=3), 'reference_time': pd.Timestamp('2014-09-05')}) ds.to_netcdf('test_ancillary_variables.nc', engine='netcdf4') ds_new = xr.open_dataset('test_ancillary_variables.nc', decode_cf=True) print(ds_new['temperature']) ``` #### Expected Output ``` ...... Attributes: ancillary_variables: [ ......... ] ``` #### Versions
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 4.9.0-8-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.4 xarray: 0.15.1 pandas: 1.0.4 numpy: 1.18.4 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: 2.4.0 cftime: 1.1.3 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.5 cfgrib: None iris: None bottleneck: None dask: 2.14.0 distributed: 2.17.0 matplotlib: 3.2.1 cartopy: 0.18.0 seaborn: None numbagg: None setuptools: 47.1.1.post20200529 pip: 20.1.1 conda: None pytest: None IPython: None sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4121/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 596606599,MDU6SXNzdWU1OTY2MDY1OTk=,3957,Sort DataArray by data values along one dim,30388627,closed,0,,,10,2020-04-08T14:05:44Z,2022-04-09T15:52:20Z,2022-04-09T15:52:20Z,NONE,,,,"`.sortby()` only supports sorting DataArray by `coords values`. I'm trying to sort one DataArray (`cld`) by `data values` along one dim and sort another DataArray (`pair`) by the same order. #### MCVE Code Sample ```python import xarray as xr import numpy as np x = 4 y = 2 z = 4 data = np.arange(x*y*z).reshape(z, y, x) # 3d array with coords cld_1 = xr.DataArray(data, dims=['z', 'y', 'x'], coords={'z': np.arange(z)}) # 2d array without coords cld_2 = xr.DataArray(np.arange(x*y).reshape(y, x)*1.5+1, dims=['y', 'x']) # expand 2d to 3d cld_2 = cld_2.expand_dims(z=[4]) # concat cld = xr.concat([cld_1, cld_2], dim='z') # paired array pair = cld.copy(data=np.arange(x*y*(z+1)).reshape(z+1, y, x)) print(cld) print(pair) ``` #### Output ``` array([[[ 0. , 1. , 2. , 3. ], [ 4. , 5. , 6. , 7. ]], [[ 8. , 9. , 10. , 11. ], [12. , 13. , 14. , 15. ]], [[16. , 17. , 18. , 19. ], [20. , 21. , 22. , 23. ]], [[24. , 25. , 26. , 27. ], [28. , 29. , 30. , 31. ]], [[ 1. , 2.5, 4. , 5.5], [ 7. , 8.5, 10. , 11.5]]]) Coordinates: * z (z) int64 0 1 2 3 4 Dimensions without coordinates: y, x array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]], [[ 8, 9, 10, 11], [12, 13, 14, 15]], [[16, 17, 18, 19], [20, 21, 22, 23]], [[24, 25, 26, 27], [28, 29, 30, 31]], [[32, 33, 34, 35], [36, 37, 38, 39]]]) Coordinates: * z (z) int64 0 1 2 3 4 Dimensions without coordinates: y, x ``` #### Problem Description I've tried `argsort()`: `cld.argsort(axis=0)`, but the result is wrong: ``` array([[[0, 0, 0, 0], [0, 0, 0, 0]], [[4, 4, 4, 4], [4, 4, 4, 4]], [[1, 1, 1, 1], [1, 1, 1, 1]], [[2, 2, 2, 2], [2, 2, 2, 2]], [[3, 3, 3, 3], [3, 3, 3, 3]]], dtype=int64) Coordinates: * z (z) int64 0 1 2 3 4 Dimensions without coordinates: y, x ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3957/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1112925311,I_kwDOAMm_X85CVeR_,6188,extrapolate not working for multi-dimentional data,30388627,closed,1,,,2,2022-01-24T17:16:20Z,2022-01-24T22:34:08Z,2022-01-24T22:27:48Z,NONE,,,,"### What happened? I'm trying to interpolate multi-dimensional data. But, it doesn't work with extrapolating. ### What did you expect to happen? _No response_ ### Minimal Complete Verifiable Example ```python import xarray as xr import numpy as np da = xr.DataArray( np.sin(0.3 * np.arange(20).reshape(5, 4)), [(""x"", np.arange(5)), (""y"", [0.1, 0.2, 0.3, 0.4])], ) x = xr.DataArray([-0.5, 1.5, 2.5], dims=""z"") y = xr.DataArray([0.15, 0.25, 0.35], dims=""z"") da.interp(x=x, y=y, kwargs={""fill_value"": ""extrapolate""}) ``` ### Relevant log output ```python --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [2], in 8 x = xr.DataArray([-0.5, 1.5, 2.5], dims=""z"") 10 y = xr.DataArray([0.15, 0.25, 0.35], dims=""z"") ---> 12 da.interp(x=x, y=y, kwargs={""fill_value"": ""extrapolate""}) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataarray.py:1742, in DataArray.interp(self, coords, method, assume_sorted, kwargs, **coords_kwargs) 1737 if self.dtype.kind not in ""uifc"": 1738 raise TypeError( 1739 ""interp only works for a numeric type array. "" 1740 ""Given {}."".format(self.dtype) 1741 ) -> 1742 ds = self._to_temp_dataset().interp( 1743 coords, 1744 method=method, 1745 kwargs=kwargs, 1746 assume_sorted=assume_sorted, 1747 **coords_kwargs, 1748 ) 1749 return self._from_temp_dataset(ds) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:3192, in Dataset.interp(self, coords, method, assume_sorted, kwargs, method_non_numeric, **coords_kwargs) 3189 if dtype_kind in ""uifc"": 3190 # For normal number types do the interpolation: 3191 var_indexers = {k: v for k, v in use_indexers.items() if k in var.dims} -> 3192 variables[name] = missing.interp(var, var_indexers, method, **kwargs) 3193 elif dtype_kind in ""ObU"" and (use_indexers.keys() & var.dims): 3194 # For types that we do not understand do stepwise 3195 # interpolation to avoid modifying the elements. (...) 3198 # this loop there might be some duplicate code that slows it 3199 # down, therefore collect these signals and run it later: 3200 to_reindex[name] = var File ~/miniconda3/lib/python3.9/site-packages/xarray/core/missing.py:640, in interp(var, indexes_coords, method, **kwargs) 638 original_dims = broadcast_dims + dims 639 new_dims = broadcast_dims + list(destination[0].dims) --> 640 interped = interp_func( 641 var.transpose(*original_dims).data, x, destination, method, kwargs 642 ) 644 result = Variable(new_dims, interped, attrs=var.attrs) 646 # dimension of the output array File ~/miniconda3/lib/python3.9/site-packages/xarray/core/missing.py:765, in interp_func(var, x, new_x, method, kwargs) 749 meta = var._meta 751 return da.blockwise( 752 _dask_aware_interpnd, 753 out_ind, (...) 762 align_arrays=False, 763 ) --> 765 return _interpnd(var, x, new_x, func, kwargs) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/missing.py:789, in _interpnd(var, x, new_x, func, kwargs) 787 # stack new_x to 1 vector, with reshape 788 xi = np.stack([x1.values.ravel() for x1 in new_x], axis=-1) --> 789 rslt = func(x, var, xi, **kwargs) 790 # move back the interpolation axes to the last position 791 rslt = rslt.transpose(range(-rslt.ndim + 1, 1)) File ~/miniconda3/lib/python3.9/site-packages/scipy/interpolate/interpolate.py:2703, in interpn(points, values, xi, method, bounds_error, fill_value) 2701 # perform interpolation 2702 if method == ""linear"": -> 2703 interp = RegularGridInterpolator(points, values, method=""linear"", 2704 bounds_error=bounds_error, 2705 fill_value=fill_value) 2706 return interp(xi) 2707 elif method == ""nearest"": File ~/miniconda3/lib/python3.9/site-packages/scipy/interpolate/interpolate.py:2469, in RegularGridInterpolator.__init__(self, points, values, method, bounds_error, fill_value) 2465 fill_value_dtype = np.asarray(fill_value).dtype 2466 if (hasattr(values, 'dtype') and not 2467 np.can_cast(fill_value_dtype, values.dtype, 2468 casting='same_kind')): -> 2469 raise ValueError(""fill_value must be either 'None' or "" 2470 ""of a type compatible with values"") 2472 for i, p in enumerate(points): 2473 if not np.all(np.diff(p) > 0.): ValueError: fill_value must be either 'None' or of a type compatible with values ``` ### Anything else we need to know? I've also tried `da.interp(x=x, kwargs={""fill_value"": ""extrapolate""}).interp(y=y)`, but I got this error: ``` --------------------------------------------------------------------------- KeyError Traceback (most recent call last) Input In [4], in 10 y = xr.DataArray([0.15, 0.25, 0.35], dims=""z"") 12 # da.interp(x=x, y=y, kwargs={""fill_value"": ""extrapolate""}) ---> 13 da.interp(x=x, kwargs={""fill_value"": ""extrapolate""}).interp(y=y) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataarray.py:1742, in DataArray.interp(self, coords, method, assume_sorted, kwargs, **coords_kwargs) 1737 if self.dtype.kind not in ""uifc"": 1738 raise TypeError( 1739 ""interp only works for a numeric type array. "" 1740 ""Given {}."".format(self.dtype) 1741 ) -> 1742 ds = self._to_temp_dataset().interp( 1743 coords, 1744 method=method, 1745 kwargs=kwargs, 1746 assume_sorted=assume_sorted, 1747 **coords_kwargs, 1748 ) 1749 return self._from_temp_dataset(ds) File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:3130, in Dataset.interp(self, coords, method, assume_sorted, kwargs, method_non_numeric, **coords_kwargs) 3121 if coords: 3122 # This avoids broadcasting over coordinates that are both in 3123 # the original array AND in the indexing array. It essentially 3124 # forces interpolation along the shared coordinates. 3125 sdims = ( 3126 set(self.dims) 3127 .intersection(*[set(nx.dims) for nx in indexers.values()]) 3128 .difference(coords.keys()) 3129 ) -> 3130 indexers.update({d: self.variables[d] for d in sdims}) 3132 obj = self if assume_sorted else self.sortby([k for k in coords]) 3134 def maybe_variable(obj, k): 3135 # workaround to get variable for dimension without coordinate. File ~/miniconda3/lib/python3.9/site-packages/xarray/core/dataset.py:3130, in (.0) 3121 if coords: 3122 # This avoids broadcasting over coordinates that are both in 3123 # the original array AND in the indexing array. It essentially 3124 # forces interpolation along the shared coordinates. 3125 sdims = ( 3126 set(self.dims) 3127 .intersection(*[set(nx.dims) for nx in indexers.values()]) 3128 .difference(coords.keys()) 3129 ) -> 3130 indexers.update({d: self.variables[d] for d in sdims}) 3132 obj = self if assume_sorted else self.sortby([k for k in coords]) 3134 def maybe_variable(obj, k): 3135 # workaround to get variable for dimension without coordinate. File ~/miniconda3/lib/python3.9/site-packages/xarray/core/utils.py:459, in Frozen.__getitem__(self, key) 458 def __getitem__(self, key: K) -> V: --> 459 return self.mapping[key] KeyError: 'z' ``` ### Environment ```python INSTALLED VERSIONS ------------------ commit: None python: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.11.0-40-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 0.20.2 pandas: 1.3.5 numpy: 1.19.5 scipy: 1.7.3 netCDF4: 1.5.8 pydap: None h5netcdf: None h5py: 3.6.0 Nio: None zarr: 2.10.3 cftime: 1.5.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.10 cfgrib: None iris: None bottleneck: None dask: 2021.12.0 distributed: 2021.12.0 matplotlib: 3.5.1 cartopy: 0.20.2 seaborn: None numbagg: None fsspec: 2022.01.0 cupy: None pint: 0.18 sparse: None setuptools: 59.8.0 pip: 21.3.1 conda: 4.11.0 pytest: None IPython: 8.0.0 sphinx: None ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6188/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1085619598,I_kwDOAMm_X85AtT2O,6091,uint type data are read as wrong type (float64),30388627,closed,0,,,3,2021-12-21T09:29:10Z,2022-01-09T03:30:55Z,2022-01-09T03:30:55Z,NONE,,,,"**What happened**: The `uint` data type variables are read as `float64` instead of the correct `uint` type. **Minimal Complete Verifiable Example**: ```python import xarray as xr print(xr.open_dataset('test_save.nc')['processing_quality_flags'].dtype) ``` **Anything else we need to know?**: The [sample data](https://github.com/pydata/xarray/files/7751114/test_save.nc.zip) is attached here. The output of `ncdump -h test_save.nc`: ``` netcdf test_save { dimensions: y = 3246 ; x = 450 ; variables: float longitude(y, x) ; longitude:_FillValue = NaNf ; longitude:name = ""longitude"" ; longitude:standard_name = ""longitude"" ; longitude:units = ""degrees_east"" ; float latitude(y, x) ; latitude:_FillValue = NaNf ; latitude:name = ""latitude"" ; latitude:standard_name = ""latitude"" ; latitude:units = ""degrees_north"" ; uint processing_quality_flags(y, x) ; processing_quality_flags:_FillValue = 4294967295U ; processing_quality_flags:comment = ""Flags indicating conditions that affect quality of the retrieval."" ; processing_quality_flags:end_time = ""2019-07-02 05:00:24"" ; processing_quality_flags:file_key = ""PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/processing_quality_flags"" ; processing_quality_flags:file_type = ""tropomi_l2"" ; processing_quality_flags:flag_masks = 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 255U, 256U, 512U, 1024U, 2048U, 4096U, 8192U, 16384U, 32768U, 65536U, 131072U, 262144U, 524288U, 1048576U, 2097152U, 4194304U, 8388608U, 16777216U, 33554432U, 67108864U, 134217728U, 268435456U, 536870912U ; processing_quality_flags:flag_meanings = ""success radiance_missing irradiance_missing input_spectrum_missing reflectance_range_error ler_range_error snr_range_error sza_range_error vza_range_error lut_range_error ozone_range_error wavelength_offset_error initialization_error memory_error assertion_error io_error numerical_error lut_error ISRF_error convergence_error cloud_filter_convergence_error max_iteration_convergence_error aot_lower_boundary_convergence_error other_boundary_convergence_error geolocation_error ch4_noscat_zero_error h2o_noscat_zero_error max_optical_thickness_error aerosol_boundary_error boundary_hit_error chi2_error svd_error dfs_error radiative_transfer_error optimal_estimation_error profile_error cloud_error model_error number_of_input_data_points_too_low_error cloud_pressure_spread_too_low_error cloud_too_low_level_error generic_range_error generic_exception input_spectrum_alignment_error abort_error wrong_input_type_error wavelength_calibration_error coregistration_error slant_column_density_error airmass_factor_error vertical_column_density_error signal_to_noise_ratio_error configuration_error key_error saturation_error max_num_outlier_exceeded_error solar_eclipse_filter cloud_filter altitude_consistency_filter altitude_roughness_filter sun_glint_filter mixed_surface_type_filter snow_ice_filter aai_filter cloud_fraction_fresco_filter aai_scene_albedo_filter small_pixel_radiance_std_filter cloud_fraction_viirs_filter cirrus_reflectance_viirs_filter cf_viirs_swir_ifov_filter cf_viirs_swir_ofova_filter cf_viirs_swir_ofovb_filter cf_viirs_swir_ofovc_filter cf_viirs_nir_ifov_filter cf_viirs_nir_ofova_filter cf_viirs_nir_ofovb_filter cf_viirs_nir_ofovc_filter refl_cirrus_viirs_swir_filter refl_cirrus_viirs_nir_filter diff_refl_cirrus_viirs_filter ch4_noscat_ratio_filter ch4_noscat_ratio_std_filter h2o_noscat_ratio_filter h2o_noscat_ratio_std_filter diff_psurf_fresco_ecmwf_filter psurf_fresco_stdv_filter ocean_filter time_range_filter pixel_or_scanline_index_filter geographic_region_filter input_spectrum_warning wavelength_calibration_warning extrapolation_warning sun_glint_warning south_atlantic_anomaly_warning sun_glint_correction snow_ice_warning cloud_warning AAI_warning pixel_level_input_data_missing data_range_warning low_cloud_fraction_warning altitude_consistency_warning signal_to_noise_ratio_warning deconvolution_warning so2_volcanic_origin_likely_warning so2_volcanic_origin_certain_warning interpolation_warning saturation_warning high_sza_warning cloud_retrieval_warning cloud_inhomogeneity_warning"" ; processing_quality_flags:flag_values = 0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U, 16U, 17U, 18U, 19U, 20U, 21U, 22U, 23U, 24U, 25U, 26U, 27U, 28U, 29U, 30U, 31U, 32U, 33U, 34U, 35U, 36U, 37U, 38U, 39U, 40U, 41U, 42U, 43U, 44U, 45U, 46U, 47U, 48U, 49U, 50U, 51U, 52U, 53U, 54U, 55U, 64U, 65U, 66U, 67U, 68U, 69U, 70U, 71U, 72U, 73U, 74U, 75U, 76U, 77U, 78U, 79U, 80U, 81U, 82U, 83U, 84U, 85U, 86U, 87U, 88U, 89U, 90U, 91U, 92U, 93U, 94U, 95U, 96U, 97U, 256U, 512U, 1024U, 2048U, 4096U, 8192U, 16384U, 32768U, 65536U, 131072U, 262144U, 524288U, 1048576U, 2097152U, 4194304U, 8388608U, 16777216U, 33554432U, 67108864U, 134217728U, 268435456U, 536870912U ; processing_quality_flags:long_name = ""Processing quality flags"" ; processing_quality_flags:modifiers = """" ; processing_quality_flags:platform_shortname = ""S5P"" ; processing_quality_flags:reader = ""tropomi_l2"" ; processing_quality_flags:sensor = ""tropomi"" ; processing_quality_flags:start_time = ""2019-07-02 03:18:54"" ; processing_quality_flags:coordinates = ""latitude longitude"" ; } ``` Note that I can't reproduce it using this example: ``` import numpy as np import xarray as xr da = xr.DataArray(np.array([1,2,3], dtype='uint')).rename('test_array') da.to_netcdf(""test.nc"", engine='netcdf4') with xr.open_dataset('test.nc') as ds: print(ds['test_array'].dtype) >>> uint64 ``` **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.11.0-40-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 0.20.1 pandas: 1.3.4 numpy: 1.20.3 scipy: 1.7.3 netCDF4: 1.5.8 pydap: None h5netcdf: None h5py: 3.6.0 Nio: None zarr: 2.10.3 cftime: 1.5.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.10 cfgrib: None iris: None bottleneck: None dask: 2021.11.2 distributed: 2021.11.2 matplotlib: 3.5.0 cartopy: 0.20.1 seaborn: None numbagg: None fsspec: 2021.11.1 cupy: None pint: 0.18 sparse: None setuptools: 59.4.0 pip: 21.3.1 conda: 4.11.0 pytest: None IPython: 7.30.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6091/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1083806365,I_kwDOAMm_X85AmZKd,6085,Missing linked coordinates of subgroup variable,30388627,closed,0,,,3,2021-12-18T10:55:56Z,2021-12-27T18:30:59Z,2021-12-27T18:30:59Z,NONE,,,,"**What happened**: I have a [NetCDF file](https://data-portal.s5p-pal.com/browser/item/BXADeFDHwTQ3o8nrrhTDZSMwnfrWHe16d/2JM1fiAU7vaLzQZSRP3o4uRznddN4VH4NGpp4dfkKSnZV4hzrZifph/eX91ZTvd7bADysky6BArSuuZDRDyS1Va6ZSSSaUkw4PxEXiYyc3ZYZ1vNcwo/xdDvwjHCFDzMnS3V2LdCjo3DPbiMR3LiLiz79gzQibo1ebTmhymGartDy3faKioX/2RU2DwH5yvwhdKJrx5pfNf1FLnnGDvfwrtn7eX1XxCuDH7RVftpZfUXTHRVEFtagV6syF/cA42MuC47K24cXuCNNjhLQcYkrKqf9YgPPXVFFVXWWY7SmuTFWY8gcBbGcg1trTsa65vhci8WPV5AMH7nVpJ9C8U1taG5J9NvTmUp9A6BQ635uFqrXY9VnXnzTVwa86vQHyRiZm11u72xYpmsQhVPRgrxHdaR8sNBT2kUQKwrcE9) that has groups like this: ``` --/PRODUCT/ --/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS ..... ``` **Screenshots** ![image](https://user-images.githubusercontent.com/30388627/146638398-8ea1a6da-f6d5-452b-84c8-573b7f0df435.png) ![image](https://user-images.githubusercontent.com/30388627/146638407-9f33fc01-7ff9-41a2-9cd3-a5ae69dca272.png) When I read the variable named `air_mass_factor_clear` inside `/PRODUCT/SUPPORT_DATA/DETAILED_RESULTS`, the coordinates are missing. But, it works for variable named `nitrogendioxide_tropospheric_column` in the `/PRODUCT/` group. **What you expected to happen**: Coordinates of variables in subgroups are loaded. **Minimal Complete Verifiable Example**: ```python xr.open_dataset('./201908/S5P_PAL__L2__NO2____20190811T022605_20190811T040734_09459_01_020301_20211110T023157.nc', group='PRODUCT/')['nitrogendioxide_tropospheric_column'] ``` ![image](https://user-images.githubusercontent.com/30388627/146638383-e66ef713-3a04-410b-a17e-65e76f1ae209.png) ```python xr.open_dataset('./201908/S5P_PAL__L2__NO2____20190811T022605_20190811T040734_09459_01_020301_20211110T023157.nc', group='PRODUCT/SUPPORT_DATA/DETAILED_RESULTS/')['air_mass_factor_clear'] ``` ![image](https://user-images.githubusercontent.com/30388627/146638413-cf6572ed-dcc7-4fe7-8df5-a583e9561df8.png) **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:20:46) [GCC 9.4.0] python-bits: 64 OS: Linux OS-release: 5.11.0-40-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 0.20.1 pandas: 1.3.4 numpy: 1.20.3 scipy: 1.7.3 netCDF4: 1.5.8 pydap: None h5netcdf: None h5py: 3.6.0 Nio: None zarr: 2.10.3 cftime: 1.5.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.2.10 cfgrib: None iris: None bottleneck: None dask: 2021.11.2 distributed: 2021.11.2 matplotlib: 3.5.0 cartopy: 0.20.1 seaborn: None numbagg: None fsspec: 2021.11.1 cupy: None pint: 0.18 sparse: None setuptools: 59.4.0 pip: 21.3.1 conda: 4.11.0 pytest: None IPython: 7.30.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6085/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1086038682,I_kwDOAMm_X85Au6Ka,6095,Issue on page /examples/multidimensional-coords.html,30388627,open,0,,,1,2021-12-21T17:04:09Z,2021-12-21T19:17:42Z,,NONE,,,,The `Groupby` example focuses on lat_bin. Then the `xc` in the `groupby_bins` function should be `yc`.,"{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6095/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue 488190500,MDU6SXNzdWU0ODgxOTA1MDA=,3275,Change the label size and tick label size of colorbar,30388627,closed,0,,,10,2019-09-02T13:27:32Z,2021-11-17T19:38:25Z,2019-09-02T13:36:18Z,NONE,,,,"#### MCVE Code Sample ```python # Your code here import xarray as xr airtemps = xr.tutorial.open_dataset('air_temperature') air = airtemps.air - 273.15 air2d = air.isel(time=500) air2d.plot.pcolormesh(add_colorbar=True, add_labels=True, cbar_kwargs=dict(orientation='horizontal', pad=0.15, shrink=1, label='Temperature ($^{\circ}$C)')) ``` #### Expected Output ![image](https://user-images.githubusercontent.com/30388627/64117609-3225c480-cdc8-11e9-8eb7-b573e8035119.png) #### Problem Description Is it possible to change the label size and ticks label size of colorbar? `size` and `labelsize` don't work in `cbar_kwargs`. #### Output of ``xr.show_versions()``
# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.7 (default, Feb 28 2019, 07:28:18) [MSC v.1900 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None libhdf5: 1.10.4 libnetcdf: 4.6.2 xarray: 0.12.1 pandas: 0.24.2 numpy: 1.16.3 scipy: 1.2.1 netCDF4: 1.5.1.1 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudonetCDF: None rasterio: 1.0.22 cfgrib: None iris: None bottleneck: None dask: 1.2.0 distributed: 1.27.1 matplotlib: 3.1.1 cartopy: 0.17.0 seaborn: None setuptools: 41.0.1 pip: 19.1 conda: None pytest: None IPython: 7.6.1 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3275/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 912149228,MDU6SXNzdWU5MTIxNDkyMjg=,5439,Set `allow_rechunk=True` still raise different lengths error,30388627,closed,0,,,1,2021-06-05T08:17:18Z,2021-06-05T08:37:11Z,2021-06-05T08:34:52Z,NONE,,,,"**What happened**: I'm using `apply_ufunc` to apply `np.minimum.reduceat()` function, which is much quicker than `groupby_bins().min()`. However, the length of bin is different from the input data. As a result, this causes the length error. **Minimal Complete Verifiable Example**: ```python import numpy as np import xarray as xr data = xr.DataArray(np.arange(10), dims=['x']) dask_data = data.chunk({'x': -1}) bins_reduceat = np.linspace(0, 9, 10).astype('int') def reduceat_np(data, bins): return np.minimum.reduceat(data, bins) res = xr.apply_ufunc(reduceat_np, dask_data, bins_reduceat[:5], dask=""parallelized"", output_dtypes=[data.dtype], dask_gufunc_kwargs={'allow_rechunk': True}, ) res.compute() ``` Error: ``` ~/new/miniconda3/envs/pyresample_min/lib/python3.8/site-packages/dask/array/gufunc.py in apply_gufunc(func, signature, *args, **kwargs) 392 #### Check that the arrays have same length for same dimensions or dimension `1` 393 if set(sizes) | {1} != {1, max(sizes)}: --> 394 raise ValueError( 395 ""Dimension `'{}'` with different lengths in arrays"".format(dim) 396 ) ValueError: Dimension `'__loopdim0__'` with different lengths in arrays ``` **Anything else we need to know?**: It works well if the data and bin have the same length. **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27) [GCC 9.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-957.el7.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.18.2 pandas: 1.2.4 numpy: 1.20.2 scipy: 1.6.3 netCDF4: 1.5.6 pydap: None h5netcdf: None h5py: 3.2.1 Nio: None zarr: 2.8.1 cftime: 1.2.1 nc_time_axis: 1.2.0 PseudoNetCDF: None rasterio: 1.2.3 cfgrib: None iris: 3.0.1 bottleneck: None dask: 2021.04.1 distributed: 2021.04.1 matplotlib: 3.3.4 cartopy: 0.19.0.post1 seaborn: None numbagg: None pint: 0.17 setuptools: 49.6.0.post20210108 pip: 21.1.1 conda: None pytest: 6.2.4 IPython: 7.23.1 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5439/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 897689314,MDU6SXNzdWU4OTc2ODkzMTQ=,5358,Support `range` in `groupby_bins`,30388627,closed,0,,,4,2021-05-21T05:25:12Z,2021-05-31T19:10:24Z,2021-05-21T12:44:39Z,NONE,,,,"Although `groupby_bins` supports setting bins as int, it doesn't support manually setting the range. Here's an example: ``` from scipy.stats import binned_statistic import numpy as np import xarray as xr # --- scipy method --- x = np.arange(500) values = x*50 statistics, _, _ = binned_statistic(x, values, statistic='min', bins=500, range=(0, 500)) # --- xarray method --- x = xr.DataArray(x) values = xr.DataArray(values) x.groupby_bins('dim_0', bins=500).min() ``` I can set `range=(0, 500)` in `binned_statistic`, how can I get the same result using `groupby_bins`? Is it suitable to add this new feature? I have also posted a similar [question](https://stackoverflow.com/questions/67630382/apply-scipy-binned-statistic-by-dask) on StackOverflow.","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/5358/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 694874737,MDU6SXNzdWU2OTQ4NzQ3Mzc=,4410,interpolate_na doesn't support extrapolation,30388627,closed,0,,,4,2020-09-07T08:46:50Z,2020-11-30T17:25:42Z,2020-11-30T17:25:42Z,NONE,,,,"**What happened**: `interpolate_na` doesn't support extrapolation **What you expected to happen**: Support extrapolation. **Minimal Complete Verifiable Example**: ```python import xarray as xr import numpy as np x = xr.DataArray( [[0, 1, np.nan, np.nan, 2, np.nan, np.nan]], dims=['y', 'x'], coords={""x"": xr.Variable(""x"", [0, 1, 1.1, 1.8, 2, 4, 5]), 'y': xr.Variable(""y"", [0])}, ) x = x.interpolate_na(dim=""x"", method=""linear"", use_coordinate=""x"") print(x) ``` The output is: ``` array([[0. , 1. , 1.1, 1.8, 2. , nan, nan]]) ``` It should be this array after extrapolation: ``` array([[0. , 1. , 1.1, 1.8, 2. , 4, 5]]) ``` **Environment**:
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.5 | packaged by conda-forge | (default, Jul 24 2020, 01:25:15) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 5.4.0-42-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.16.0 pandas: 1.0.5 numpy: 1.19.1 scipy: 1.5.2 netCDF4: 1.5.4 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: 2.4.0 cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.5 cfgrib: None iris: None bottleneck: None dask: 2.21.0 distributed: 2.21.0 matplotlib: 3.3.0 cartopy: None seaborn: None numbagg: None pint: None setuptools: 49.2.0.post20200712 pip: 20.1.1 conda: None pytest: None IPython: None sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4410/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 591643901,MDExOlB1bGxSZXF1ZXN0Mzk2Nzc0MTAw,3924,Coordinates passed to interp have nan values,30388627,closed,0,,,9,2020-04-01T05:46:54Z,2020-08-27T08:51:32Z,2020-08-27T08:51:32Z,NONE,,0,pydata/xarray/pulls/3924,"## Problem `Keyerror` when the coordinates passed to `interp` have nan value. ### Example ``` import numpy as np import xarray as xr da = xr.DataArray(np.sin(0.3 * np.arange(20).reshape(5, 4)), [('x', np.arange(5)), ('y', [0.1, 0.2, 0.3, 0.4])]) x = xr.DataArray([[0.5, np.nan], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [np.nan, 0.35]], dims=['z1', 'z2']) da_nan = da.interp(x=x, y=y) ``` ### Output ``` E:\miniconda3\envs\satpy\lib\site-packages\pandas\core\indexes\base.py:2826: RuntimeWarning: invalid value encountered in less op(left_distances, right_distances) | (right_indexer == -1), Traceback (most recent call last): File ""C:\Users\Xin\Desktop\test_none.py"", line 10, in da_nan = da.interp(x=x, y=y) File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\dataarray.py"", line 1365, in interp **coords_kwargs, File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\dataset.py"", line 2610, in interp variables[name] = missing.interp(var, var_indexers, method, **kwargs) File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\missing.py"", line 611, in interp var, indexes_coords = _localize(var, indexes_coords) File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\missing.py"", line 552, in _localize imin = index.get_loc(np.min(new_x.values), method=""nearest"") File ""E:\miniconda3\envs\satpy\lib\site-packages\pandas\core\indexes\base.py"", line 2654, in get_loc raise KeyError(key) KeyError: nan ``` ## Solution Use `np.nanmin` and `np.nanmax` in `index.get_loc()` ## Test ### Code ``` import numpy as np import xarray as xr da = xr.DataArray(np.sin(0.3 * np.arange(20).reshape(5, 4)), [('x', np.arange(5)), ('y', [0.1, 0.2, 0.3, 0.4])]) x = xr.DataArray([[0.5, np.nan], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [np.nan, 0.35]], dims=['z1', 'z2']) da_nan = da.interp(x=x, y=y) x = xr.DataArray([[0.5, 1], [1.5, 2.5]], dims=['z1', 'z2']) y = xr.DataArray([[0.15, 0.2], [0.25, 0.35]], dims=['z1', 'z2']) da_nonan = da.interp(x=x, y=y) print('da_nan \n', da_nan) print('da_nonan \n', da_nonan) ``` ### Output ``` E:\miniconda3\envs\satpy\lib\site-packages\scipy\interpolate\interpolate.py:2539: RuntimeWarning: invalid value encountered in less out_of_bounds += x < grid[0] E:\miniconda3\envs\satpy\lib\site-packages\scipy\interpolate\interpolate.py:2540: RuntimeWarning: invalid value encountered in greater out_of_bounds += x > grid[-1] da_nan array([[ 0.55626357, nan], [ nan, -0.46643289]]) Coordinates: x (z1, z2) float64 0.5 nan 1.5 2.5 y (z1, z2) float64 0.15 0.2 nan 0.35 Dimensions without coordinates: z1, z2 da_nonan array([[ 0.55626357, 0.99749499], [ 0.63496063, -0.46643289]]) Coordinates: x (z1, z2) float64 0.5 1.0 1.5 2.5 y (z1, z2) float64 0.15 0.2 0.25 0.35 Dimensions without coordinates: z1, z2 ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3924/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,pull 609108666,MDU6SXNzdWU2MDkxMDg2NjY=,4016,Concatenate DataArrays on one dim when another dim has difference sizes,30388627,closed,0,,,8,2020-04-29T14:36:10Z,2020-05-06T00:54:39Z,2020-04-30T12:12:11Z,NONE,,,,"It's impossible to concatenate two arrays on same named dimensions with different sizes. #### MCVE Code Sample ```python import xarray as xr import pandas as pd a = xr.DataArray([0], dims=['x']) b = xr.DataArray([1, 2, 3], dims=['x']) a = a.expand_dims(""time"") b = b.expand_dims(""time"") a.coords[""time""] = pd.DatetimeIndex(['2020-02-14 05:25:10']) b.coords[""time""] = pd.DatetimeIndex(['2020-02-14 05:25:10']) c = xr.concat([a, b], dim='time') print(c) ``` #### Expected Output ``` [[0], [1, 2, 3]] ``` #### Problem Description ``` File ""C:\Users\Xin\Desktop\test_github.py"", line 10, in c = xr.concat([a, b], dim='time') File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 135, in concat return f(objs, dim, data_vars, coords, compat, positions, fill_value, join) File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 455, in _dataarray_concat join=join, File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\concat.py"", line 319, in _dataset_concat *datasets, join=join, copy=False, exclude=[dim], fill_value=fill_value File ""E:\miniconda3\envs\satpy\lib\site-packages\xarray\core\alignment.py"", line 327, in align % (dim, sizes) ValueError: arguments without labels along dimension 'x' cannot be aligned because they have different dimension sizes: {1, 3} ``` #### Versions
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 21:48:41) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None libhdf5: 1.10.5 libnetcdf: 4.7.3 xarray: 0.15.1 pandas: 1.0.3 numpy: 1.18.1 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: 2.4.0 cftime: 1.1.1.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.3 cfgrib: None iris: None bottleneck: None dask: 2.10.1 distributed: 2.14.0 matplotlib: 3.2.1 cartopy: 0.17.0 seaborn: 0.10.0 numbagg: None setuptools: 46.1.3.post20200325 pip: 20.0.2 conda: None pytest: None IPython: 7.13.0 sphinx: 2.4.4
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4016/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 595900209,MDU6SXNzdWU1OTU5MDAyMDk=,3949,Index 3D array with index of last axis stored in 2D array,30388627,closed,0,,,2,2020-04-07T14:13:39Z,2020-04-07T14:30:12Z,2020-04-07T14:30:12Z,NONE,,,,"This is copied from a [question](https://stackoverflow.com/questions/32089973/numpy-index-3d-array-with-index-of-last-axis-stored-in-2d-array) on stackoverflow. > I have a `ndarray` of `shape(z,y,x)` containing values. I am trying to index this array with another `ndarray` of `shape(y,x)` that contains the z-index of the value I am interested in. > How do I have to index `val_arr` with `z_indices` to get the values at the desired z-axis position? #### MCVE Code Sample ```python import numpy as np val_arr = np.arange(27).reshape(3, 3, 3) z_indices = np.array([[1, 0, 2], [0, 0, 1], [2, 0, 1]]) index_array = z_indices.choose(val_arr) print(index_array) ``` #### xarray version ```python import numpy as np import xarray as xr val_arr = xr.DataArray(np.arange(27).reshape(3, 3, 3), dims=['z', 'y', 'x']) z_indices = xr.DataArray(np.array([[1, 0, 2], [0, 0, 1], [2, 0, 1]]), dims=['y', 'x']) index_array = np.choose(z_indices, val_arr) print(index_array) ``` #### Expected Output ``` array([[ 9, 1, 20], [ 3, 4, 14], [24, 7, 17]]) Dimensions without coordinates: y, x ``` #### Problem Description Is this feature of `choose` supported in xarray? ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3949/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 594900245,MDU6SXNzdWU1OTQ5MDAyNDU=,3941,Sum based on start_index and end_index array,30388627,closed,0,,,5,2020-04-06T08:15:57Z,2020-04-07T02:45:26Z,2020-04-07T02:45:26Z,NONE,,,,"I have three arrays: 1. `a`: input array 2. `sindex`: the array containing the start index for summation 3. `eindex`: the array containing the end index for summation #### MCVE Code Sample ```python import xarray as xr data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) # input array a = xr.DataArray(data, dims=['x', 'y']) # start_index array sindex = xr.DataArray(np.array([0, 0, 1, 1]), dims=['x']) # end_index array eindex = xr.DataArray(np.array([0, 1, 2, 2]), dims=['x']) # empty array for saving summation sum_a = xr.DataArray(np.empty((a.shape[0], 1)), dims=['x', 'y']) for x in a.x: # sum values from sindex to eindex at row x sum_a[x] = a[x, sindex[x].values:eindex[x].values+1].sum() print(sum_a) ``` #### Expected Output ``` array([[ 1.], [ 9.], [17.], [23.]]) Dimensions without coordinates: x, y ``` #### Problem Description Is it necessary to use `xr.apply_ufunc`? or any other good method?","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3941/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 593770078,MDU6SXNzdWU1OTM3NzAwNzg=,3931,Interpolate 3D array by another 3D array,30388627,closed,0,,,10,2020-04-04T08:09:07Z,2020-04-05T01:22:44Z,2020-04-05T01:22:44Z,NONE,,,,"I have two data: 1. 3D data with z(height) levels 2. 3D pressure data which are at the same levels Then, I want to interpolate the first 3D data to another 3D pressure data. I have to iterate through `x`, `y` and interpolate the data by pressure levels. This is too slow when the 3D array is large. Is there a more efficient and easier method to accomplish this? #### MCVE Code Sample ```python import xarray as xr import numpy as np x = 10 y = 10 z = 4 data = np.arange(x*y*z).reshape((x, y, z)) # bottom_up data bottom_up = xr.DataArray(data, coords={'x': np.arange(x), 'y': np.arange(y), 'z': np.arange(z)}, dims=['x', 'y', 'z'] ) # corresponding pressure data pressure = xr.DataArray(data+1, coords={'x': np.arange(x), 'y': np.arange(y), 'z': np.arange(z)}, dims=['x', 'y', 'z'] ) # pressure levels which data are interpolated to interp_p = xr.DataArray(data[:, :, :-2]+0.5, coords={'x': np.arange(x), 'y': np.arange(y), 'z': np.arange(z-2)}, dims=['x', 'y', 'z']) # empty DataArray where interpolated values are saved output = interp_p.copy(data=np.full_like(interp_p, np.nan)) # iterate through x and y for x in bottom_up.x: for y in bottom_up.y: # replace bottom_up with pressure bottom_up = bottom_up.assign_coords(z=(pressure[x, y, :]).values) # interpolate data to interpolated pressure levels output[x, y, :] = bottom_up[x, y, :].interp(z=interp_p[x, y, :], kwargs={'fill_value': 'extrapolate'} ) print(output) ```","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3931/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 507658070,MDU6SXNzdWU1MDc2NTgwNzA=,3407,Save 'S1' array without the char_dim_name dimension,30388627,closed,0,,,2,2019-10-16T07:04:47Z,2019-10-16T08:55:02Z,2019-10-16T08:55:01Z,NONE,,,,"#### MCVE Code Sample ```python import numpy as np import xarray as xr tstr='2019-07-25_00:00:00' Times = xr.DataArray(np.array(["" "".join(tstr).split()], dtype = 'S1'), dims = ['Time', 'DateStrLen']) ds = xr.Dataset({'Times':Times}) ds.to_netcdf('test.nc', format='NETCDF4',encoding={'Times': {'zlib':True, 'complevel':5}}, unlimited_dims={'Time':True}) ``` #### Expected Output Because I want to use the nc file as the input of WRF model, I just need `Time` and `DateStrLen` two dimensions. `ncdump -h test.nc`: ``` netcdf test { dimensions: Time = UNLIMITED ; // (1 currently) DateStrLen = 19 ; variables: char Times(Time, DateStrLen) ; } ``` Although it's possible to set the exact `char_dim_name` to `Time` like #2895, but I need the unlimited `Time` dimension as the first one. #### Problem Description This is the actual output of `ncdump -h test.nc`: ``` netcdf test { dimensions: Time = UNLIMITED ; // (1 currently) DateStrLen = 19 ; string1 = 1 ; variables: char Times(Time, DateStrLen, string1) ; } ``` #### Output of ``xr.show_versions()``
INSTALLED VERSIONS ------------------ commit: None python: 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 19:07:31) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 3.0.76-0.11-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.1 libnetcdf: 4.4.1.1 xarray: 0.13.0 pandas: 0.25.1 numpy: 1.17.2 scipy: 1.3.1 netCDF4: 1.3.1 pydap: None h5netcdf: None h5py: 2.8.0 Nio: None zarr: 2.3.2 cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.5.0 distributed: 2.5.2 matplotlib: 3.1.1 cartopy: 0.17.0 seaborn: None numbagg: None setuptools: 41.2.0 pip: 19.2.3 conda: None pytest: None IPython: 7.8.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3407/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 490593787,MDU6SXNzdWU0OTA1OTM3ODc=,3290,Using min() with skipna=True,30388627,closed,0,,,8,2019-09-07T05:20:54Z,2019-09-08T02:52:57Z,2019-09-08T02:52:56Z,NONE,,,,"#### MCVE Code Sample ```python from datetime impo rt datetime import xarray as xr import os def read_data(f, composition, west, east, north, south): # read data ds = xr.open_dataset(f, group='PRODUCT') # subset to region index = ((ds.longitude > west) & (ds.longitude < east)) ds = ds.where(index) # read composition data = ds[composition][0,:,:] data_units = data.units # read time t = ds['time_utc'] st = datetime.strptime(str(t.min(skipna=True).values), '%Y-%m-%dT%H:%M:%S.%fZ') et = datetime.strptime(str(t.max(skipna=True).values), '%Y-%m-%dT%H:%M:%S.%fZ') # read lon and lat lon = data.coords['longitude'] lat = data.coords['latitude'] return lon, lat, data, data_units, st, et datadir = '/xin/data/TROPOMI/GZ/bug' os.chdir(datadir) west = 112.5; east = 114.5; north = 24; south = 22.5; f = 'S5P_NRTI_L2__O3_____20190825T053303_20190825T053803_09659_01_010107_20190825T061441.nc' lon, lat, data, data_units, st, et = read_data(f, 'ozone_total_vertical_column', west, east, north, south) ``` #### Problem Description You can download the data from [google drive](https://drive.google.com/file/d/1JY6cjViJ-_qkBYqgxUvUfRp0rRqfbpvw/view?usp=sharing). I get errors shown in details, even using `skipna=True`.
Traceback (most recent call last): File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/duck_array_ops.py"", line 236, in f return func(values, axis=axis, **kwargs) File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/nanops.py"", line 77, in nanmin 'min', dtypes.get_pos_infinity(a.dtype), a, axis) File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/nanops.py"", line 69, in _nan_minmax_object data = dtypes.fill_value(value.dtype) if valid_count == 0 else data AttributeError: module 'xarray.core.dtypes' has no attribute 'fill_value' During handling of the above exception, another exception occurred: Traceback (most recent call last): File ""bug.py"", line 31, in west, east, north, south) File ""bug.py"", line 16, in read_data st = datetime.strptime(str(t.min(skipna=True).values), '%Y-%m-%dT%H:%M:%S.%fZ') File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/common.py"", line 25, in wrapped_func skipna=skipna, allow_lazy=True, **kwargs) File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/dataarray.py"", line 1597, in reduce var = self.variable.reduce(func, dim, axis, keep_attrs, **kwargs) File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/variable.py"", line 1354, in reduce axis=axis, **kwargs) File ""/public/software/anaconda/anaconda3/envs/behr/lib/python3.6/site-packages/xarray-0.11.3-py3.6.egg/xarray/core/duck_array_ops.py"", line 249, in f raise NotImplementedError(msg) NotImplementedError: min is not available with skipna=False with the installed version of numpy; upgrade to numpy 1.12 or newer to use skipna=True or skipna=None
#### Output of ``xr.show_versions()``
# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.7 | packaged by conda-forge | (default, Feb 20 2019, 02:51:38) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 3.0.76-0.11-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.2 xarray: 0.11.3 pandas: 0.20.3 numpy: 1.13.1 scipy: 0.19.1 netCDF4: 1.4.2 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 PseudonetCDF: None rasterio: 1.0.21 cfgrib: None iris: None bottleneck: None cyordereddict: None dask: 1.1.2 distributed: None matplotlib: 3.0.3 cartopy: 0.17.0 seaborn: 0.9.0 setuptools: 36.4.0 pip: 9.0.1 conda: None pytest: None IPython: None sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/3290/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 405244302,MDU6SXNzdWU0MDUyNDQzMDI=,2731,Can't access variables in the subgroup,30388627,closed,0,,,1,2019-01-31T13:24:51Z,2019-01-31T21:57:57Z,2019-01-31T21:57:57Z,NONE,,,,"#### Code Sample ```python import xarray as xr from netCDF4 import Dataset rootgrp = Dataset(""test.nc"", ""w"", format=""NETCDF4"") fcstgrp = rootgrp.createGroup(""forecasts"") lat = rootgrp.createDimension(""lat"", 73) lon = rootgrp.createDimension(""lon"", 144) latitudes = rootgrp.createVariable(""lat"",""f4"",(""lat"",)) longitudes = rootgrp.createVariable(""lon"",""f4"",(""lon"",)) temp = rootgrp.createVariable(""temp"",""f4"",(""lat"",""lon"",)) ftemp = rootgrp.createVariable(""/forecasts/temp"",""f4"",""lat"",""lon"",) rootgrp.close() ds = xr.open_dataset('test.nc') print (ds['temp']) print (ds['/forecasts/temp']) ``` #### Problem description The `temp` variable in the `/` group can be accessed successfully, but `temp` in the `/forecasts` group not. It says: ``` KeyError: '/forecasts/temp' ``` #### Output of ``xr.show_versions()``
INSTALLED VERSIONS ------------------ commit: None python: 3.6.8.final.0 python-bits: 64 OS: Linux OS-release: 4.9.0-8-amd64 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_US.utf8 LOCALE: en_US.UTF-8 xarray: 0.11.0 pandas: 0.23.4 numpy: 1.15.4 scipy: 1.1.0 netCDF4: 1.4.2 h5netcdf: 0.5.1 h5py: 2.8.0 Nio: None zarr: None cftime: 1.0.0 PseudonetCDF: None rasterio: None iris: 2.2.0 bottleneck: 1.2.1 cyordereddict: None dask: 0.16.1 distributed: 1.20.2 matplotlib: 3.0.2 cartopy: 0.17.0 seaborn: 0.8.1 setuptools: 38.4.0 pip: 18.1 conda: 4.6.1 pytest: 3.3.2 IPython: 6.2.1 sphinx: 1.6.6
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2731/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 394625579,MDU6SXNzdWUzOTQ2MjU1Nzk=,2636,open_mfdataset change the attributes of Coordinates,30388627,closed,0,,,6,2018-12-28T12:24:01Z,2018-12-29T23:47:42Z,2018-12-29T23:47:42Z,NONE,,,,"#### Code Sample ```python import xarray as xr import numpy as np from netCDF4 import Dataset temp = np.random.randn(2, 2, 3) precip = np.random.rand(2, 2, 3) lon = [[-99.83, -99.32], [-99.79, -99.23]] lat = [[42.25, 42.21], [42.63, 42.59]] attrs = {'units': 'hours since 2015-01-01'} ds_1 = xr.Dataset({'temperature': (['x', 'y', 'time'], temp)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': ('time', [100, 101, 102], attrs)}) ds_2 = xr.Dataset({'temperature': (['x', 'y', 'time'], temp+1)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': ('time', [200, 201, 202], attrs)}) ds_1.to_netcdf('ds1.nc') ds_2.to_netcdf('ds2.nc') ds = xr.open_mfdataset('ds*.nc') ds.to_netcdf('merge.nc') with xr.open_dataset('merge.nc') as f: print (f,'\n') print ('---------------------------') ds_1 = Dataset('ds1.nc') print ('keys of ds_1:') print (ds_1.variables.keys(),'\n') print ('time of ds_1:') print (ds_1.variables['time'],'\n') print ('---------------------------') merge = Dataset('merge.nc') print ('keys of merge:') print (merge.variables.keys(),'\n') print ('time of merge:') print (merge.variables['time'],'\n') ``` #### Problem description As `time` is the **coordinate** in *xarray.Dataset*, it's **variable** in *netCDF4*. When *netCDF4* is used to read `time` of merged file , the units is `hours since 2015-01-05 04:00:00`. I want to keep the attributes of `time` as `hours since 2015-01-01`. #### Output of ``all print()`` ``` Dimensions: (time: 6, x: 2, y: 2) Coordinates: lon (x, y) float64 ... lat (x, y) float64 ... * time (time) datetime64[ns] 2015-01-05T04:00:00 ... Dimensions without coordinates: x, y Data variables: temperature (x, y, time) float64 ... --------------------------- keys of ds_1: odict_keys(['temperature', 'lon', 'lat', 'time']) time of ds_1: int64 time(time) units: hours since 2015-01-01 unlimited dimensions: current shape = (3,) filling on, default _FillValue of -9223372036854775806 used --------------------------- keys of merge: odict_keys(['lon', 'lat', 'temperature', 'time']) time of merge: int64 time(time) units: hours since 2015-01-05 04:00:00 calendar: proleptic_gregorian unlimited dimensions: current shape = (6,) filling on, default _FillValue of -9223372036854775806 used ``` ","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2636/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue