Skip to content

Fix: EA attribute specifying whether copy=False is ignored#63130

Closed
Aniketsy wants to merge 21 commits into
pandas-dev:mainfrom
Aniketsy:fix-63040
Closed

Fix: EA attribute specifying whether copy=False is ignored#63130
Aniketsy wants to merge 21 commits into
pandas-dev:mainfrom
Aniketsy:fix-63040

Conversation

@Aniketsy
Copy link
Copy Markdown
Contributor

@Aniketsy Aniketsy commented Nov 16, 2025

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thank you!

@Aniketsy Aniketsy marked this pull request as draft November 16, 2025 16:13
@Aniketsy Aniketsy marked this pull request as ready for review November 19, 2025 09:58
@Aniketsy Aniketsy marked this pull request as draft November 20, 2025 11:37
@Aniketsy
Copy link
Copy Markdown
Contributor Author

@jbrockmendel Could you please take a look in this, If i'm not in wrong direction.

Comment thread pandas/tests/extension/base/missing.py Outdated
@Aniketsy Aniketsy marked this pull request as ready for review November 22, 2025 06:56
@Aniketsy
Copy link
Copy Markdown
Contributor Author

@jbrockmendel Please review these changes, whenever you get a chance.

Comment thread pandas/tests/extension/base/missing.py Outdated
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this comment should be for EAs that dont respect the copy keyword?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment in the else block for the EAs that don't respect the copy keyword.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok but isnt the comment here still wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about removing that comment earlier but wasn’t fully sure since it was written specifically for the if case. You're right, so I’ll remove it.

Comment thread pandas/tests/extension/base/missing.py Outdated
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, expected)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you keep using data_missing instead of defining a new expected. i.e. minimize the diff

Comment thread pandas/tests/extension/test_sparse.py
@Aniketsy
Copy link
Copy Markdown
Contributor Author

Aniketsy commented Dec 3, 2025

@jbrockmendel I've updated the code as per your suggestion. Please let me know if this also needs a whatsnew entry.

@Aniketsy
Copy link
Copy Markdown
Contributor Author

Aniketsy commented Dec 8, 2025

@jbrockmendel Is this PR ready now? The two ci-failures seem to be expected, since they’re caused by these. @pytest.mark.xfail(reason="copy keyword is missing")
@pytest.mark.xfail(reason="copy=False is not Implemented")
please let me know if you'd like me to enhance anything further.

@Aniketsy
Copy link
Copy Markdown
Contributor Author

Aniketsy commented Jan 1, 2026

Hi @jbrockmendel , just a gentle reminder on this when you get a chance. Thanks!

@jbrockmendel jbrockmendel added the Testing pandas testing functions or related to the test suite label Mar 6, 2026
Comment thread pandas/tests/extension/base/missing.py Outdated
res_copy = data.fillna(fill_value, copy=True)
tm.assert_extension_array_equal(
res_copy, data_missing.fillna(fill_value, copy=True)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this assertion added? seems meaningless

Copy link
Copy Markdown
Contributor Author

@Aniketsy Aniketsy Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this can be removed. thanks!

Comment thread pandas/tests/extension/base/missing.py Outdated
@@ -6,6 +6,8 @@


class BaseMissingTests:
_supports_fillna_copy_false = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the name say "respect" instead of "support"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this not fully sure, but I’ve updated it as per your suggestion.

@Aniketsy
Copy link
Copy Markdown
Contributor Author

I took a help of llm for fixing ci-fails, and updated with some changes.

filled : IntervalArray with NA/NaN filled
"""
if copy is False:
raise NotImplementedError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IntervalArray.fillna always copies regardless of the copy keyword, so i think NotImplementedError is not needed removing this will pass without error, and behavior stays, same. I would like to know your thoughts on this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raising is correct here.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass copy=copy?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or raise/warn if the user passes copy=False

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass copy=copy?

i think we can go with this . I'll update

@jbrockmendel
Copy link
Copy Markdown
Member

FAILED pandas/tests/extension/decimal/test_decimal.py::TestDecimalArray::test_fillna_frame - AssertionError: Did not see expected warning of class 'Pandas4Warning'

Comment thread pandas/tests/extension/decimal/array.py
@Aniketsy
Copy link
Copy Markdown
Contributor Author

FAILED pandas/tests/extension/decimal/test_decimal.py::TestDecimalArray::test_fillna_frame - AssertionError: Did not see expected warning of class 'Pandas4Warning'
FAILED pandas/tests/extension/decimal/test_decimal.py::TestDecimalArray::test_fillna_series - AssertionError: Did not see expected warning of class 'DeprecationWarning'
FAILED pandas/tests/extension/decimal/test_decimal.py::TestDecimalArray::test_fillna_limit_frame - AssertionError: Did not see expected warning of class 'DeprecationWarning'
FAILED pandas/tests/extension/decimal/test_decimal.py::TestDecimalArray::test_fillna_limit_series - AssertionError: Did not see expected warning of class 'DeprecationWarning'

@jbrockmendel as we have passed copy directly, i think we can remove these test, please let me know your thoughts on this.

Comment thread pandas/tests/extension/decimal/array.py Outdated

def test_fillna_readonly(self, data_missing):
pa_dtype = data_missing.dtype.pyarrow_dtype
if pa.types.is_duration(pa_dtype):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its ugly but you could patch _respects_fillna_copy_false inside a context

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]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tm.assert_extension_array_equal(res_no_copy, res_copy), i think this already check, i also checked by restoring and got this failure on testing

    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
        res_copy = data.fillna(fill_value, copy=True)
>       assert res_copy[0] == fill_value
               ^^^^^^^^^^^^^^^^^^^^^^^^^
E       AssertionError

pandas\tests\extension\base\missing.py:134: AssertionError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.
On running locally all tests were passing

@jbrockmendel
Copy link
Copy Markdown
Member

Can you figure out the remaining test fialures

@Aniketsy
Copy link
Copy Markdown
Contributor Author

sorry, i don't know if i should invest more time in this, as i've left with 2 PR's and two are closed, please feel free to close these. i don't want to create extra work for you to review . Thanks @jbrockmendel ☺️

@jbrockmendel
Copy link
Copy Markdown
Member

closed by #65179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Testing pandas testing functions or related to the test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

not necessarily for this PR, but should we add an EA attribute specifying whether copy=False is ignored? that way we could avoid overriding tests?

2 participants