-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Convert to compatible NumPy dtype for MaskedArray to_numpy #55058
Conversation
I think this is pretty reasonable. Is this part of a larger set of changes or is this self-contained? Probably worth a whatsnew |
This is something we wanted to clean up for a while now, but yes I have to add a whatsnew (didn't get to it yet because this needs more than a single line) |
Added the whatsnew |
Does this close #48891? |
yep |
# Conflicts: # pandas/tests/base/test_conversion.py # pandas/tests/frame/test_repr.py
cc @mroeschke I think this is ready for a review |
pandas/io/formats/format.py
Outdated
@@ -1527,6 +1528,8 @@ def _format_strings(self) -> list[str]: | |||
if isinstance(values, Categorical): | |||
# Categorical is special for now, so that we can preserve tzinfo | |||
array = values._internal_get_values() | |||
elif isinstance(values, BaseMaskedArray): | |||
array = values.to_numpy(na_value=NA) |
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.
As I discovered in https://github.com/pandas-dev/pandas/pull/56003/files#diff-c2df0eefbdda16cb85d5e0a305db90101f92bfb790a8e989ab2e99b935b7f6b3, maybe we just want to do to_numpy(dtype=object)
here?
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.
Yep hat should work as well
@pytest.mark.parametrize("na_action", [None, "ignore"]) | ||
def test_map(self, data_missing, na_action): | ||
result = data_missing.map(lambda x: x, na_action=na_action) | ||
if data_missing.dtype == Float32Dtype(): |
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.
If there a solution to avoid this?
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.
Not with roundtripping through object, maybe your other suggestion above solves this.
No if your suggestion doesn't work
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.
Should we do the same thing for ArrowExtensionArray.to_numpy
?
# Conflicts: # doc/source/whatsnew/v2.2.0.rst
Can we get this in if ci is green now? Just merged main to resolve whatsnew conflicts |
Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Thanks @phofl |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.This still needs a whatsnew