Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MarcoGorelli opened this issue Jan 5, 2025 · 1 comment
Labels
feature request New feature or request Python Affects Python cuDF API.

Comments

@MarcoGorelli
Copy link
Contributor

MarcoGorelli commented Jan 5, 2025

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)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-27928310299f> in <cell line: 5>()
      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):

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

@MarcoGorelli MarcoGorelli added the bug Something isn't working label Jan 5, 2025
@MarcoGorelli MarcoGorelli changed the title [BUG] clip with two Series as arguments produces ValueError, even though docs says it accepts array-like [FEA] clip with two Series as arguments produces ValueError, even though docs says it accepts array-like Jan 5, 2025
@MarcoGorelli MarcoGorelli changed the title [FEA] clip with two Series as arguments produces ValueError, even though docs says it accepts array-like [FEA] allow Series.clip to clip accept Series as lower and upper bounds Jan 5, 2025
@mroeschke mroeschke added feature request New feature or request Python Affects Python cuDF API. and removed bug Something isn't working labels Jan 6, 2025
@mroeschke
Copy link
Contributor

Thanks for the report.

Going to relabel as a feature request as this probably should be considered NotImplmentedError yet as the docs state

In case of Series/Index, lower is expected to be a scalar or an array of size 1

It appears the cuda kernel only supports cliping by a scalar value per column and would need to also support element-wise cliping by an equal length array-like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Python Affects Python cuDF API.
Projects
Status: Todo
Development

No branches or pull requests

2 participants