{DataArray,Dataset}.rank() should support an optional list of dimensions
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
{DataArray,Dataset}.rank() requires a single dim. Why not support an optional list of dimensions (defaulting to all)?
In [1]: import numpy as np, xarray as xr
In [2]: d = xr.DataArray(np.arange(12).reshape((4,3)), dims=('abc', 'xyz'))
In [3]: d
Out[3]:
<xarray.DataArray (abc: 4, xyz: 3)>
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11]])
Dimensions without coordinates: abc, xyz
In [4]: d.rank()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-585571c1eca8> in <module>
----> 1 d.rank()
TypeError: rank() missing 1 required positional argument: 'dim'
In [5]: d.rank(dim=('xyz', 'abc'))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-006c73551ff8> in <module>
----> 1 d.rank(dim=('xyz', 'abc'))
~/.conda/envs/build/lib/python3.7/site-packages/xarray/core/dataarray.py in rank(self, dim, pct, keep_attrs)
3054 """
3055
-> 3056 ds = self._to_temp_dataset().rank(dim, pct=pct, keep_attrs=keep_attrs)
3057 return self._from_temp_dataset(ds)
3058
~/.conda/envs/build/lib/python3.7/site-packages/xarray/core/dataset.py in rank(self, dim, pct, keep_attrs)
5295 """
5296 if dim not in self.dims:
-> 5297 raise ValueError("Dataset does not contain the dimension: %s" % dim)
5298
5299 variables = {}
TypeError: not all arguments converted during string formatting
In [6]: xr.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.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.5
libnetcdf: 4.7.3
xarray: 0.15.0
pandas: 1.0.1
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: 0.8.0
h5py: 2.10.0
Nio: None
zarr: None
cftime: 1.0.4.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2.11.0
distributed: 2.11.0
matplotlib: 3.1.3
cartopy: None
seaborn: 0.10.0
numbagg: installed
setuptools: 45.2.0.post20200209
pip: 20.0.2
conda: 4.8.2
pytest: None
IPython: 7.12.0
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the DataArray.rank and Dataset.rank entry points described in the issue, then reproduce the provided NumPy/xarray example. Check how rank currently validates dim and add coverage for no dimension, a list of dimensions, and the existing single-dimension behavior; done means the requested calls work without the shown TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100