-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
BUG: Fix implementation of temp_setattr #45954
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
Conversation
jbrockmendel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
pandas/tests/test_common.py
Outdated
| # GH#45954 | ||
| ser = Series(dtype=object) | ||
| ser.name = "first" | ||
| try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit more robust to validate the error raised:
if with_exception:
maybe_raises = pytest.raises(ValueError, match="Exception raised")
else:
maybe_raises = contextlib.nullcontext()
with maybe_raises:
with com.temp_setattr(ser, "name", "second"):
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! flake8 didn't like using pytest.raises outside a context manager; raising in either case made it a little simpler.
|
thanks @rhshadrach |
Doesn't fix any user-facing bug (at least, that I'm aware of), but the current implementation will not restore the original attribute if an exception is raised within the context manager.