Skip to content

DataFrame.interpolate(axis=1, method="time", inplace=True) #9687

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
markrichardson opened this issue Mar 20, 2015 · 5 comments · Fixed by #30646
Closed

DataFrame.interpolate(axis=1, method="time", inplace=True) #9687

markrichardson opened this issue Mar 20, 2015 · 5 comments · Fixed by #30646
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@markrichardson
Copy link

In pandas 0.15.2, DataFrame.interpolate( ... ) doesn't work with the keyword combination axis=1, method="time", inplace=True. It just returns the original DataFrame.

import pandas as pd
import numpy as np

periods=5
idx = pd.date_range(start="2014-01-01", periods=periods)
data = np.random.rand(periods, periods)
data[data < 0.5] = np.nan
df0 = pd.DataFrame(index=idx, columns=idx, data=data)
df1 = df0.copy()

print "(1) Original df"
print df0

print "\n(2a) axis=0, inplace=False"
print df0.interpolate(axis=0, method="time")
print "\n(2b) axis=0, inplace=True"
df0.interpolate(axis=0, method="time", inplace=True)
print df0

print "\n(3a) axis=1, inplace=False"
print df1.interpolate(axis=1, method="time")
print "\n(3b) axis=1, inplace=True"
df1.interpolate(axis=1, method="time", inplace=True)
print df1
@jreback
Copy link
Contributor

jreback commented Mar 20, 2015

hmm, prob needs some more testing. pull-requests are welcome on this.
just a note though. inplace makes code IMHO harder to read and does not allow method chaining, so generally should be avoided.

@jreback jreback added Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Mar 20, 2015
@jreback jreback added this to the Next Major Release milestone Mar 20, 2015
@TomAugspurger
Copy link
Contributor

The method parameter doesn't matter. All inplace ops fail w/ axis=1.

@TomAugspurger
Copy link
Contributor

@jreback am I right that df.T returns a copy?

In [16]: df.T.T is df
Out[16]: False

If so, then my implementation w/ inplace and axis=1 is pretty broken.

@jreback
Copy link
Contributor

jreback commented Mar 20, 2015

you need to do something like this (as you are just overwriting the reference)

if inplace:
        if axis == 1:
                self._update_inplace(new_data)
                self._data = self.T._data
        else:
                self._update_inplace(new_data)

@mroeschke
Copy link
Member

Looks to be fixed on master. Could use a test.

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Oct 6, 2019
@simonjayhawkins simonjayhawkins modified the milestones: Contributions Welcome, 1.0 Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
5 participants