Skip to content

BUG: Index.fillna ignores 'downcast' #44048

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

Closed
jbrockmendel opened this issue Oct 16, 2021 · 1 comment · Fixed by #44873
Closed

BUG: Index.fillna ignores 'downcast' #44048

jbrockmendel opened this issue Oct 16, 2021 · 1 comment · Fixed by #44873
Labels
Bug Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 16, 2021

Issue Description

def fillna(self, value=None, downcast=None):
    value = self._require_scalar(value)
     if self.hasnans:
        result = self.putmask(self._isnan, value)
        if downcast is None:
             return Index._with_infer(result, name=self.name)
     return self._view()

In the case with downcast not None and self.hasnans, we fall through to return self._view() and ignore result. We don't have any such cases in the test suite.

Expected Behavior

Not ignoring result or downcast.

I'd be OK with deprecating the keyword; i expect it is just there to match NDFrame.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 16, 2021
@jorisvandenbossche jorisvandenbossche added Index Related to the Index class or subclasses and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 20, 2021
@jorisvandenbossche
Copy link
Member

Concrete example of resulting behaviour:

In [14]: idx = pd.Index([1, 2, np.nan])

In [15]: idx
Out[15]: Float64Index([1.0, 2.0, nan], dtype='float64')

In [16]: idx.fillna(0.0)
Out[16]: Float64Index([1.0, 2.0, 0.0], dtype='float64')

In [17]: idx.fillna(0.0, downcast="infer")
Out[17]: Float64Index([1.0, 2.0, nan], dtype='float64')

So with specifying downcast, it's not actually filling any NaNs.

@mroeschke mroeschke added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Oct 30, 2021
@jreback jreback added this to the 1.4 milestone Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants