Skip to content

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

@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

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions