-
Notifications
You must be signed in to change notification settings - Fork 16
feat(xorq): autocleaning + interpreter version with 5 ported commands #767
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
paddymul
wants to merge
1
commit into
main
Choose a base branch
from
feat/xorq-autoclean-interpreter
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
Changes from all commits
Commits
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,22 @@ | ||
| from buckaroo.dataflow.autocleaning import AutocleaningConfig | ||
| from buckaroo.customizations.xorq_commands import ( | ||
| DropCol, DropDuplicates, FillNA, NoOp, Search) | ||
|
|
||
|
|
||
| XORQ_BASE_COMMANDS = [DropCol, DropDuplicates, FillNA, NoOp, Search] | ||
|
|
||
|
|
||
| class NoCleaningConfXorq(AutocleaningConfig): | ||
| """No automatic cleaning — just expose the interpreter and quick-search. | ||
|
|
||
| The autocleaning analysis classes are pandas-flavoured (HeuristicFracs, | ||
| PdCleaningStats, ...) and would not work against ibis exprs, so we | ||
| leave the analysis list empty. The lisp interpreter still runs against | ||
| the expression via the ported xorq_commands, and the frontend's | ||
| quick-search box drives the Search command. | ||
| """ | ||
|
|
||
| autocleaning_analysis_klasses = [] | ||
| command_klasses = XORQ_BASE_COMMANDS | ||
| quick_command_klasses = [Search] | ||
| name = "" |
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,114 @@ | ||
| """buckaroo Commands targeting xorq/ibis expressions. | ||
|
|
||
| Each command mirrors the shape of pandas_commands.py / polars_commands.py: | ||
| a ``command_default`` / ``command_pattern`` pair that the frontend reads, | ||
| plus ``transform`` (expr -> expr) and ``transform_to_py`` (str). Unlike | ||
| the pandas commands, transforms never mutate — ibis expressions are | ||
| immutable, so each transform builds and returns a new expression that | ||
| the dataflow continues to push down. | ||
|
|
||
| xorq is an optional dependency; this module is import-safe without it, | ||
| because nothing here imports xorq at module load. Transforms call methods | ||
| on the passed-in expression (duck typing), so the module only matters | ||
| when an ibis/xorq expression actually flows through. | ||
| """ | ||
|
|
||
| from ..jlisp.lisp_utils import s | ||
|
|
||
|
|
||
| class Command: | ||
| @staticmethod | ||
| def transform(expr, col, val): | ||
| return expr | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col, val): | ||
| return " # no op" | ||
|
|
||
|
|
||
| class NoOp(Command): | ||
| command_default = [s('noop'), s('df'), "col"] | ||
| command_pattern = [None] | ||
|
|
||
| @staticmethod | ||
| def transform(expr, col): | ||
| return expr | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col): | ||
| return " #noop" | ||
|
|
||
|
|
||
| class DropCol(Command): | ||
| command_default = [s('dropcol'), s('df'), "col"] | ||
| command_pattern = [None] | ||
|
|
||
| @staticmethod | ||
| def transform(expr, col): | ||
| return expr.drop(col) | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col): | ||
| return f" expr = expr.drop('{col}')" | ||
|
|
||
|
|
||
| class FillNA(Command): | ||
| command_default = [s('fillna'), s('df'), "col", 0] | ||
| command_pattern = [[3, 'fillVal', 'type', 'integer']] | ||
|
|
||
| @staticmethod | ||
| def transform(expr, col, val): | ||
| return expr.mutate(**{col: expr[col].fill_null(val)}) | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col, val): | ||
| return f" expr = expr.mutate({col}=expr['{col}'].fill_null({val!r}))" | ||
|
|
||
|
|
||
| class DropDuplicates(Command): | ||
| command_default = [s('drop_duplicates'), s('df'), "col"] | ||
| command_pattern = [None] | ||
|
|
||
| @staticmethod | ||
| def transform(expr, col): | ||
| return expr.distinct(on=[col]) | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col): | ||
| return f" expr = expr.distinct(on=['{col}'])" | ||
|
|
||
|
|
||
| def _search_expr(expr, val): | ||
| """Filter rows where any string column contains ``val``. | ||
|
|
||
| Empty / None val short-circuits — the frontend sends "" to clear the | ||
| quick-search box, and pl.col-style ``contains(None)`` would drop every | ||
| row on the polars side; mirror that contract here. | ||
| """ | ||
| if val is None or val == "": | ||
| return expr | ||
| schema = expr.schema() | ||
| string_cols = [name for name in expr.columns if schema[name].is_string()] | ||
| if not string_cols: | ||
| return expr | ||
| cond = None | ||
| for c in string_cols: | ||
| c_cond = expr[c].contains(val) | ||
| cond = c_cond if cond is None else cond | c_cond | ||
| return expr.filter(cond) | ||
|
|
||
|
|
||
| class Search(Command): | ||
| command_default = [s('search'), s('df'), "col", ""] | ||
| command_pattern = [[3, 'term', 'type', 'string']] | ||
| quick_args_pattern = [[3, 'term', 'type', 'string']] | ||
|
|
||
| @staticmethod | ||
| def transform(expr, col, val): | ||
| return _search_expr(expr, val) | ||
|
|
||
| @staticmethod | ||
| def transform_to_py(expr, col, val): | ||
| return ( | ||
| " from buckaroo.customizations.xorq_commands import _search_expr\n" | ||
| f" expr = _search_expr(expr, '{val}')") | ||
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
Oops, something went wrong.
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.
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.
When a user applies this command, the inherited code generator wraps these snippets as
def clean(df): ... return dfinconfigure_utils.buckaroo_to_py, but the new xorq snippets assign toexprwithout ever defining it. For example, a drop-column op generates a function that raisesUnboundLocalErroratexpr = expr.drop(...)instead of providing usable generated code inoperation_results['generated_py_code']; the same pattern appears in the other non-noop xorq commands.Useful? React with 👍 / 👎.