NVIDIA / NVIDIA/cudf

[FEA] support passing label to value_counts()

Open
#12,565 0 comments 0 reactions 0 assignees View on GitHub
0 - Backlog feature request Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Is your feature request related to a problem? Please describe.**
working with `import cudf as pd`

**Describe the solution you'd like**
matching behavior with `pandas`
```
In [1]: import cudf as pd

In [2]: pd.__version__
Out[2]: '22.12.00'

In [3]: df = pd.DataFrame({"XYZ": ["foo", "foo", "foo", "foo", "foo"]})

In [4]: df.value_counts("XYZ")
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[4], line 1
----> 1 df.value_counts("XYZ")

File /usr/local/lib/python3.8/dist-packages/cudf/core/dataframe.py:7188, in DataFrame.value_counts(self, subset, normalize, sort, ascending, dropna)
7186 diff = set(subset) - set(self._data)
7187 if len(diff) != 0:
-> 7188 raise KeyError(f"columns {diff} do not exist")
7189 columns = list(self._data.names) if subset is None else subset
7190 result = (
7191 self.groupby(
7192 by=columns,
(...)
7196 .astype("int64")
7197 )

KeyError: "columns {'Y', 'X', 'Z'} do not exist"

In [5]: df.to_pandas().value_counts("XYZ")
Out[5]:
XYZ
foo 5
dtype: int64
```

**Additional context**
[`pandas.DataFrame.value_counts`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.value_counts.html) declares support for `list-like` input, but is [implemented](https://github.com/pandas-dev/pandas/blob/v1.5.2/pandas/core/frame.py#L7215) with [`pandas.DataFrame.groupby`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html), which accepts `mapping, function, label, or list of labels`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.