-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: fix AttributeError raised in libreduction #29100
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
Conversation
pandas/core/groupby/generic.py
Outdated
@@ -261,7 +261,7 @@ def aggregate(self, func=None, *args, **kwargs): | |||
|
|||
try: | |||
return self._python_agg_general(func, *args, **kwargs) | |||
except AssertionError: | |||
except (AssertionError, AttributeError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what hits AttributeError here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have tests that raise AttributeError here (in master) when a Categorical or IntegerArray is passed to SeriesBinGrouper.
@@ -203,7 +203,8 @@ cdef class SeriesBinGrouper: | |||
self.f = f | |||
|
|||
values = series.values | |||
if not values.flags.c_contiguous: | |||
if util.is_array(values) and not values.flags.c_contiguous: | |||
# e.g. Categorical has no `flags` attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work with Categorical otherwise (the BinGrouper)? do we need tests here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have tests that get here with Categorical and IntegerArray.
lgtm. |
Looks like we have "slow" tests that still raise AttributeError. AFAICT within the groupby/reduce machinery a For now I'm reverting the re-raising of AttributeError and adding the index_data thing to my list of groupby-followups. |
lgtm as well.
Hmm do we just not hit these at all in CI? |
It's hit in the CI, but it wasn't hit locally before I opened the PR. Currently working on a branch that I think fixes the remaining AttributeError, but longer-term the _index_data thing is pretty nasty. |
Shouldn't this add a test, or remove an otherwise catched exception? |
There is one more case where an AttributeError gets raised, so we can't just yet. |
But the cause of the regression in the case I reported was that the AttributeError was no longer catched? Or for the case in our current tests, that's then probably still catched elsewhere? |
The thing that we recently stopped catching (or more specifically, started re-raising) consistently is AssertionError. Without knowing anything about the geopandas case, this is my best guess for what might have been affected.
If you look at the most recent commit for this PR, you'll see that in the status quo (and in this PR, after the last commit), AttributeError is caught in an |
My example was running into another try/except block (see the one I linked in #29141 (comment)), so I suppose that is simply not covered by our tests. The reason it was working is because pandas/pandas/core/groupby/groupby.py Lines 893 to 905 in 6c898e6
|
The branch that fixes the remaining AttributeError (and so starts re-raising all AttributeErrors) is passing locally, will make a PR for that as a follow-up once this goes in. |
thanks |
Bite-sized chunk of the promised "addressing of recently-added TODOs" for groupby Exception un-suppression. cc @WillAyd @jreback.