Skip to content

Commit 0e5dc6d

Browse files
resolved rebase issues
1 parent 8ad125c commit 0e5dc6d

File tree

1 file changed

+1
-109
lines changed

1 file changed

+1
-109
lines changed

pandas/core/generic.py

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828

2929
import numpy as np
3030

31-
import pandas as pd
32-
import pandas.core.algorithms as algos
33-
import pandas.core.common as com
3431
import pandas.core.indexing as indexing
3532
from pandas._config import config
3633
from pandas._libs import lib
@@ -53,9 +50,6 @@
5350
from pandas.compat import set_function_name
5451
from pandas.compat._optional import import_optional_dependency
5552
from pandas.compat.numpy import function as nv
56-
from pandas.core import missing, nanops
57-
from pandas.core.base import PandasObject, SelectionMixin
58-
from pandas.core.construction import create_series_with_explicit_dtype
5953
from pandas.core.dtypes.common import (
6054
ensure_int64,
6155
ensure_object,
@@ -99,6 +93,7 @@
9993
from pandas.io.formats import format as fmt
10094
from pandas.io.formats.format import DataFrameFormatter, format_percentiles
10195
from pandas.io.formats.printing import pprint_thing
96+
from pandas.util._decorators import doc
10297

10398
if TYPE_CHECKING:
10499
from pandas._libs.tslibs import BaseOffset
@@ -6957,109 +6952,6 @@ def interpolate(
69576952
Name: d, dtype: float64
69586953
"""
69596954

6960-
@doc(_shared_docs["interpolate"], **_shared_doc_kwargs)
6961-
def interpolate(
6962-
self,
6963-
method="linear",
6964-
axis=0,
6965-
limit=None,
6966-
inplace=False,
6967-
limit_direction="forward",
6968-
limit_area=None,
6969-
downcast=None,
6970-
**kwargs,
6971-
):
6972-
"""
6973-
Interpolate values according to different methods.
6974-
"""
6975-
inplace = validate_bool_kwarg(inplace, "inplace")
6976-
6977-
axis = self._get_axis_number(axis)
6978-
6979-
fillna_methods = ["ffill", "bfill", "pad", "backfill"]
6980-
should_transpose = axis == 1 and method not in fillna_methods
6981-
6982-
obj = self.T if should_transpose else self
6983-
6984-
if obj.empty:
6985-
return self.copy()
6986-
6987-
if method not in fillna_methods:
6988-
axis = self._info_axis_number
6989-
6990-
if isinstance(obj.index, MultiIndex) and method != "linear":
6991-
raise ValueError(
6992-
"Only `method=linear` interpolation is supported on MultiIndexes."
6993-
)
6994-
6995-
# Set `limit_direction` depending on `method`
6996-
if limit_direction is None:
6997-
limit_direction = (
6998-
"backward" if method in ("backfill", "bfill") else "forward"
6999-
)
7000-
else:
7001-
if method in ("pad", "ffill") and limit_direction != "forward":
7002-
raise ValueError(
7003-
f"`limit_direction` must be 'forward' for method `{method}`"
7004-
)
7005-
if method in ("backfill", "bfill") and limit_direction != "backward":
7006-
raise ValueError(
7007-
f"`limit_direction` must be 'backward' for method `{method}`"
7008-
)
7009-
7010-
if obj.ndim == 2 and np.all(obj.dtypes == np.dtype(object)):
7011-
raise TypeError(
7012-
"Cannot interpolate with all object-dtype columns "
7013-
"in the DataFrame. Try setting at least one "
7014-
"column to a numeric dtype."
7015-
)
7016-
7017-
# create/use the index
7018-
if method == "linear":
7019-
# prior default
7020-
index = np.arange(len(obj.index))
7021-
else:
7022-
index = obj.index
7023-
methods = {"index", "values", "nearest", "time"}
7024-
is_numeric_or_datetime = (
7025-
is_numeric_dtype(index.dtype)
7026-
or is_datetime64_any_dtype(index.dtype)
7027-
or is_timedelta64_dtype(index.dtype)
7028-
)
7029-
if method not in methods and not is_numeric_or_datetime:
7030-
raise ValueError(
7031-
"Index column must be numeric or datetime type when "
7032-
f"using {method} method other than linear. "
7033-
"Try setting a numeric or datetime index column before "
7034-
"interpolating."
7035-
)
7036-
7037-
if isna(index).any():
7038-
raise NotImplementedError(
7039-
"Interpolation with NaNs in the index "
7040-
"has not been implemented. Try filling "
7041-
"those NaNs before interpolating."
7042-
)
7043-
new_data = obj._mgr.interpolate(
7044-
method=method,
7045-
axis=axis,
7046-
index=index,
7047-
limit=limit,
7048-
limit_direction=limit_direction,
7049-
limit_area=limit_area,
7050-
inplace=inplace,
7051-
downcast=downcast,
7052-
**kwargs,
7053-
)
7054-
7055-
result = self._constructor(new_data)
7056-
if should_transpose:
7057-
result = result.T
7058-
if inplace:
7059-
return self._update_inplace(result)
7060-
else:
7061-
return result.__finalize__(self, method="interpolate")
7062-
70636955
# ----------------------------------------------------------------------
70646956
# Timeseries methods Methods
70656957

0 commit comments

Comments
 (0)