Skip to content

CLN: simplify interpolate_2d and callers #36624

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 3 commits into from
Sep 26, 2020

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

minor comment otherwise lgtm

@@ -1181,12 +1181,15 @@ def interpolate(
m = None

if m is not None:
if fill_value is not None:
# similar to validate_fillna_kwargs
raise ValueError("Cannot pass both fill_value and method")
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test for codecov?

@WillAyd WillAyd added the Clean label Sep 25, 2020

msg = "Cannot pass both fill_value and method"
with pytest.raises(ValueError, match=msg):
ser.interpolate(fill_value=3, method="pad")
Copy link
Member

Choose a reason for hiding this comment

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

fill_value is not in the Series.interpolate api. This is accepted through kwargs from the public api? Then fill_value is accepted and passed along internally? I assume none of the scipy interpolate functions accept fill_value? or won't in the future!

do we really need the ValueError if fill_value is passed?

Copy link
Member Author

Choose a reason for hiding this comment

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

do we really need the ValueError if fill_value is passed?

In master:

>>> ser = pd.Series([1, 2, np.nan, 4])
>>> ser.interpolate(method="pad", fill_value=99)
0    1.0
1    2.0
2    NaN
3    4.0
dtype: float64

I'm pretty confident this isn't intentional.

Copy link
Member

Choose a reason for hiding this comment

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

but on master and this PR

>>> pd.__version__
'1.2.0.dev0+499.g3b12293cea'
>>> ser = pd.Series([1, 2, np.nan, 4])
>>> ser.interpolate(fill_value=99)
0    1.0
1    2.0
2    3.0
3    4.0
dtype: float64

>>> ser.interpolate(humpty_dumpty=99)
0    1.0
1    2.0
2    3.0
3    4.0
dtype: float64

why the ValueError when method passed?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. it may be that we can disallow fill_value at the top of Series.interpolate. making **kwargs explicit would be nice. But i haven't thoroughly checked if thats possible.
  2. BlockManager.interpolate also gets called from fillna, so we need to rule out fill_value at the place where this PR does it.

Copy link
Contributor

Choose a reason for hiding this comment

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

this looks ok to me; i think we are accepting too much here accidently.

@jbrockmendel can you add a whatsnew note in any case (just saying passing invalid keyword args to .interpolate() will raise (or can do it after when all non-named keyword args are banned.

Copy link
Member

Choose a reason for hiding this comment

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

so a ValueError may be appropriate for fill_na, but the test is for Series.interpolate. Why not TypeError: interpolate() got an unexpected keyword argument 'fill_value'?


msg = "Cannot pass both fill_value and method"
with pytest.raises(ValueError, match=msg):
ser.interpolate(fill_value=3, method="pad")
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks ok to me; i think we are accepting too much here accidently.

@jbrockmendel can you add a whatsnew note in any case (just saying passing invalid keyword args to .interpolate() will raise (or can do it after when all non-named keyword args are banned.

@jbrockmendel
Copy link
Member Author

or can do it after when all non-named keyword args are banned

yah lets save it for the end

@jreback jreback added this to the 1.2 milestone Sep 26, 2020
@jreback jreback added API - Consistency Internal Consistency of API/Behavior Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Sep 26, 2020
@jreback jreback merged commit b0dfe1a into pandas-dev:master Sep 26, 2020
@jbrockmendel jbrockmendel deleted the ref-mask_missing branch September 26, 2020 01:16
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Clean Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants