-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Open
pedromfdiogo
wants to merge
9
commits into
pandas-dev:main
Choose a base branch
from
pedromfdiogo:bug#60766
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f8153f3
Fix #60766:.map,.apply would convert element type for extension array.
pedromfdiogo bf6aaef
Update v3.0.0.rst
pedromfdiogo e8edcea
fixed test_masked.py
pedromfdiogo d845306
Apply Ruff and Ruff-format auto-fixes
pedromfdiogo ef9812e
Merge branch 'main' into bug#60766
pedromfdiogo 8222c21
fixed some errors
pedromfdiogo f4df033
fixed test_map_na_action_ignore
pedromfdiogo 9e97dba
fixed space
pedromfdiogo 1cf2604
fixed spaces
pedromfdiogo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pandas as pd | ||
pedromfdiogo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def test_basemaskedarray_map(): | ||
for dtype, data, expected_data in [ | ||
("Int32", [1, 2, None, 4], [2, 3, pd.NA, 5]), | ||
]: | ||
pedromfdiogo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s = pd.Series(data, dtype=dtype) | ||
|
||
def transform(x): | ||
if x is None: | ||
return x | ||
return x + 1 | ||
|
||
result = s.map(transform) | ||
expected = pd.Series(expected_data, dtype=result.dtype) | ||
|
||
assert result.tolist() == expected.tolist() | ||
pedromfdiogo marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
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) | ||
|
@@ -181,10 +187,15 @@ def test_map(self, data_missing, na_action): | |
def test_map_na_action_ignore(self, data_missing_for_sorting): | ||
zero = data_missing_for_sorting[2] | ||
result = data_missing_for_sorting.map(lambda x: zero, na_action="ignore") | ||
|
||
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. Better to avoid this unrelated changes |
||
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]) | ||
for i in range(len(result)): | ||
if result[i] is pd.NA: | ||
result[i] = "nan" | ||
result = result.astype("float64") | ||
pedromfdiogo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tm.assert_numpy_array_equal(result, expected) | ||
|
||
def _get_expected_exception(self, op_name, obj, other): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.