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.startswith need to only take str or tuple inputs #17749

Closed
galipremsagar opened this issue Jan 15, 2025 · 0 comments · Fixed by #17782
Closed

[BUG] .str.startswith need to only take str or tuple inputs #17749

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

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
.str.startswith appears to be taking inputs that are not str and tuple too. Atleast in pandas compatibility mode we need to disable allowing other input types.

Steps/Code to reproduce bug

In [1]: import cudf

In [2]: s = cudf.Series(["foo", "bar"])

In [3]: s.str.startswith(s)
Out[3]: 
0    True
1    True
dtype: bool

In [4]: s.to_pandas().str.startswith(s.to_pandas())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 s.to_pandas().str.startswith(s.to_pandas())

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:2482, in StringMethods.startswith(self, pat, na)
   2480 if not isinstance(pat, (str, tuple)):
   2481     msg = f"expected a string or tuple, not {type(pat).__name__}"
-> 2482     raise TypeError(msg)
   2483 result = self._data.array._str_startswith(pat, na=na)
   2484 return self._wrap_result(result, returns_string=False)

TypeError: expected a string or tuple, not Series
@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
@GPUtester GPUtester moved this from Todo to In Progress in cuDF Python Jan 23, 2025
@rapids-bot rapids-bot bot closed this as completed in e9bfab5 Jan 24, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in cuDF Python Jan 24, 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: Done
Development

Successfully merging a pull request may close this issue.

1 participant