NVIDIA / NVIDIA/cudf

[FEA] Allow keep='all' for nlargest/nsmallest

Open
#12,513 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.**
writing code with `import cudf as pd`

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

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

In [3]: df = pd.DataFrame({'a': [1, 2, 3] * 2, 'b': list('abcdef')})

In [4]: df.nlargest(1, 'a', keep='all')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In [4], line 1
----> 1 df.nlargest(1, 'a', keep='all')

File ~/.local/lib/python3.9/site-packages/nvtx/nvtx.py:101, in annotate.__call__..inner(*args, **kwargs)
98 @wraps(func)
99 def inner(*args, **kwargs):
100 libnvtx_push_range(self.attributes, self.domain.handle)
--> 101 result = func(*args, **kwargs)
102 libnvtx_pop_range(self.domain.handle)
103 return result

File ~/.local/lib/python3.9/site-packages/cudf/core/dataframe.py:3624, in DataFrame.nlargest(self, n, columns, keep)
3558 @_cudf_nvtx_annotate
3559 def nlargest(self, n, columns, keep="first"):
3560 """Return the first *n* rows ordered by *columns* in descending order.
3561
3562 Return the first *n* rows with the largest values in *columns*, in
(...)
3622 Brunei 434000 12128 BN
3623 """
-> 3624 return self._n_largest_or_smallest(True, n, columns, keep)

File ~/.local/lib/python3.9/site-packages/cudf/core/indexed_frame.py:2156, in IndexedFrame._n_largest_or_smallest(self, largest, n, columns, keep)
2154 return self._gather(indices, keep_index=True, check_bounds=False)
2155 else:
-> 2156 raise ValueError('keep must be either "first", "last"')

ValueError: keep must be either "first", "last"

In [5]: df.to_pandas().nlargest(1, 'a', keep='all')
Out[5]:
a b
2 3 c
5 3 f
```

**Additional context**
https://github.com/pandas-dev/pandas/pull/21650

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.