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 1183858748,I_kwDOAMm_X85GkEA8,6424,DataArray.plot.contourf() fails when data has no positive values,42851573,closed,0,,,3,2022-03-28T19:00:33Z,2022-03-30T14:28:51Z,2022-03-30T14:28:51Z,NONE,,,,"### What happened? For a DataArray with no positive values, the `plot.contourf()` fails to produce the correct figure. It makes the contourf plot and returns successfully, but emits several warnings and does not complete the colorbar. Two sample screenshots are in \
below. The `plot.contour()` function has the same behavior, but only when `add_colorbar=True`. ### What did you expect to happen? _No response_ ### Minimal Complete Verifiable Example ```Python import xarray as XR da = xr.DataArray(np.arange(20).reshape(4,5), dims=('x','y')) da.plot.contourf() # successful (first image below) (da-19).plot.contourf() # fails (second image below) ``` ### Relevant log output ```Python > da = xr.DataArray(np.arange(20).reshape(4,5), dims=('x','y')) > da array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]) Dimensions without coordinates: x, y > da.plot.contourf() # successful (first image below) > (da-18).plot.contourf() # successful > (da-19).plot.contourf() # fails (second image below) ~/miniconda3/envs/plots/lib/python3.9/site-packages/matplotlib/transforms.py:2663: RuntimeWarning: divide by zero encountered in double_scalars y_scale = 1.0 / inh ~/miniconda3/envs/plots/lib/python3.9/site-packages/matplotlib/transforms.py:2665: RuntimeWarning: invalid value encountered in double_scalars [0.0 , y_scale, (-inb*y_scale)], posx and posy should be finite values posx and posy should be finite values posx and posy should be finite values posx and posy should be finite values > da-19 array([[-19, -18, -17, -16, -15], [-14, -13, -12, -11, -10], [ -9, -8, -7, -6, -5], [ -4, -3, -2, -1, 0]]) Dimensions without coordinates: x, y ``` ### Anything else we need to know?
Screenshots of plots ```python > da.plot.contourf() # successful ``` ```python > (da-19).plot.contourf() # fails ```
### Environment
xr.show_versions() miniconda3/envs/plots/lib/python3.9/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils. warnings.warn(""Setuptools is replacing distutils."") INSTALLED VERSIONS ------------------ commit: None python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:14) [Clang 12.0.1 ] python-bits: 64 OS: Darwin OS-release: 21.3.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 2022.3.0 pandas: 1.3.5 numpy: 1.21.5 scipy: 1.7.1 netCDF4: 1.5.7 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.4 dask: 2022.03.0 distributed: None matplotlib: 3.5.0 cartopy: 0.20.2 seaborn: None numbagg: None fsspec: 2022.02.0 cupy: None pint: None sparse: None setuptools: 61.2.0 pip: 22.0.4 conda: None pytest: None IPython: 7.29.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6424/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue 1124596666,I_kwDOAMm_X85DB_u6,6238,[API]: inconsistent `rename` for DataArray vs Dataset,42851573,open,0,,,1,2022-02-04T20:37:34Z,2022-03-16T04:19:44Z,,NONE,,,,"### What happened? The DataArray.rename API is inconsistent with Dataset.rename and the documentation does not make that obvious. Unlike Dataset.rename, * A DataArray cannot be renamed using a keyword argument, but fails saying ""[name] is not a variable or dimension in this dataset"" (example A below). * Passing the new name as a positional argument, but with other keyword arguments fails with the statement ""the first argument to .rename must be a dictionary"" (example B below). * As a consequence, renaming the array as well as its dimension(s)/coordinate(s) requires two separate function calls, i.e. `da.rename(""newname"").rename(""dim_0""=""x"")`. Examples --------- Start with an array, da, and a dataset, ds ```python >>> da = xr.DataArray( np.zeros((2,3)), name=""alpha"", coords={""x"":range(2), ""y"":range(3)} ) >>> da array([[0., 0., 0.], [0., 0., 0.]]) Coordinates: * x (x) int64 0 1 * y (y) int64 0 1 2 >>> ds = xr.Dataset({""alpha"":da}) >>> ds Dimensions: (x: 2, y: 3) Coordinates: * x (x) int64 0 1 * y (y) int64 0 1 2 Data variables: alpha (x, y) float64 0.0 0.0 0.0 0.0 0.0 0.0 ``` **Dataset example** ds.rename renames everything at once using keyword arguments ```python >>> ds.rename(x=""i"", y=""j"", alpha=""beta"") Dimensions: (i: 2, j: 3) Coordinates: * i (i) int64 0 1 * j (j) int64 0 1 2 Data variables: beta (i, j) float64 0.0 0.0 0.0 0.0 0.0 0.0 ``` **Example A** da.rename does not recognize the array's current name as a keyword and returns a confusing error message. ```python >>> da.rename(alpha=""beta"") --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in ----> 1 da.rename(alpha=""beta"", x=""i"") xarray/core/dataarray.py in rename(self, new_name_or_name_dict, **names) 1842 ) 1843 name_dict = either_dict_or_kwargs(new_name_or_name_dict, names, ""rename"") -> 1844 dataset = self._to_temp_dataset().rename(name_dict) 1845 return self._from_temp_dataset(dataset) 1846 else: xarray/core/dataset.py in rename(self, name_dict, **names) 3390 for k in name_dict.keys(): 3391 if k not in self and k not in self.dims: -> 3392 raise ValueError( 3393 f""cannot rename {k!r} because it is not a "" 3394 ""variable or dimension in this dataset"" ValueError: cannot rename 'alpha' because it is not a variable or dimension in this dataset ``` **Example B** da.rename will not change the name of the array as well as the dimension(s)/coordinate(s) names and emits an untrue error message, since the array cannot be renamed using a dict. ```python >>> da.rename(""beta"", x=""i"") --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in ----> 1 da.rename(""beta"", x=""i"") xarray/core/dataarray.py in rename(self, new_name_or_name_dict, **names) 1841 Mapping[Hashable, Hashable], new_name_or_name_dict 1842 ) -> 1843 name_dict = either_dict_or_kwargs(new_name_or_name_dict, names, ""rename"") 1844 dataset = self._to_temp_dataset().rename(name_dict) 1845 return self._from_temp_dataset(dataset) xarray/core/utils.py in either_dict_or_kwargs(pos_kwargs, kw_kwargs, func_name) 284 285 if not is_dict_like(pos_kwargs): --> 286 raise ValueError(f""the first argument to .{func_name} must be a dictionary"") 287 if kw_kwargs: 288 raise ValueError( ValueError: the first argument to .rename must be a dictionary ``` ### What did you expect to happen? _No response_ ### Minimal Complete Verifiable Example _No response_ ### Relevant log output _No response_ ### Anything else we need to know? _No response_ ### Environment INSTALLED VERSIONS ------------------ commit: None python: 3.9.10 | packaged by conda-forge | (main, Feb 1 2022, 21:25:34) [Clang 11.1.0 ] python-bits: 64 OS: Darwin OS-release: 21.1.0 machine: arm64 processor: arm 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.21.1 pandas: 1.3.5 numpy: 1.22.2 scipy: 1.7.1 netCDF4: 1.5.7 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.5.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: None distributed: None matplotlib: 3.5.0 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None setuptools: 60.7.1 pip: 22.0.3 conda: None pytest: None IPython: 7.29.0 sphinx: None","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/6238/reactions"", ""total_count"": 2, ""+1"": 2, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue