Skip to content

REF: _cython_agg_blocks #31752

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
wants to merge 4 commits into from
Closed

Conversation

jbrockmendel
Copy link
Member

This is effectively an alternative approach to #31616, trying to use a 1-pass approach.

This does not address the uniqueness problem discussed in #31735.

cc @TomAugspurger @WillAyd

@@ -1063,58 +1087,32 @@ def _cython_agg_blocks(
deleted_items.append(locs)
continue
else:
if isinstance(result, Series):
Copy link
Member

Choose a reason for hiding this comment

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

Hmm why is this required here?

Copy link
Member Author

Choose a reason for hiding this comment

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

we have test cases that get here with a Series and without this the cast just below here is inaccurate

Copy link
Member

Choose a reason for hiding this comment

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

Hmm that's unfortunate. Don't want to go too far down the typing road on this one but maybe should be using assert ... instead of cast

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

hmm, reveal_type(result) entering this block is object. probably need to take control of the type of result before this. does adding type annotations to _recast_result help?

Copy link
Member

Choose a reason for hiding this comment

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

it looks like since aggregate in SelectionMixin does not have type annotations, the return type of s.aggregate(lambda x: alt(x, axis=self.axis)) is Any and hence as result is object no type narrowing occurs. reveal_type(s) is 'pandas.core.groupby.groupby.GroupBy' so it's just aggregate that needs the annotations.

except ValueError:
# reshape to be valid for non-Extension Block
result = result.reshape(1, -1)
for i, col in enumerate(result.columns):
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps misinterpreting but does this not have a huge performance penalty? IIUC tried column iteration back in #28782 but performance took a pretty big hit in doing so

Copy link
Member Author

Choose a reason for hiding this comment

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

the actual aggregation isn't being done columnwise, just re-assembling new blocks

@WillAyd WillAyd added the Groupby label Feb 6, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

this is still really pretty gnarly. do you have time to really refactor this? e.g. move to internals & then cleanup.

split_items: List[np.ndarray] = []
split_frames: List[DataFrame] = []

def _recast_result(result, values):
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this somewhere else, pandas.core.dtypes.cast maybe

@jbrockmendel
Copy link
Member Author

closing to clear the queue

@jbrockmendel jbrockmendel added the Mothballed Temporarily-closed PR the author plans to return to label Apr 21, 2020
@jbrockmendel jbrockmendel removed the Mothballed Temporarily-closed PR the author plans to return to label Aug 27, 2020
@jbrockmendel jbrockmendel deleted the gb-idea branch August 27, 2020 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants