Skip to content

Bug: Don't intercept TypeError in DataFrame.agg #49399

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
rhshadrach opened this issue Oct 30, 2022 · 7 comments · Fixed by #49969
Closed

Bug: Don't intercept TypeError in DataFrame.agg #49399

rhshadrach opened this issue Oct 30, 2022 · 7 comments · Fixed by #49969
Assignees
Labels
Apply Apply, Aggregate, Transform, Map DataFrame DataFrame data structure Error Reporting Incorrect or improved errors from pandas good first issue

Comments

@rhshadrach
Copy link
Member

pandas/pandas/core/apply.py

Lines 735 to 745 in 3370c81

try:
result = super().agg()
except TypeError as err:
exc = TypeError(
"DataFrame constructor called with "
f"incompatible data and dtype: {err}"
)
raise exc from err
finally:
self.obj = obj
self.axis = axis

We intercept any TypeError and reword the message to be about the DataFrame constructor. This likely made sense before, but with the code being refactored and #43741, TypeErrors can occur for many different reasons. We should just remove the except block above.

@rhshadrach rhshadrach added Error Reporting Incorrect or improved errors from pandas Apply Apply, Aggregate, Transform, Map good first issue DataFrame DataFrame data structure labels Oct 30, 2022
@sarvaSanjay
Copy link
Contributor

So just to confirm all we want to do is delete lines 737-742 ? Or do we have to add more specific ways to intercept type errors?

@rhshadrach
Copy link
Member Author

So just to confirm all we want to do is delete lines 737-742 ?

That's correct; since this can raise for e.g. a user-defined function, I don't believe we can be any more helpful than just allowing the normal error to raise.

@sarvaSanjay
Copy link
Contributor

take

@alexanderwertman3
Copy link

I would like to work on this for a school project

@yuvanist
Copy link
Contributor

@sarvaSanjay If you are not updating the test for this, I'll take it. Please let me know.

@yuvanist
Copy link
Contributor

take

@yuvanist
Copy link
Contributor

@rhshadrach #49969 PR closes this. Please review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map DataFrame DataFrame data structure Error Reporting Incorrect or improved errors from pandas good first issue
Projects
None yet
4 participants