-
Notifications
You must be signed in to change notification settings - Fork 698
Dask backend execution #2557
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
jreback
merged 11 commits into
ibis-project:master
from
gerrymanoim:ibis-dask-execution
Dec 23, 2020
Merged
Dask backend execution #2557
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
30f8bee
Implement execution for dask backend
4f97f39
fix tests
ba0cd60
fix up conftest so dask passes
d0e75ff
do not drop the sorted value
ff5de84
fix tests correctly
a29f021
better imports for groupby objects
9988ee3
xfail udfs properly instead of not running them
6555d30
Update dask reqs for min version
8de540b
forward on partitions
b4ecc65
rip out timecontext
2c7f535
Lower the min required dask version
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| dask=2.22.0 |
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| dask | ||
| dask | ||
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
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 |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| # This is awaiting implementation of the rest of execution | ||
| # https://github.com/ibis-project/ibis/issues/2537 | ||
| from ibis.backends.pandas.core import execute, execute_node # noqa: F401,F403 | ||
| from .aggregations import * # noqa: F401,F403 | ||
| from .arrays import * # noqa: F401,F403 | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from .decimal import * # noqa: F401,F403 | ||
| from .generic import * # noqa: F401,F403 | ||
| from .indexing import * # noqa: F401,F403 | ||
| from .join import * # noqa: F401,F403 | ||
| from .maps import * # noqa: F401,F403 | ||
| from .numeric import * # noqa: F401,F403 | ||
| from .reductions import * # noqa: F401,F403 | ||
| from .selection import * # noqa: F401,F403 | ||
| from .strings import * # noqa: F401,F403 | ||
| from .structs import * # noqa: F401,F403 | ||
| from .temporal import * # noqa: F401,F403 | ||
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,143 @@ | ||
| """Execution rules for Aggregatons - mostly TODO | ||
|
|
||
| - ops.Aggregation | ||
| - ops.Any | ||
| - ops.NotAny | ||
| - ops.All | ||
| - ops.NotAll | ||
|
|
||
| """ | ||
|
|
||
| import functools | ||
| import operator | ||
| from typing import Optional | ||
|
|
||
| import dask.dataframe as dd | ||
|
|
||
| import ibis.expr.operations as ops | ||
| from ibis.backends.pandas.execution.generic import execute, execute_node | ||
| from ibis.expr.scope import Scope | ||
| from ibis.expr.typing import TimeContext | ||
|
|
||
|
|
||
| # TODO - aggregations - #2553 | ||
| # Not all code paths work cleanly here | ||
| @execute_node.register(ops.Aggregation, dd.DataFrame) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add to the list of things that we can register for pandas/dask |
||
| def execute_aggregation_dataframe( | ||
| op, data, scope=None, timecontext: Optional[TimeContext] = None, **kwargs | ||
| ): | ||
| assert op.metrics, 'no metrics found during aggregation execution' | ||
|
|
||
| if op.sort_keys: | ||
| raise NotImplementedError( | ||
| 'sorting on aggregations not yet implemented' | ||
| ) | ||
|
|
||
| predicates = op.predicates | ||
| if predicates: | ||
| predicate = functools.reduce( | ||
| operator.and_, | ||
| ( | ||
| execute(p, scope=scope, timecontext=timecontext, **kwargs) | ||
| for p in predicates | ||
| ), | ||
| ) | ||
| data = data.loc[predicate] | ||
|
|
||
| columns = {} | ||
|
|
||
| if op.by: | ||
| grouping_key_pairs = list( | ||
| zip(op.by, map(operator.methodcaller('op'), op.by)) | ||
| ) | ||
| grouping_keys = [ | ||
| by_op.name | ||
| if isinstance(by_op, ops.TableColumn) | ||
| else execute( | ||
| by, scope=scope, timecontext=timecontext, **kwargs | ||
| ).rename(by.get_name()) | ||
| for by, by_op in grouping_key_pairs | ||
| ] | ||
| columns.update( | ||
| (by_op.name, by.get_name()) | ||
| for by, by_op in grouping_key_pairs | ||
| if hasattr(by_op, 'name') | ||
| ) | ||
| source = data.groupby(grouping_keys) | ||
| else: | ||
| source = data | ||
|
|
||
| scope = scope.merge_scope(Scope({op.table.op(): source}, timecontext)) | ||
|
|
||
| pieces = [] | ||
| for metric in op.metrics: | ||
| piece = execute(metric, scope=scope, timecontext=timecontext, **kwargs) | ||
| piece.name = metric.get_name() | ||
| pieces.append(piece) | ||
|
|
||
| result = dd.concat(pieces, axis=1) | ||
|
|
||
| # If grouping, need a reset to get the grouping key back as a column | ||
| if op.by: | ||
| result = result.reset_index() | ||
|
|
||
| result.columns = [columns.get(c, c) for c in result.columns] | ||
|
|
||
| if op.having: | ||
| # .having(...) is only accessible on groupby, so this should never | ||
| # raise | ||
| if not op.by: | ||
| raise ValueError( | ||
| 'Filtering out aggregation values is not allowed without at ' | ||
| 'least one grouping key' | ||
| ) | ||
|
|
||
| # TODO(phillipc): Don't recompute identical subexpressions | ||
| predicate = functools.reduce( | ||
| operator.and_, | ||
| ( | ||
| execute(having, scope=scope, timecontext=timecontext, **kwargs) | ||
| for having in op.having | ||
| ), | ||
| ) | ||
| assert len(predicate) == len( | ||
| result | ||
| ), 'length of predicate does not match length of DataFrame' | ||
| result = result.loc[predicate.values] | ||
| return result | ||
|
|
||
|
|
||
| # TODO - aggregations - #2553 | ||
| # @execute_node.register((ops.Any, ops.All), (dd.Series, SeriesGroupBy)) | ||
| # def execute_any_all_series(op, data, aggcontext=None, **kwargs): | ||
| # if isinstance(aggcontext, (agg_ctx.Summarize, agg_ctx.Transform)): | ||
| # result = aggcontext.agg(data, type(op).__name__.lower()) | ||
| # else: | ||
| # result = aggcontext.agg( | ||
| # data, lambda data: getattr(data, type(op).__name__.lower())() | ||
| # ) | ||
| # return result | ||
|
|
||
| # TODO - aggregations - #2553 | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # @execute_node.register(ops.NotAny, (dd.Series, SeriesGroupBy)) | ||
| # def execute_notany_series(op, data, aggcontext=None, **kwargs): | ||
| # if isinstance(aggcontext, (agg_ctx.Summarize, agg_ctx.Transform)): | ||
| # result = ~(aggcontext.agg(data, 'any')) | ||
| # else: | ||
| # result = aggcontext.agg(data, lambda data: ~(data.any())) | ||
| # try: | ||
| # return result.astype(bool) | ||
| # except TypeError: | ||
| # return result | ||
|
|
||
| # TODO - aggregations - #2553 | ||
| # @execute_node.register(ops.NotAll, (dd.Series, SeriesGroupBy)) | ||
| # def execute_notall_series(op, data, aggcontext=None, **kwargs): | ||
| # if isinstance(aggcontext, (agg_ctx.Summarize, agg_ctx.Transform)): | ||
| # result = ~(aggcontext.agg(data, 'all')) | ||
| # else: | ||
| # result = aggcontext.agg(data, lambda data: ~(data.all())) | ||
| # try: | ||
| # return result.astype(bool) | ||
| # except TypeError: | ||
| # return result | ||
Oops, something went wrong.
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.