Skip to content

BUG: Implement fillna(..., limit=x) for EAs #58249

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

Merged
merged 5 commits into from
May 3, 2024

Conversation

rhshadrach
Copy link
Member

@@ -1073,6 +1066,12 @@ def fillna(
Length: 6, dtype: Int64
"""
mask = self.isna()
if limit is not None and limit < len(self):
modify = mask.cumsum() > limit
Copy link
Member Author

Choose a reason for hiding this comment

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

self.isna() can return an ExtensionArray, which may not implement cumsum because we don't require it to implement _accumulate (but do require _reduce). Would it be okay to require _accumulate? Still not sure about the comparison > in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jbrockmendel - any thoughts here?

Copy link
Member

Choose a reason for hiding this comment

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

I’d be fine with that. Could add a comment to that effect

@@ -149,6 +149,16 @@ def test_fillna_frame(self):
"""We treat dictionaries as a mapping in fillna, not a scalar."""
super().test_fillna_frame()

@pytest.mark.xfail(reason="fill value is a dictionary, takes incorrect code path")
Copy link
Member Author

Choose a reason for hiding this comment

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

We cannot use fillna with JSONArray because DataFrame.fillna has special logic for dict / Series argument.

@rhshadrach rhshadrach added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate ExtensionArray Extending pandas with custom dtypes or arrays. labels Apr 13, 2024
@rhshadrach rhshadrach marked this pull request as ready for review May 2, 2024 22:53
@mroeschke mroeschke added this to the 3.0 milestone May 3, 2024
@mroeschke mroeschke merged commit ca370af into pandas-dev:main May 3, 2024
17 of 29 checks passed
@mroeschke
Copy link
Member

Thanks @rhshadrach

@rhshadrach rhshadrach deleted the enh_ea_fillna_limit branch May 4, 2024 11:55
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* BUG: Implement fillna(..., limit=x) for EAs

* Comments

* type ignores

* Update doc/source/whatsnew/v3.0.0.rst

---------

Co-authored-by: Matthew Roeschke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Implement fillna(..., limit=x) for EAs
3 participants