@@ -1106,128 +1106,34 @@ def interpolate(
1106
1106
# If there are no NAs, then interpolate is a no-op
1107
1107
return [self ] if inplace else [self .copy ()]
1108
1108
1109
- # a fill na type method
1110
1109
try :
1111
1110
m = missing .clean_fill_method (method )
1112
1111
except ValueError :
1113
1112
m = None
1113
+ if m is None and self .dtype .kind != "f" :
1114
+ # only deal with floats
1115
+ # bc we already checked that can_hold_na, we dont have int dtype here
1116
+ # TODO: make a copy if not inplace?
1117
+ return [self ]
1114
1118
1115
- if m is not None :
1116
- if fill_value is not None :
1117
- # similar to validate_fillna_kwargs
1118
- raise ValueError ("Cannot pass both fill_value and method" )
1119
-
1120
- return self ._interpolate_with_fill (
1121
- method = m ,
1122
- axis = axis ,
1123
- inplace = inplace ,
1124
- limit = limit ,
1125
- limit_area = limit_area ,
1126
- downcast = downcast ,
1127
- )
1128
- # validate the interp method
1129
- m = missing .clean_interp_method (method , ** kwargs )
1130
-
1131
- assert index is not None # for mypy
1119
+ data = self .values if inplace else self .values .copy ()
1120
+ data = cast (np .ndarray , data ) # bc overridden by ExtensionBlock
1132
1121
1133
- return self . _interpolate (
1134
- method = m ,
1135
- index = index ,
1122
+ interp_values = missing . interpolate_array_2d (
1123
+ data ,
1124
+ method = method ,
1136
1125
axis = axis ,
1126
+ index = index ,
1137
1127
limit = limit ,
1138
1128
limit_direction = limit_direction ,
1139
1129
limit_area = limit_area ,
1140
1130
fill_value = fill_value ,
1141
- inplace = inplace ,
1142
- downcast = downcast ,
1143
1131
** kwargs ,
1144
1132
)
1145
1133
1146
- @final
1147
- def _interpolate_with_fill (
1148
- self ,
1149
- method : str = "pad" ,
1150
- axis : int = 0 ,
1151
- inplace : bool = False ,
1152
- limit : Optional [int ] = None ,
1153
- limit_area : Optional [str ] = None ,
1154
- downcast : Optional [str ] = None ,
1155
- ) -> List [Block ]:
1156
- """ fillna but using the interpolate machinery """
1157
- inplace = validate_bool_kwarg (inplace , "inplace" )
1158
-
1159
- assert self ._can_hold_na # checked by caller
1160
-
1161
- values = self .values if inplace else self .values .copy ()
1162
-
1163
- values = missing .interpolate_2d (
1164
- values ,
1165
- method = method ,
1166
- axis = axis ,
1167
- limit = limit ,
1168
- limit_area = limit_area ,
1169
- )
1170
-
1171
- values = maybe_coerce_values (values )
1172
- blocks = [self .make_block_same_class (values )]
1173
- return self ._maybe_downcast (blocks , downcast )
1174
-
1175
- @final
1176
- def _interpolate (
1177
- self ,
1178
- method : str ,
1179
- index : Index ,
1180
- fill_value : Optional [Any ] = None ,
1181
- axis : int = 0 ,
1182
- limit : Optional [int ] = None ,
1183
- limit_direction : str = "forward" ,
1184
- limit_area : Optional [str ] = None ,
1185
- inplace : bool = False ,
1186
- downcast : Optional [str ] = None ,
1187
- ** kwargs ,
1188
- ) -> List [Block ]:
1189
- """ interpolate using scipy wrappers """
1190
- inplace = validate_bool_kwarg (inplace , "inplace" )
1191
- data = self .values if inplace else self .values .copy ()
1192
-
1193
- # only deal with floats
1194
- if self .dtype .kind != "f" :
1195
- # bc we already checked that can_hold_na, we dont have int dtype here
1196
- return [self ]
1197
-
1198
- if is_valid_na_for_dtype (fill_value , self .dtype ):
1199
- fill_value = self .fill_value
1200
-
1201
- if method in ("krogh" , "piecewise_polynomial" , "pchip" ):
1202
- if not index .is_monotonic :
1203
- raise ValueError (
1204
- f"{ method } interpolation requires that the index be monotonic."
1205
- )
1206
- # process 1-d slices in the axis direction
1207
-
1208
- def func (yvalues : np .ndarray ) -> np .ndarray :
1209
-
1210
- # process a 1-d slice, returning it
1211
- # should the axis argument be handled below in apply_along_axis?
1212
- # i.e. not an arg to missing.interpolate_1d
1213
- return missing .interpolate_1d (
1214
- xvalues = index ,
1215
- yvalues = yvalues ,
1216
- method = method ,
1217
- limit = limit ,
1218
- limit_direction = limit_direction ,
1219
- limit_area = limit_area ,
1220
- fill_value = fill_value ,
1221
- bounds_error = False ,
1222
- ** kwargs ,
1223
- )
1224
-
1225
- # interp each column independently
1226
- interp_values = np .apply_along_axis (func , axis , data )
1227
1134
interp_values = maybe_coerce_values (interp_values )
1228
-
1229
- blocks = [self .make_block_same_class (interp_values )]
1230
- return self ._maybe_downcast (blocks , downcast )
1135
+ nbs = [self .make_block_same_class (interp_values )]
1136
+ return self ._maybe_downcast (nbs , downcast )
1231
1137
1232
1138
def take_nd (
1233
1139
self ,
0 commit comments