Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TST: add regression tests for interpolate(method="time") with nullable dtypes (GH#40252) #62571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonathan-gut wants to merge 1 commit into pandas-dev:main
base: main
Choose a base branch
Loading
from jonathan-gut:issue
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions pandas/tests/frame/methods/test_interpolate.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
NaT,
Series,
date_range,
NA,
)
import pandas._testing as tm

Expand Down Expand Up @@ -440,3 +441,41 @@ def test_interpolate_arrow(self, dtype):
result = df.interpolate(limit=2)
expected = DataFrame({"a": [1, 1.5, 2.0, None, 3]}, dtype="float64[pyarrow]")
tm.assert_frame_equal(result, expected)

def test_interpolate_time_with_nullable_int64(self, frame_or_series):
# GH#40252 regression: method="time" should work with nullable Int64
idx = date_range("2024年01月01日", periods=3, freq="D")
ser = Series([1, NA, 3], dtype="Int64", index=idx)

res = frame_or_series(ser).interpolate(method="time")

expected_ser = Series([1.0, 2.0, 3.0], dtype="Float64", index=idx)
expected = frame_or_series(expected_ser)
tm.assert_equal(res, expected)

def test_interpolate_time_with_nullable_float64(self, frame_or_series):
# GH#40252 regression: method="time" with nullable Float64
idx = date_range("2024年02月01日", periods=3, freq="D")
ser = Series([1.5, NA, 3.5], dtype="Float64", index=idx)

res = frame_or_series(ser).interpolate(method="time")

expected_ser = Series([1.5, 2.5, 3.5], dtype="Float64", index=idx)
expected = frame_or_series(expected_ser)
tm.assert_equal(res, expected)

def test_interpolate_time_with_nullable_int64_unsorted_index(self, frame_or_series):
# Ensure correctness when the DatetimeIndex is unsorted
idx_sorted = date_range("2024年03月01日", periods=3, freq="D") # 1st, 2nd, 3rd
idx_unsorted = idx_sorted[[2, 0, 1]] # 3rd, 1st, 2nd

# values aligned with idx_unsorted: 3, 1, NA (dtype EA Int64)
ser_unsorted = Series([3, 1, NA], dtype="Int64", index=idx_unsorted)

res = frame_or_series(ser_unsorted).interpolate(method="time")

# Expected: equivalent to sorting by time, interpolating, then restoring order
expected_sorted = Series([1.0, 2.0, 3.0], dtype="Float64", index=idx_sorted)
expected_ser = expected_sorted.reindex(idx_unsorted)
expected = frame_or_series(expected_ser)
tm.assert_equal(res, expected)
Loading

AltStyle によって変換されたページ (->オリジナル) /