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

[BUG] .str.replace leading to data-corruption when a non-string is passed #17745

Open
galipremsagar opened this issue Jan 15, 2025 · 0 comments
Assignees
Labels
bug Something isn't working Python Affects Python cuDF API.

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
When the replacement value is not a string, there appears to be a data-corruption in .str.replace

Steps/Code to reproduce bug

In [1]: import cudf

In [2]: idx = cudf.Index(['a', 'b', 'c'])

In [3]: idx.str.replace("a", 3)
Out[3]: Index(['', 'b', 'c'], dtype='object')

In [4]: idx.to_pandas().str.replace("a", 3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 idx.to_pandas().str.replace("a", 3)

File /datasets/pgali/envs/cudfdev/lib/python3.12/site-packages/pandas/core/strings/accessor.py:137, in forbid_nonstring_types.<locals>._forbid_nonstring_types.<locals>.wrapper(self, *args, **kwargs)
    132     msg = (
    133         f"Cannot use .str.{func_name} with values of "
    134         f"inferred dtype '{self._inferred_dtype}'."
    135     )
    136     raise TypeError(msg)
--> 137 return func(self, *args, **kwargs)

File /datasets/pgali/envs/cudfdev/lib/python3.12/site-packages/pandas/core/strings/accessor.py:1548, in StringMethods.replace(self, pat, repl, n, case, flags, regex)
   1546 # Check whether repl is valid (GH 13438, GH 15055)
   1547 if not (isinstance(repl, str) or callable(repl)):
-> 1548     raise TypeError("repl must be a string or callable")
   1550 is_compiled_re = is_re(pat)
   1551 if regex or regex is None:

TypeError: repl must be a string or callable
@galipremsagar galipremsagar added bug Something isn't working Python Affects Python cuDF API. labels Jan 15, 2025
@galipremsagar galipremsagar self-assigned this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Python Affects Python cuDF API.
Projects
Status: Todo
Development

No branches or pull requests

1 participant