-
-
Notifications
You must be signed in to change notification settings - Fork 20k
Fix: EA attribute specifying whether copy=False is ignored #63130
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 15 commits
43be6b7
251ff22
0d8bae3
0df38db
453b25f
5421db1
3f6333e
964a6d2
1bf16a2
871f164
33f796f
b7325fa
cbf76eb
5a373d5
4178f66
963bd84
d0bc508
e3da0bc
cdfd705
9584cd1
7fedd5c
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
|
|
||
|
|
||
| class BaseMissingTests: | ||
| _respects_fillna_copy_false = True | ||
|
|
||
| def test_isna(self, data_missing): | ||
| expected = np.array([True, False]) | ||
|
|
||
|
|
@@ -123,18 +125,23 @@ def test_fillna_no_op_returns_copy(self, data): | |
| tm.assert_extension_array_equal(result, data) | ||
|
|
||
| def test_fillna_readonly(self, data_missing): | ||
| fill_value = data_missing[1] | ||
| data = data_missing.copy() | ||
| data._readonly = True | ||
|
|
||
| # by default fillna(copy=True), then this works fine | ||
| result = data.fillna(data_missing[1]) | ||
| assert result[0] == data_missing[1] | ||
|
Member
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 restore this line somewhere (to check that the NAs actually got filled)
Contributor
Author
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.
Member
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. That suggests that the fillna isn't actually working. That would indicate a real bug.
Contributor
Author
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. i've used llm to debug and updated with some changes and restored as per your suggestion. |
||
| res_copy = data.fillna(fill_value, copy=True) | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
|
|
||
| # but with copy=False, this raises for EAs that respect the copy keyword | ||
| with pytest.raises(ValueError, match="Cannot modify read-only array"): | ||
| data.fillna(data_missing[1], copy=False) | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
| if self._respects_fillna_copy_false: | ||
| with pytest.raises(ValueError, match="Cannot modify read-only array"): | ||
| data.fillna(fill_value, copy=False) | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
| else: | ||
| # EAs that do not respect the copy keyword, copy=False is ignored | ||
| res_no_copy = data.fillna(fill_value, copy=False) | ||
| tm.assert_extension_array_equal(res_no_copy, res_copy) | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
|
|
||
| def test_fillna_series(self, data_missing): | ||
| fill_value = data_missing[1] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,10 +299,11 @@ def convert_values(param): | |
|
|
||
| return np.asarray(res, dtype=bool) | ||
|
|
||
| # We override fillna here to simulate a 3rd party EA that has done so. This | ||
| # lets us test a 3rd-party EA that has not yet updated to include a "copy" | ||
| # keyword in its fillna method. | ||
| def fillna(self, value=None, limit=None): | ||
| # We override fillna here to simulate a 3rd-party EA that defines its own | ||
| # fillna behavior and ignores the copy keyword. | ||
| def fillna(self, value=None, limit=None, copy: bool = True): | ||
| # We intentionally ignore copy and always perform a copy to ensure | ||
| # the original array is not modified. | ||
| return super().fillna(value=value, limit=limit, copy=True) | ||
|
Member
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. pass copy=copy?
Member
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. or raise/warn if the user passes copy=False
Contributor
Author
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.
i think we can go with this . I'll update
Aniketsy marked this conversation as resolved.
|
||
|
|
||
|
|
||
|
|
||
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.
why?
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.
IntervalArray.fillnaalways copies regardless of the copy keyword, so i thinkNotImplementedErroris not needed removing this will pass without error, and behavior stays, same. I would like to know your thoughts on 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.
raising is correct here.