Skip to content

Commit

Permalink
improved CSE (common subexpression elimination) for c.group_by mode
Browse files Browse the repository at this point in the history
  • Loading branch information
westandskif committed Sep 4, 2024
1 parent 541a8fe commit a65ec41
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.14.2 (2024-09-04)

- improved CSE (common subexpression elimination) for `c.group_by` mode

## 1.14.1 (2024-09-01)

- python 3.13t (free threading) support
Expand Down
2 changes: 1 addition & 1 deletion src/convtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
from ._dt import DateGrid, DateTimeGrid


__version__ = "1.14.1"
__version__ = "1.14.2"
10 changes: 5 additions & 5 deletions src/convtools/_aggregations.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ def fuzzy_merge_aggregate_cmp(x, y):


def no_side_effects_test(x):
if isinstance(x, AstCall):
x = x.func
if isinstance(x, AstAttribute):
x = x.value
elif (
if (
isinstance(x, AstCompare)
and isinstance(x.ops[0], AstIs)
and isinstance(x.comparators[0], AstName)
and x.comparators[0].id == "_none"
):
x = x.left
elif isinstance(x, AstCall):
x = x.func
if isinstance(x, AstAttribute):
x = x.value
return isinstance(x, AstName) and x.id.startswith("agg_data_")


Expand Down
17 changes: 17 additions & 0 deletions tests/test_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,23 @@ def test_group_by_reducers_reuse():
},
]

converter = (
c.group_by(c.item("x"))
.aggregate(
{
"x": c.item("x"),
"y": c.ReduceFuncs.Sum(c.item("obj", "y")),
"z": c.ReduceFuncs.Sum(c.item("obj", "z")),
}
)
.gen_converter(debug=False)
)
code_str = format_code(get_code_str(converter))
assert (
code_str.count("row_['obj']") == 1
or code_str.count('row_["obj"]') == 1
)


def test_aggregate_reducers_reuse():
converter = c.aggregate(
Expand Down

0 comments on commit a65ec41

Please sign in to comment.