Skip to content

Commit 82c854e

Browse files
committed
REGR: Interpolate with method=index
1 parent b64f438 commit 82c854e

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

pandas/core/missing.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,7 @@ def get_interp_index(method, index: Index) -> Index:
314314
# prior default
315315
from pandas import Index
316316

317-
if isinstance(index.dtype, DatetimeTZDtype) or lib.is_np_dtype(
318-
index.dtype, "mM"
319-
):
320-
# Convert datetime-like indexes to int64
321-
index = Index(index.view("i8"))
322-
323-
elif not is_numeric_dtype(index.dtype):
324-
# We keep behavior consistent with prior versions of pandas for
325-
# non-numeric, non-datetime indexes
326-
index = Index(range(len(index)))
317+
index = Index(np.arange(len(index)))
327318
else:
328319
methods = {"index", "values", "nearest", "time"}
329320
is_numeric_or_datetime = (

pandas/tests/resample/test_base.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,22 @@ def test_resample_interpolate_regular_sampling_off_grid(
123123
ser = Series(np.arange(5.0), index)
124124

125125
method = all_1d_no_arg_interpolation_methods
126-
# Resample to 1 hour sampling and interpolate with the given method
127-
ser_resampled = ser.resample("1h").interpolate(method)
126+
result = ser.resample("1h").interpolate(method)
128127

129-
# Check that none of the resampled values are NaN, except the first one
130-
# which lies 1 minute before the first actual data point
131-
assert np.isnan(ser_resampled.iloc[0])
132-
assert not ser_resampled.iloc[1:].isna().any()
133-
134-
if method not in ["nearest", "zero"]:
135-
# Check that the resampled values are close to the expected values
136-
# except for methods with known inaccuracies
137-
assert np.all(
138-
np.isclose(ser_resampled.values[1:], np.arange(0.5, 4.5, 0.5), rtol=1.0e-1)
128+
if method == "linear":
129+
values = np.repeat(np.arange(0.0, 4.0), 2) + np.tile(
130+
np.arange(1 / 3, 0.7, 1 / 3), 4
139131
)
132+
elif method == "nearest":
133+
values = np.repeat(np.arange(0.0, 5.0), 2)[1:-1]
134+
elif method == "zero":
135+
values = np.repeat(np.arange(0.0, 4.0), 2)
136+
else:
137+
values = 0.491667 + np.arange(0.0, 4.0, 0.5)
138+
values = np.insert(values, 0, np.nan)
139+
index = date_range("2000-01-01 00:00:00", periods=9, freq="1h")
140+
expected = Series(values, index=index)
141+
tm.assert_series_equal(result, expected)
140142

141143

142144
def test_resample_interpolate_irregular_sampling(all_1d_no_arg_interpolation_methods):

pandas/tests/resample/test_time_grouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def test_groupby_resample_interpolate_with_apply_syntax_off_grid(groupy_test_df)
433433
data={
434434
"price": [
435435
10.0,
436-
9.21131,
436+
9.5,
437437
11.0,
438438
]
439439
},

pandas/tests/series/methods/test_interpolate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_nan_interpolate(self, kwargs):
270270
def test_nan_irregular_index(self):
271271
s = Series([1, 2, np.nan, 4], index=[1, 3, 5, 9])
272272
result = s.interpolate()
273-
expected = Series([1.0, 2.0, 2.6666666666666665, 4.0], index=[1, 3, 5, 9])
273+
expected = Series([1.0, 2.0, 3.0, 4.0], index=[1, 3, 5, 9])
274274
tm.assert_series_equal(result, expected)
275275

276276
def test_nan_str_index(self):

0 commit comments

Comments
 (0)