-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Fix #60766:.map,.apply would convert element type for extension array #61396
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
base: main
Are you sure you want to change the base?
Changes from all commits
f8153f3
bf6aaef
e8edcea
d845306
ef9812e
8222c21
f4df033
9e97dba
1cf2604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from pandas import ( | ||
NA, | ||
Series, | ||
isna, | ||
) | ||
from pandas.testing import assert_series_equal | ||
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. use tm.assert_series_equal |
||
|
||
|
||
def test_basemaskedarray_map(): | ||
s = Series([1, 2, None, 4], dtype="Int32") | ||
|
||
def transform(x): | ||
if isna(x): | ||
return x | ||
return x + 1 | ||
|
||
result = s.map(transform) | ||
expected = Series([2, 3, NA, 5], dtype=result.dtype) | ||
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. can you be explicit about the expected dtype. i.e. is it Int32? |
||
|
||
assert_series_equal(result, expected) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,12 @@ 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.kind != "b": | ||
for i in range(len(result)): | ||
if result[i] is pd.NA: | ||
result[i] = "nan" | ||
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. isnt this pretty unwanted behavior? |
||
result = result.astype("float64") | ||
|
||
if data_missing.dtype == Float32Dtype(): | ||
# map roundtrips through objects, which converts to float64 | ||
expected = data_missing.to_numpy(dtype="float64", na_value=np.nan) | ||
|
@@ -184,7 +190,7 @@ def test_map_na_action_ignore(self, data_missing_for_sorting): | |
if data_missing_for_sorting.dtype.kind == "b": | ||
expected = np.array([False, pd.NA, False], dtype=object) | ||
else: | ||
expected = np.array([zero, np.nan, zero]) | ||
expected = np.array([zero, pd.NA, zero]) | ||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def _get_expected_exception(self, op_name, obj, other): | ||
|
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.
can you name this file just
test_map.py