@@ -6835,27 +6835,16 @@ def interpolate(
6835
6835
axis = self ._get_axis_number (axis )
6836
6836
6837
6837
if axis == 0 :
6838
- ax = self ._info_axis_name
6839
- _maybe_transposed_self = self
6840
- elif axis == 1 :
6841
- _maybe_transposed_self = self .T
6842
- ax = 1
6843
-
6844
- ax = _maybe_transposed_self ._get_axis_number (ax )
6845
-
6846
- if _maybe_transposed_self .ndim == 2 :
6847
- alt_ax = 1 - ax
6838
+ df = self
6848
6839
else :
6849
- alt_ax = ax
6840
+ df = self . T
6850
6841
6851
- if isinstance (_maybe_transposed_self .index , MultiIndex ) and method != "linear" :
6842
+ if isinstance (df .index , MultiIndex ) and method != "linear" :
6852
6843
raise ValueError (
6853
6844
"Only `method=linear` interpolation is supported on MultiIndexes."
6854
6845
)
6855
6846
6856
- if _maybe_transposed_self ._data .get_dtype_counts ().get ("object" ) == len (
6857
- _maybe_transposed_self .T
6858
- ):
6847
+ if df .ndim == 2 and np .all (df .dtypes == np .dtype (object )):
6859
6848
raise TypeError (
6860
6849
"Cannot interpolate with all object-dtype columns "
6861
6850
"in the DataFrame. Try setting at least one "
@@ -6865,9 +6854,9 @@ def interpolate(
6865
6854
# create/use the index
6866
6855
if method == "linear" :
6867
6856
# prior default
6868
- index = np .arange (len (_maybe_transposed_self . _get_axis ( alt_ax ) ))
6857
+ index = np .arange (len (df . index ))
6869
6858
else :
6870
- index = _maybe_transposed_self . _get_axis ( alt_ax )
6859
+ index = df . index
6871
6860
methods = {"index" , "values" , "nearest" , "time" }
6872
6861
is_numeric_or_datetime = (
6873
6862
is_numeric_dtype (index )
@@ -6888,10 +6877,10 @@ def interpolate(
6888
6877
"has not been implemented. Try filling "
6889
6878
"those NaNs before interpolating."
6890
6879
)
6891
- data = _maybe_transposed_self ._data
6880
+ data = df ._data
6892
6881
new_data = data .interpolate (
6893
6882
method = method ,
6894
- axis = ax ,
6883
+ axis = self . _info_axis_number ,
6895
6884
index = index ,
6896
6885
limit = limit ,
6897
6886
limit_direction = limit_direction ,
@@ -6901,15 +6890,13 @@ def interpolate(
6901
6890
** kwargs ,
6902
6891
)
6903
6892
6893
+ result = self ._constructor (new_data )
6894
+ if axis == 1 :
6895
+ result = result .T
6904
6896
if inplace :
6905
- if axis == 1 :
6906
- new_data = self ._constructor (new_data ).T ._data
6907
- self ._update_inplace (new_data )
6897
+ return self ._update_inplace (result )
6908
6898
else :
6909
- res = self ._constructor (new_data ).__finalize__ (self )
6910
- if axis == 1 :
6911
- res = res .T
6912
- return res
6899
+ return result .__finalize__ (self )
6913
6900
6914
6901
# ----------------------------------------------------------------------
6915
6902
# Timeseries methods Methods
0 commit comments