Skip to content

BUG: Fix interpolate ValueError for datetime64_tz index #27549

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

Merged
merged 6 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Timezones

Numeric
^^^^^^^
-
- Bug in :meth:`interpolate` when using a timezone aware :class:`DatetimeIndex` (:issue:`27548`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't render, you want :meth:`Series.interpolate`

-
-

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
is_bool,
is_bool_dtype,
is_datetime64_any_dtype,
is_datetime64_dtype,
is_datetime64tz_dtype,
is_dict_like,
is_extension_array_dtype,
Expand Down Expand Up @@ -7023,7 +7022,7 @@ def interpolate(
methods = {"index", "values", "nearest", "time"}
is_numeric_or_datetime = (
is_numeric_dtype(index)
or is_datetime64_dtype(index)
or is_datetime64_any_dtype(index)
or is_timedelta64_dtype(index)
)
if method not in methods and not is_numeric_or_datetime:
Expand Down
15 changes: 13 additions & 2 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,12 +1521,23 @@ def test_interp_nonmono_raise(self):
s.interpolate(method="krogh")

@td.skip_if_no_scipy
def test_interp_datetime64(self):
@pytest.mark.parametrize("method", ["nearest", "pad"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can parametrize on tz_naive_fixture here (and just remove the bottom test); this includes None and a bunch of timezones.

def test_interp_datetime64(self, method):
df = Series([1, np.nan, 3], index=date_range("1/1/2000", periods=3))
result = df.interpolate(method="nearest")
result = df.interpolate(method=method)
expected = Series([1.0, 1.0, 3.0], index=date_range("1/1/2000", periods=3))
assert_series_equal(result, expected)

@td.skip_if_no_scipy
@pytest.mark.parametrize("method", ["nearest", "pad"])
def test_interp_datetime64_tz(self, method):
df = Series([1, np.nan, 3], index=date_range("1/1/2000", periods=3, tz="UTC"))
result = df.interpolate(method=method)
expected = Series(
[1.0, 1.0, 3.0], index=date_range("1/1/2000", periods=3, tz="UTC")
)
assert_series_equal(result, expected)

def test_interp_limit_no_nans(self):
# GH 7173
s = pd.Series([1.0, 2.0, 3.0])
Expand Down