|
28 | 28 |
|
29 | 29 | import numpy as np |
30 | 30 |
|
31 | | -import pandas as pd |
32 | | -import pandas.core.algorithms as algos |
33 | | -import pandas.core.common as com |
34 | 31 | import pandas.core.indexing as indexing |
35 | 32 | from pandas._config import config |
36 | 33 | from pandas._libs import lib |
|
53 | 50 | from pandas.compat import set_function_name |
54 | 51 | from pandas.compat._optional import import_optional_dependency |
55 | 52 | 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 |
59 | 53 | from pandas.core.dtypes.common import ( |
60 | 54 | ensure_int64, |
61 | 55 | ensure_object, |
|
99 | 93 | from pandas.io.formats import format as fmt |
100 | 94 | from pandas.io.formats.format import DataFrameFormatter, format_percentiles |
101 | 95 | from pandas.io.formats.printing import pprint_thing |
| 96 | +from pandas.util._decorators import doc |
102 | 97 |
|
103 | 98 | if TYPE_CHECKING: |
104 | 99 | from pandas._libs.tslibs import BaseOffset |
@@ -6957,109 +6952,6 @@ def interpolate( |
6957 | 6952 | Name: d, dtype: float64 |
6958 | 6953 | """ |
6959 | 6954 |
|
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 | | - |
7063 | 6955 | # ---------------------------------------------------------------------- |
7064 | 6956 | # Timeseries methods Methods |
7065 | 6957 |
|
|
0 commit comments