-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Convert to compatible NumPy dtype for MaskedArray to_numpy #55058
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
Changes from 1 commit
c3c718c
03ff78e
2e1a696
92a509f
d55e41f
a37564a
e4618bb
72cfba1
6223938
207a0d0
8a57091
cb7ca91
5c8707a
76e86f2
90bcbe2
b39c729
26f8b38
6dde692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ | |
) | ||
|
||
from pandas.core.arrays import ( | ||
BaseMaskedArray, | ||
Categorical, | ||
DatetimeArray, | ||
TimedeltaArray, | ||
|
@@ -1660,6 +1661,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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep hat should work as well |
||
else: | ||
array = np.asarray(values) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,16 @@ def data_for_grouping(dtype): | |
|
||
|
||
class TestMaskedArrays(base.ExtensionTests): | ||
@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 commentThe 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 commentThe 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 |
||
# map roundtrips through objects, which converts to float64 | ||
expected = data_missing.to_numpy(dtype="float64", na_value=np.nan) | ||
else: | ||
expected = data_missing.to_numpy() | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def _get_expected_exception(self, op_name, obj, other): | ||
try: | ||
dtype = tm.get_dtype(obj) | ||
|
Uh oh!
There was an error while loading. Please reload this page.