-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ERR: better error message on invalid return from .apply #13820
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
Comments
Mind explaining your actual use-case a bit? In general Series / DataFrames don't work very well with nested data, though this could change in the future. As a workaround you can achieve this by calling your function on each element of |
yeah this is completely non-idiomatic you can do this:
pandas expects to be able to coerce non-same sized input according to the original size if its not labeled. So I would expect your original example to fail. I suppose it could raise a better error message though. Its just not reasonable to return arbitrary output and have pandas automatically assign labels to it. |
Thank you both for your answer.
So, I am not sure the corrected issue title matches with my case. @jreback could you double check with the new elements I added? A workaround I found is to convert the list to string in order to force to keep it in a single column: def apply_list (row):
return str([2*row['A'], 4*row['C'], 3*row['B']]) |
This looks to work on master/0.25.1 now. Could use a regression test.
|
Code Sample
(Wrong) Error Output
Expected Result & Use case
Expected: a Serie containing a list for each row which are in my real case the result of a matrix multiplication processed with values coming from other columns (see a complete example in the next section)
Note: It works with a DataFrame without a datetime column (but not with a DataFrame with it):
Complete example with matrix multiplication
It works as I want if there is no datetime column in df:
output of
pd.show_versions()
The text was updated successfully, but these errors were encountered: