question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: inplace behavior is inconsist for fillna

See original GitHub issue

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np
pdf = pd.DataFrame({"x": [np.nan, 2, 3, 4, np.nan, 6], "y": [np.nan, 2, 3, 4, np.nan, 6]})
pser = pdf.x
# Didn't make a copy write to existing  (it's unexpected behavior)
pdf.fillna(0, inplace=True)
>>> pser
0    0.0
1    2.0
2    3.0
3    4.0
4    0.0
5    6.0


import pandas as pd
import numpy as np
pdf = pd.DataFrame({"x": [np.nan, 2, 3, 4, np.nan, 6], "y": [np.nan, 2, 3, 4, np.nan, 6]})
pser = pdf.x
# Make a copy and doesn't write to existing (it's expected behavior)
>>> pdf.fillna({"x": -1, "y": -2}, inplace=True)
>>> pser
0    NaN
1    2.0
2    3.0
3    4.0
4    NaN
5    6.0
Name: x, dtype: float64

Issue Description

Looks like behavior is a little bit differet in current pandas.

Expected Behavior

~Always make a copy and doesn’t write to existing array for~ Do in-place operation in all functions with inplace (such like eval/update/fillna).

Installed Versions

1.4+

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
simonjayhawkinscommented, Jun 21, 2022

I’d like to raise two separate issues for eval and update (#47188 (comment)).

opened #47449 for eval

0reactions
simonjayhawkinscommented, Jun 21, 2022

I’d like to raise two separate issues for eval and update (#47188 (comment)).

fix for update included in https://github.com/pandas-dev/pandas/pull/47327

Read more comments on GitHub >

github_iconTop Results From Across the Web

fillna() method's behavior in Pandas -- does not obey to ...
fillna (like many other methods in pandas) isn't inplace by default. You need to either pass inplace=True or reassign its return value.
Read more >
Working with missing data — pandas 1.5.2 documentation
This behavior is consistent with R, for example: ... fillna() can “fill in” NA values with non-NA data in a couple of ways,...
Read more >
Using Pandas and Python to Explore Your Dataset
Missing Values; Invalid Values; Inconsistent Values ... compare Pandas and Python data structures, you'll see that this behavior makes Pandas much faster!
Read more >
Why You Should Probably Never Use pandas inplace=True
Inplace is a parameter accepted by a number of pandas methods which affects the behaviour of how the method runs. Some examples of...
Read more >
The IamDataFrame class — pyam 1.6.0 documentation
This is intended behaviour and consistent with pandas but may be confusing for ... If False and other is an IamDataFrame, raise an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found