-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: pd.Series.interpolate non-numeric index column (21662) #25394
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
Conversation
pandas/tests/series/test_missing.py
Outdated
"setting a numeric index column before "\ | ||
"interpolating." | ||
with pytest.raises(ValueError, match=expected_error): | ||
result = df[0].interpolate(method="zero") |
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.
You can parameterize over method
Hello @TrigonaMinima! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-03-24 19:04:39 UTC |
Codecov Report
@@ Coverage Diff @@
## master #25394 +/- ##
===========================================
- Coverage 91.73% 41.72% -50.01%
===========================================
Files 173 173
Lines 52845 52848 +3
===========================================
- Hits 48479 22053 -26426
- Misses 4366 30795 +26429
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25394 +/- ##
==========================================
+ Coverage 91.47% 91.47% +<.01%
==========================================
Files 173 173
Lines 52872 52876 +4
==========================================
+ Hits 48364 48368 +4
Misses 4508 4508
Continue to review full report at Codecov.
|
pandas/tests/series/test_missing.py
Outdated
"method", | ||
{ | ||
"linear", "zero", "slinear", "quadratic", "cubic", "spline", | ||
"barycentric", "polynomial", "krogh", "piecewise_polynomial", |
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.
we might have a fixture for this
@jreback this PR is complete. I have rebased it with the master as well. The unsuccessful checks are because of the previous commits. |
can you merge master |
pandas/core/generic.py
Outdated
@@ -6863,6 +6863,18 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, | |||
index = np.arange(len(_maybe_transposed_self._get_axis(alt_ax))) | |||
else: | |||
index = _maybe_transposed_self._get_axis(alt_ax) | |||
methods = {"index", "values", "nearest", "time"} | |||
num_dt_flg = ( |
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.
call is this: is_numeric_or_datetime
pandas/tests/series/test_missing.py
Outdated
@@ -14,6 +14,8 @@ | |||
from pandas.errors import PerformanceWarning | |||
import pandas.util._test_decorators as td | |||
|
|||
from pandas.core.dtypes.common import is_timedelta64_dtype |
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.
in tests we want to import from: pandas.api.types
pandas/tests/series/test_missing.py
Outdated
if method == "pchip": | ||
_skip_if_no_pchip() | ||
elif is_timedelta64_dtype(ind): | ||
if method in {"linear", "index", "values", "pchip"}: |
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.
i find this a touch complicated. it might be worthile to make this into several tests (you would make a fixture for the input parameterization)
can you add a whatsnew note as well (bug fixes / numeric) |
@jreback done |
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.
looks good. small change. ping on green.
pandas/core/generic.py
Outdated
"Index column must be numeric or datetime type when " | ||
"using any interpolation method other than linear. " | ||
"Try setting a numeric or datetome index column before " | ||
"interpolating.") |
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.
you can add that {method}
was passed in the text.
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 a replacement, e.g. "{method}"....format(method=method)
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.
done
@jreback it's green now |
pandas/core/generic.py
Outdated
"Index column must be numeric or datetime type when " | ||
"using any interpolation method other than linear. " | ||
"Try setting a numeric or datetome index column before " | ||
"interpolating.") |
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 a replacement, e.g. "{method}"....format(method=method)
thanks @TrigonaMinima |
git diff upstream/master -u -- "*.py" | flake8 --diff
Raises a helpful exception when a non-numeric index is sent to
interpolate
with methods which require numeric index. Skipped a few methods which can also work on datetime index.