-
Notifications
You must be signed in to change notification settings - Fork 70
ENH: len for groupby #533
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
Open
RayJi01
wants to merge
34
commits into
xorbitsai:main
Choose a base branch
from
RayJi01:feature/len_for_groupby
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ENH: len for groupby #533
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
35a6a8a
fix some minor issues on formatting
RayJi01 d6b836a
Merge branch 'xprobe-inc:main' into main
RayJi01 5376759
Merge branch 'xprobe-inc:main' into main
RayJi01 e7c6224
first try on implement Len Operands
RayJi01 a7819c5
first try on implement Len Operands2
RayJi01 9d647f1
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 98f0a08
issues of reducer_index
RayJi01 f21a683
issues of reducer_index
RayJi01 6235355
Merge branch 'xprobe-inc:main' into main
RayJi01 ba93ce7
Fix tile
UranusSeven 5dbbbb0
len method implemented with random test passed
RayJi01 4f9106f
try to solve chunk_size issues
RayJi01 59fc701
multiple chunks(chunk_size) implemented with UT and IT passed
RayJi01 6be18c2
Merge branch 'xprobe-inc:main' into main
RayJi01 c66a5b9
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 75edbdf
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 5be25cf
Merge branch 'xprobe-inc:main' into main
RayJi01 a73eb21
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 150b30c
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 2afbd92
Merge branch 'xprobe-inc:main' into main
RayJi01 d1b77e3
Merge branch 'xprobe-inc:main' into main
RayJi01 b899fe0
first try on implement Len Operands
RayJi01 a39c029
first try on implement Len Operands2
RayJi01 9710c4c
issues of reducer_index
RayJi01 472d03c
issues of reducer_index
RayJi01 b0c3f94
Fix tile
UranusSeven c356e0f
len method implemented with random test passed
RayJi01 3285a68
try to solve chunk_size issues
RayJi01 b2a647c
multiple chunks(chunk_size) implemented with UT and IT passed
RayJi01 04939bf
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 7178676
Merge remote-tracking branch 'origin/feature/len_for_groupby' into fe…
RayJi01 33da36e
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 1fd2dfd
Merge branch 'main' into feature/len_for_groupby
mergify[bot] 0cf151b
Merge branch 'main' into feature/len_for_groupby
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import pandas as pd | ||
|
||
from ... import opcodes | ||
from ...core import OutputType | ||
from ...core.operand import Operand, OperandStage | ||
from ..operands import DataFrameOperandMixin | ||
|
||
|
||
class GroupByLen(DataFrameOperandMixin, Operand): | ||
_op_type_ = opcodes.GROUPBY_LEN | ||
|
||
def __call__(self, groupby): | ||
return self.new_scalar([groupby]) | ||
|
||
@classmethod | ||
def tile(cls, op: "GroupByLen"): | ||
in_groupby = op.inputs[0] | ||
|
||
# generate map chunks | ||
map_chunks = [] | ||
for chunk in in_groupby.chunks: | ||
map_op = op.copy().reset_key() | ||
map_op.stage = OperandStage.map | ||
map_op.output_types = [OutputType.series] | ||
chunk_inputs = [chunk] | ||
|
||
map_chunks.append(map_op.new_chunk(chunk_inputs)) | ||
|
||
# generate reduce chunks, we only need one reducer here. | ||
out_chunks = [] | ||
reduce_op = op.copy().reset_key() | ||
reduce_op.output_types = [OutputType.scalar] | ||
reduce_op.stage = OperandStage.reduce | ||
params = dict(dtype=int) | ||
out_chunks.append( | ||
reduce_op.new_chunk(map_chunks, shape=(), index=(0,), dtype=int) | ||
) | ||
|
||
# final wrap up: | ||
new_op = op.copy() | ||
params = op.outputs[0].params.copy() | ||
|
||
params.pop("shape") | ||
|
||
params["chunks"] = out_chunks | ||
return new_op.new_scalars(op.inputs, **params) | ||
|
||
@classmethod | ||
def execute_map(cls, ctx, op: "GroupByLen"): | ||
chunk = op.outputs[0] | ||
in_df_grouped = ctx[op.inputs[0].key] | ||
|
||
# grouped object .size() method ensure every unique keys | ||
summary = in_df_grouped.size() | ||
sum_indexes = summary.index | ||
|
||
res = [] | ||
for index in sum_indexes: | ||
res.append(index) | ||
|
||
# use series to convey every index store in this level | ||
ctx[chunk.key, 1] = pd.Series(res) | ||
|
||
@classmethod | ||
def execute_reduce(cls, ctx, op: "GroupByLen"): | ||
chunk = op.outputs[0] | ||
key = op.inputs[0].key | ||
|
||
res = set() | ||
input_series = ctx[key, 1] | ||
res.update(input_series) | ||
|
||
res_len = len(res) | ||
ctx[chunk.key] = res_len | ||
|
||
@classmethod | ||
def execute(cls, ctx, op: "GroupByLen"): | ||
if op.stage == OperandStage.map: | ||
cls.execute_map(ctx, op) | ||
elif op.stage == OperandStage.reduce: | ||
cls.execute_reduce(ctx, op) | ||
|
||
|
||
def groupby_len(groupby): | ||
op = GroupByLen() | ||
return op(groupby).execute().fetch() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.