Skip to content

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

Merged
merged 1 commit into from
Mar 24, 2019
Merged

BUG: pd.Series.interpolate non-numeric index column (21662) #25394

merged 1 commit into from
Mar 24, 2019

Conversation

TrigonaMinima
Copy link

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.

"setting a numeric index column before "\
"interpolating."
with pytest.raises(ValueError, match=expected_error):
result = df[0].interpolate(method="zero")
Copy link
Member

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

@mroeschke mroeschke added Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations labels Feb 21, 2019
@pep8speaks
Copy link

pep8speaks commented Feb 21, 2019

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
Copy link

codecov bot commented Feb 21, 2019

Codecov Report

Merging #25394 into master will decrease coverage by 50%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Flag Coverage Δ
#multiple ?
#single 41.72% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 38.34% <0%> (-55.83%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/core/categorical.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-99.35%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-95.46%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.17%) ⬇️
pandas/io/sas/sas_xport.py 0% <0%> (-90.15%) ⬇️
... and 131 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c0f6a8...f62894b. Read the comment docs.

@codecov
Copy link

codecov bot commented Feb 21, 2019

Codecov Report

Merging #25394 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25394      +/-   ##
==========================================
+ Coverage   91.47%   91.47%   +<.01%     
==========================================
  Files         173      173              
  Lines       52872    52876       +4     
==========================================
+ Hits        48364    48368       +4     
  Misses       4508     4508
Flag Coverage Δ
#multiple 90.03% <100%> (ø) ⬆️
#single 41.82% <16.66%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 93.54% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2618b21...d227f8a. Read the comment docs.

"method",
{
"linear", "zero", "slinear", "quadratic", "cubic", "spline",
"barycentric", "polynomial", "krogh", "piecewise_polynomial",
Copy link
Contributor

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

@TrigonaMinima
Copy link
Author

@jreback this PR is complete. I have rebased it with the master as well. The unsuccessful checks are because of the previous commits.

@jreback
Copy link
Contributor

jreback commented Mar 20, 2019

can you merge master

@@ -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 = (
Copy link
Contributor

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

@@ -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
Copy link
Contributor

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

if method == "pchip":
_skip_if_no_pchip()
elif is_timedelta64_dtype(ind):
if method in {"linear", "index", "values", "pchip"}:
Copy link
Contributor

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)

@jreback
Copy link
Contributor

jreback commented Mar 22, 2019

can you add a whatsnew note as well (bug fixes / numeric)

@TrigonaMinima
Copy link
Author

@jreback done

Copy link
Contributor

@jreback jreback left a 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.

"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.")
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 add that {method} was passed in the text.

Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

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

done

@jreback jreback added this to the 0.25.0 milestone Mar 23, 2019
@TrigonaMinima
Copy link
Author

@jreback it's green now

"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.")
Copy link
Contributor

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)

@jreback jreback merged commit 9821b77 into pandas-dev:master Mar 24, 2019
@jreback
Copy link
Contributor

jreback commented Mar 24, 2019

thanks @TrigonaMinima

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pd.Series.interpolate(method="quadratic) Error with non-numeric index column
4 participants