Skip to content

ERR: read_csv exposes an internal function when bad argument is specified #25648

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

Closed
dsaxton opened this issue Mar 11, 2019 · 4 comments · Fixed by #34976
Closed

ERR: read_csv exposes an internal function when bad argument is specified #25648

dsaxton opened this issue Mar 11, 2019 · 4 comments · Fixed by #34976
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv Needs Discussion Requires discussion from core team before further action
Milestone

Comments

@dsaxton
Copy link
Member

dsaxton commented Mar 11, 2019

When a user tries to specify a non-existent argument in read_csv the error message pertains to what seems to be an internal function (parser_f). This behavior might be a bit surprising / confusing to users, who would expect the error message to refer to the function actually being used.

import pandas as pd
df = pd.read_csv("some_file.csv", bad_arg=True)

yields

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-d4606a60902f> in <module>()
----> 1 df = pd.read_csv("some_file.csv", bad_arg=True)

TypeError: parser_f() got an unexpected keyword argument 'bad_arg'
@WillAyd
Copy link
Member

WillAyd commented Mar 11, 2019

These IO functions are built dynamically:

parser_f.__name__ = name

Personally not sure how the traceback is built but certainly welcome to take a look. Maybe should be using functools.wraps here?

@WillAyd WillAyd added IO Data IO issues that don't fit into a more specific label Error Reporting Incorrect or improved errors from pandas labels Mar 11, 2019
@WillAyd WillAyd added this to the Contributions Welcome milestone Mar 11, 2019
@chris-b1
Copy link
Contributor

Not sure there is an easy way to do this - that error message seems to be using the code object name, which can't be modified

In [24]: def orig_func(a):
    ...:     return a
 
In [25]: new_func = orig_func
         new_func.__name__ = 'new_func'
         new_func.__qualname__ = 'new_func'

In [26]: new_func(b=2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-4e081338f0ff> in <module>()
----> 1 new_func(b=2)

TypeError: orig_func() got an unexpected keyword argument 'b'

In [27]: new_func.__code__.co_name
Out[27]: 'orig_func'

In [28]: new_func.__code__.co_name = 'new_func'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-89626da5926c> in <module>()
----> 1 new_func.__code__.co_name = 'new_func'

AttributeError: readonly attribute

@chris-b1
Copy link
Contributor

@jbrockmendel jbrockmendel added IO CSV read_csv, to_csv and removed IO Data IO issues that don't fit into a more specific label labels Dec 1, 2019
@simonjayhawkins simonjayhawkins added the Needs Discussion Requires discussion from core team before further action label May 22, 2020
@simonjayhawkins simonjayhawkins removed this from the Contributions Welcome milestone May 22, 2020
@simonjayhawkins
Copy link
Member

This needs further discussion, see #33023

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 IO CSV read_csv, to_csv Needs Discussion Requires discussion from core team before further action
Projects
None yet
6 participants