Skip to content

BUG : Allow axis = 'columns' with limit and no method to work on fillna. #42856

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 8 commits into from
Aug 20, 2021

Conversation

GYvan
Copy link
Contributor

@GYvan GYvan commented Aug 2, 2021

Added an if-condition for when axis = 1 so as to transpose the result in pandas/tests/frame/methods/test_fillna.py, and created a test for this change. The test also tests for inplace =True. This solves issue #40989

Copy link
Contributor

@KrishnaSai2020 KrishnaSai2020 left a comment

Choose a reason for hiding this comment

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

LGTM

@GYvan GYvan changed the title Error Reporting and TST: Raising the NotImplementedError for issue #40989 and and a test of the changes BUG : Raise NotImplementedError when axis = 'columns' with limit and no method Aug 4, 2021
@GYvan GYvan changed the title BUG : Raise NotImplementedError when axis = 'columns' with limit and no method BUG : Raise NotImplementedError in fillna when axis = 'columns' with limit and no method Aug 4, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

this is just not being passed thru somewhere. please trace it.

@jreback jreback added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Aug 4, 2021
@GYvan GYvan changed the title BUG : Raise NotImplementedError in fillna when axis = 'columns' with limit and no method BUG : Solving Issue #40989 by making transposes to allow axis = 'columns' with limit and no method to work. Aug 9, 2021
@GYvan GYvan requested a review from jreback August 9, 2021 19:45
@GYvan GYvan changed the title BUG : Solving Issue #40989 by making transposes to allow axis = 'columns' with limit and no method to work. BUG : Solving Issue #40989 by making transposes to allow axis = 'columns' with limit and no method to work on fillna. Aug 10, 2021
@GYvan GYvan changed the title BUG : Solving Issue #40989 by making transposes to allow axis = 'columns' with limit and no method to work on fillna. BUG : Allow axis = 'columns' with limit and no method to work on fillna. Aug 10, 2021
@@ -438,6 +438,22 @@ def test_fillna_inplace(self):
df.fillna(method="ffill", inplace=True)
tm.assert_frame_equal(df, expected)

df = DataFrame(
Copy link
Contributor

Choose a reason for hiding this comment

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

make a separate test

new_data = self._mgr.fillna(
value=value, limit=limit, inplace=inplace, downcast=downcast
)
if not self._mgr.is_single_block and axis == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this the same as L6254

Copy link
Contributor Author

@GYvan GYvan Aug 12, 2021

Choose a reason for hiding this comment

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

Yes, the code is somehow the same, with minor adjustments. I basically used it to make transposes as the ones done when the method is not None. This is because when the method is valid, both axis = 1 and axis = 0 works correctly with the given limit for Fillna due to the transposition at L6254. Therefore, I tried to do the same kind of transposing so that axis = 1 and axis = 0 would work accordingly for the given value and limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok any possibiltiy of combing those cases into a similar code block?

Copy link
Contributor Author

@GYvan GYvan Aug 17, 2021

Choose a reason for hiding this comment

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

Hi @jreback I tried to combine these cases into a similar code block and this is the code that I came up with for a separate top-level if-else block in fillna:

if not self._mgr.is_single_block and axis == 1:
            if value is None or not is_list_like(value):
                    if inplace and value is None:
                        raise NotImplementedError()
                    
                    result = self.T.fillna(method=method, value=value, limit=limit).T

                    # need to downcast here because of all of the transposes
                    result._mgr = result._mgr.downcast()
                    if value is None:
                        return result
                    new_data = result

I also added the condition for x==0 for the remaining of the elif not is_list_like(value) so that it won't interfere with the above changes with x == 1.
However, due to the additional code block: the code structure is slightly modified because before, the code for fillna was clearly split between the case for when value is None and the case for when value is not None, but this additional code block changes that. This new code block means that there are now two places where we would be "branching" on whether a value is None or not: Firstly, in the new code block, and secondly, in the original if-else block. Therefore, I think the new change might make it more difficult to follow the code compared to the original PR where the change was only made to the code that affects fillna with axis = 1 and value is not None.

@GYvan GYvan requested a review from jreback August 12, 2021 17:16
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add a release note in whatsnew for 1.4, bug fixes in the missing section

new_data = self._mgr.fillna(
value=value, limit=limit, inplace=inplace, downcast=downcast
)
if not self._mgr.is_single_block and axis == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

ok any possibiltiy of combing those cases into a similar code block?

@GYvan GYvan requested a review from jreback August 17, 2021 21:01
@jreback jreback added this to the 1.4 milestone Aug 20, 2021
@jreback
Copy link
Contributor

jreback commented Aug 20, 2021

lgtm. @mzeitlin11 or @phofl if you'd take a quick look here.

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

lgtm

@phofl phofl merged commit e8f3593 into pandas-dev:master Aug 20, 2021
@phofl
Copy link
Member

phofl commented Aug 20, 2021

thanks @GYvan

feefladder pushed a commit to feefladder/pandas that referenced this pull request Sep 7, 2021
…na. (pandas-dev#42856)

* solves issue pandas-dev#40989 by raising NotImplementedError and modifying docs

* Testing the NotImplementedError created to solve issue pandas-dev#40989

* pre-commit error fixed

* added modified generic.py

* added modified test_fillna.py

* reverted changes for test_frame.py

* added another test

* added into bug fixes in whatsnew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 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: fillna with limit and no method ignores axis='columns'
4 participants