Skip to content

Unnecessary bare except at class Block, function interpolate hides actual error #24014

Closed
@seboktamas

Description

@seboktamas

Code Sample, a copy-pastable example if possible

# Minimal example:
import pandas as pd
df = pd.Series([0,1,pd.np.nan,3,4])
df.interpolate(method='spline')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "D:\venvs\food_and_drinking\lib\site-packages\pandas\core\generic.py", line 6034, in interpolate
    **kwargs)
  File "D:\venvs\food_and_drinking\lib\site-packages\pandas\core\internals.py", line 3702, in interpolate
    return self.apply('interpolate', **kwargs)
  File "D:\venvs\food_and_drinking\lib\site-packages\pandas\core\internals.py", line 3581, in apply
    applied = getattr(b, f)(**kwargs)
  File "D:\venvs\food_and_drinking\lib\site-packages\pandas\core\internals.py", line 1168, in interpolate
    raise ValueError("invalid method '{0}' to interpolate.".format(method))
ValueError: invalid method 'spline' to interpolate.
Expected output
ValueError: You must specify the order of the spline or polynomial.

Problem description

If interpolation parameter not specified, it raises an error, which states invalid method
internals.py:1152:1155
try:
m = missing.clean_interp_method(method, **kwargs)
except:
m = None

If there is no such try/except block around the missing.clean_interp_method function call, we would get the proper exception from mising.py/clean_interp_method.

Pandas version: 0.23.4

Activity

TomAugspurger

TomAugspurger commented on Nov 30, 2018

@TomAugspurger
Contributor
added
Needs InfoClarification about behavior needed to assess issue
on Dec 2, 2018
seboktamas

seboktamas commented on Dec 3, 2018

@seboktamas
Author

Minimal example:
import pandas as pd
df = pd.Series([0,1,pd.np.nan,3,4])
df.interpolate(method='spline')

TomAugspurger

TomAugspurger commented on Dec 3, 2018

@TomAugspurger
Contributor

For clarity, the expected output is

ValueError: You must specify the order of the spline or polynomial.

@seboktamas can you edit your original post to include the minimal example and the expected output?

added
Missing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Error ReportingIncorrect or improved errors from pandas
and removed
Needs InfoClarification about behavior needed to assess issue
on Dec 3, 2018
added this to the 0.25.0 milestone on Feb 11, 2019
added a commit that references this issue on Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @jreback@TomAugspurger@seboktamas@mroeschke

      Issue actions

        Unnecessary bare except at class Block, function interpolate hides actual error · Issue #24014 · pandas-dev/pandas