Skip to content

Conversation

@rhshadrach
Copy link
Member

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.

@rhshadrach rhshadrach added the Bug label Feb 12, 2022
Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# GH#45954
ser = Series(dtype=object)
ser.name = "first"
try:
Copy link
Member

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"):
        ...
    

Copy link
Member Author

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.

@jreback jreback added this to the 1.5 milestone Feb 16, 2022
@jreback jreback merged commit 43ca51f into pandas-dev:main Feb 16, 2022
@jreback
Copy link
Contributor

jreback commented Feb 16, 2022

thanks @rhshadrach

@rhshadrach rhshadrach deleted the temp_setattr_fixup branch February 16, 2022 13:28
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants