Skip to content

REF: check instead of catching TypeError #29587

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

Merged
merged 2 commits into from
Nov 14, 2019

Conversation

jbrockmendel
Copy link
Member

No description provided.

return concat(results, keys=keys, axis=1, sort=False)
except TypeError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's an example that now ran into this TypeError?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's an example that now ran into this TypeError?

results = [3, 2, 1.5]; keys = ['size', 'count', 'mean']

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant the original dataframe / groupby example or test case that gives those values at this location

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identifying some relevant cases with an assert False, the place to look is in tests.frame.test_apply, e.g. test_non_callable_aggregates

@jreback jreback added this to the 1.0 milestone Nov 13, 2019
@jreback jreback merged commit db4095e into pandas-dev:master Nov 14, 2019
@jreback
Copy link
Contributor

jreback commented Nov 14, 2019

thanks @jbrockmendel

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Nov 14, 2019

@jreback if I review a PR with a comment, can you try to give me a little bit of time to respond to Brock's response?

@jbrockmendel thanks for that reference. So in that test case, you have functions that return single numbers.
But, you can also have an aggregation that returns an array-like or list, which has a dimension, but cannot be concatted. Quick dummy example with the case from the tests:

In [8]: df = DataFrame( 
   ...:     {"A": [None, 2, 3], "B": [1.0, np.nan, 3.0], "C": ["foo", None, "bar"]} 
   ...: )  

In [9]: df.agg([lambda x: list(x.unique())]) 

Out[9]: 
                        A                B                 C
<lambda>  [nan, 2.0, 3.0]  [1.0, nan, 3.0]  [foo, None, bar]

This now fails.
(the above example looks a bit unnatural, but in general, returning lists from an aggregation is something that certainly gets done I think, also in groupby context)

@jreback
Copy link
Contributor

jreback commented Nov 14, 2019

@jorisvandenbossche i gave a day here which is reasonable
if you want to block then put a hold on the review

@jbrockmendel
Copy link
Member Author

@jreback while i agree an explicit "hold" would be helpful, I think Joris gets some extra slack because of the timezone differences.

@jorisvandenbossche have i mentioned recently how much I dislike listlike corner cases? But the case you brought is Technically Correct, so I'd be OK if you want to revert (and add that test case)

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Nov 14, 2019

@jreback while i agree an explicit "hold" would be helpful, I think Joris gets some extra slack because of the timezone differences.

Indeed ;) For me, the "1 day" (15 hours since Brocks comment) was just a morning after having slept.
Maybe just interpret a comment that is not accompanied with a github approve as a sign that I want to check back?

But the case you brought is Technically Correct, so I'd be OK if you want to revert (and add that test case)

Do you directly think of another way to do this that you would prefer more than the try/except? Otherwise I can indeed do a revert yes.

@jbrockmendel
Copy link
Member Author

Do you directly think of another way to do this that you would prefer more than the try/except?

The check in this PR was the best idea I had. Do you have any suggestions?

@jorisvandenbossche
Copy link
Member

We could check for actual series/frame objects (since concat only allows that), but personally, I find this a perfect use case for the try except.

jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Nov 15, 2019
@jorisvandenbossche
Copy link
Member

Added a test case here: #29632

Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
@jbrockmendel jbrockmendel deleted the faster51b branch November 20, 2021 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants