-
Notifications
You must be signed in to change notification settings - Fork 28
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
Better error message for DataFrame.apply #153
Comments
I agree with you. I've been noticing better error messages and suggestions on how to fix them in some libraries like sklearn. |
I don't know if there is a pandas convention on how to add suggestion to error messages.
|
The proposals are done with issues in the pandas repository. In this case, the problem is not that much about which is the exact error message, but rather how to be able to identify the problem in the code. As it's explained at the end of the description, the error message being raised is not from the |
Hmmmmm |
How is it going @WuraolaOyewusi? I'm interested in collaborating on this. @datapythonista would it be useful to add a test at the beginning of |
|
@datapythonista makes sense! I will try to implement something similar and tell you how it goes. |
@martinagvilas . I haven't figured out a way to go about this yet. |
The next example seems reasonable to me:
And looks like it should convert the data in the DataFrame to integers, by calling the
int()
function for every element.This would be true for
Series.apply
, butDataFrame.apply
parameter is a function that receives a wholeSeries
at a time, not individual (scalar) values. The function that receives one value at a time isDataFrame.applymap
.This is how pandas is designed, and while probably a bit confusing is reasonable. So, the previous example actually fails. The error is:
Feel free to disagree, but personally I think the error message doesn't do a great job at telling the user what's wrong, or give hints on how to fix it. I think something like the next should be more useful:
While this may look straight-forward, this is easy and surely not as easy as replacing the error message. The current reported message is reported by the
Series
when is trying to be converted to an integer byint(pandas.Series())
, so it has nothing to do withapply
.I think it's doable to have an appropriate error message, but not sure about the implications.
Feel free to discuss your proposals on how to fix it here, or to try your approach and open a PR, and have the discussion there.
The text was updated successfully, but these errors were encountered: