-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Interpolation nonnumeric error handling #21773
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6024,6 +6024,13 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, | |
raise NotImplementedError("Interpolation with NaNs in the index " | ||
"has not been implemented. Try filling " | ||
"those NaNs before interpolating.") | ||
|
||
if not np.issubdtype(index.dtype, np.number): | ||
raise TypeError("Index column must be numeric when using any " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be a ValueError |
||
"interpolation method other than linear. Try " | ||
"setting a numeric index column before " | ||
"interpolating") | ||
|
||
data = _maybe_transposed_self._data | ||
new_data = data.interpolate(method=method, axis=ax, index=index, | ||
values=_maybe_transposed_self, limit=limit, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1008,3 +1008,16 @@ def test_pipe_panel(self): | |
|
||
with pytest.raises(ValueError): | ||
result = wp.pipe((f, 'y'), x=1, y=1) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to go in pandas/tests/series/test_missing.py also some tests are failing |
||
def test_interpolate(self): | ||
# Using a numeric index column | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add the issue number here |
||
df = DataFrame([0, 1, np.nan, 3], index=[1, 2, 3, 4]) | ||
series = Series(df[0]) | ||
assert series.interpolate( | ||
method="quadratic").equals(series.interpolate(method="linear")) | ||
|
||
# Using a non-numeric index column | ||
df = DataFrame([0, 1, np.nan, 3], index=["A", "B", "C", "D"]) | ||
series = Series(df[0]) | ||
with pytest.raises(TypeError): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the returned message here |
||
result = series.interpolate(method="quadratic") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
is_numeric_dtype
intead