NVIDIA / NVIDIA/cudf

[FEA] allow `Series.clip` to clip accept Series as lower and upper bounds

Open
#17,682 1 comment 0 reactions 0 assignees View on GitHub
feature request Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

```python
import cudf

data = {"a": [1, 2, 3, -4, 5], "lb": [3, 2, 1, 1, 1], "ub": [4, 4, 2, 2, 2]}
df = cudf.DataFrame(data)
df["a"].clip(df["lb"], df["ub"] + 1)
```
```python-traceback
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
3 data = {"a": [1, 2, 3, -4, 5], "lb": [3, 2, 1, 1, 1], "ub": [4, 4, 2, 2, 2]}
4 df = cudf.DataFrame(data)
----> 5 df["a"].clip(df["lb"], df["ub"] + 1)

/usr/local/lib/python3.10/dist-packages/cudf/utils/performance_tracking.py in wrapper(*args, **kwargs)
49 )
50 )
---> 51 return func(*args, **kwargs)
52
53 return wrapper

/usr/local/lib/python3.10/dist-packages/cudf/core/indexed_frame.py in clip(self, lower, upper, axis, inplace)
1004
1005 if len(lower) != self._num_columns:
-> 1006 raise ValueError(
1007 "Length of lower/upper should be equal to number of columns"
1008 )

ValueError: Length of lower/upper should be equal to number of columns
```

expected (pandas output):
```python
0 3
1 2
2 3
3 1
4 3
Name: a, dtype: int64
```

cudf version `'25.02.00a225'`

Could you please allow clipping by Series, like pandas does?

From your unofficial QA team at [Narwhals](https://github.com/narwhals-dev/narwhals)

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.