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 should not allow adding any new attribute other than defined #17750

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

Comments

@galipremsagar
Copy link
Contributor

Describe the bug
.str appears to be silently allowing adding new attributes, rather than raising an error.

Steps/Code to reproduce bug

In [1]: import cudf

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

In [3]: s.str.abc = "a"

In [5]: s.to_pandas().str.abc = "a"
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 1
----> 1 s.to_pandas().str.abc = "a"

File /datasets/pgali/envs/cudfdev/lib/python3.12/site-packages/pandas/core/base.py:177, in NoNewAttributesMixin.__setattr__(self, key, value)
    166 def __setattr__(self, key: str, value) -> None:
    167     # _cache is used by a decorator
    168     # We need to check both 1.) cls.__dict__ and 2.) getattr(self, key)
    169     # because
    170     # 1.) getattr is false for attributes that raise errors
    171     # 2.) cls.__dict__ doesn't traverse into base classes
    172     if getattr(self, "__frozen", False) and not (
    173         key == "_cache"
    174         or key in type(self).__dict__
    175         or getattr(self, key, None) is not None
    176     ):
--> 177         raise AttributeError(f"You cannot add any new attribute '{key}'")
    178     object.__setattr__(self, key, value)

AttributeError: You cannot add any new attribute 'abc'
@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
@galipremsagar galipremsagar changed the title [BUG] .str should dis-allow adding any new attribute other than defined [BUG] .str should not allow adding any new attribute other than defined 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