MCPcopy
hub / github.com/pandas-dev/pandas / get_interp_index

Function get_interp_index

pandas/core/missing.py:328–360  ·  view source on GitHub ↗
(method, index: Index)

Source from the content-addressed store, hash-verified

326
327
328def get_interp_index(method, index: Index) -> Index:
329 # create/use the index
330 if method == "linear":
331 # prior default
332 from pandas import RangeIndex
333
334 index = RangeIndex(len(index))
335 else:
336 methods = {"index", "values", "nearest", "time"}
337 is_numeric_or_datetime = (
338 is_numeric_dtype(index.dtype)
339 or isinstance(index.dtype, DatetimeTZDtype)
340 or lib.is_np_dtype(index.dtype, "mM")
341 )
342 valid = NP_METHODS + SP_METHODS
343 if method in valid:
344 if method not in methods and not is_numeric_or_datetime:
345 raise ValueError(
346 "Index column must be numeric or datetime type when "
347 f"using {method} method other than linear. "
348 "Try setting a numeric or datetime index column before "
349 "interpolating."
350 )
351 else:
352 raise ValueError(f"Can not interpolate with method={method}.")
353
354 if isna(index).any():
355 raise NotImplementedError(
356 "Interpolation with NaNs in the index "
357 "has not been implemented. Try filling "
358 "those NaNs before interpolating."
359 )
360 return index
361
362
363def interpolate_2d_inplace(

Callers

nothing calls this directly

Calls 4

RangeIndexClass · 0.90
is_numeric_dtypeFunction · 0.90
isnaFunction · 0.90
anyMethod · 0.45

Tested by

no test coverage detected