-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
43be6b7
251ff22
0d8bae3
0df38db
453b25f
5421db1
3f6333e
964a6d2
1bf16a2
871f164
33f796f
b7325fa
cbf76eb
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: | ||
| _supports_fillna_copy_false = True | ||
|
|
||
| def test_isna(self, data_missing): | ||
| expected = np.array([True, False]) | ||
|
|
||
|
|
@@ -123,18 +125,27 @@ 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] | ||
| res_copy = data.fillna(fill_value, copy=True) | ||
| tm.assert_extension_array_equal( | ||
| res_copy, data_missing.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._supports_fillna_copy_false: | ||
| # 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(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 |
|---|---|---|
|
|
@@ -97,6 +97,8 @@ def data_for_compare(request): | |
|
|
||
|
|
||
| class TestSparseArray(base.ExtensionTests): | ||
| _supports_fillna_copy_false = False | ||
|
|
||
| def _supports_reduction(self, obj, op_name: str) -> bool: | ||
| return True | ||
|
|
||
|
|
@@ -237,21 +239,6 @@ def test_isna(self, data_missing): | |
| def test_fillna_no_op_returns_copy(self, data, request): | ||
| super().test_fillna_no_op_returns_copy(data) | ||
|
|
||
| def test_fillna_readonly(self, data_missing): | ||
|
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. getting rid of this is perfect. i think there are other subclasses that override this too that we also want to get rid of |
||
| # copy keyword is ignored by SparseArray.fillna | ||
| # -> copy=True vs False doesn't make a difference | ||
| data = data_missing.copy() | ||
| data._readonly = True | ||
|
|
||
| result = data.fillna(data_missing[1]) | ||
| assert result[0] == data_missing[1] | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
|
|
||
| # fillna(copy=False) is ignored -> so same result as above | ||
| result = data.fillna(data_missing[1], copy=False) | ||
| assert result[0] == data_missing[1] | ||
| tm.assert_extension_array_equal(data, data_missing) | ||
|
|
||
| @pytest.mark.xfail(reason="Unsupported") | ||
| def test_fillna_series(self, data_missing): | ||
| # this one looks doable. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.