Skip to content
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

Add first & last aggregation ops #144

Merged
merged 18 commits into from
Aug 18, 2023
Prev Previous commit
Next Next commit
Lint
  • Loading branch information
PatrikDurdevic committed Aug 16, 2023
commit 503990ca96d5f1b39347867127218f84e5d7be79
4 changes: 2 additions & 2 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
AvgAggregationOp,
CountAggregationOp,
ExistsAggregationOp,
FirstAggregationOp,
LastAggregationOp,
MajorityAggregationOp,
MaxAggregationOp,
MinAggregationOp,
SumAggregationOp,
FirstAggregationOp,
LastAggregationOp,
)
from trane.ops.filter_ops import (
AllFilterOp,
Expand Down
6 changes: 4 additions & 2 deletions tests/ops/test_aggregation_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from trane.ops.aggregation_ops import (
AvgAggregationOp,
CountAggregationOp,
FirstAggregationOp,
LastAggregationOp,
MajorityAggregationOp,
MaxAggregationOp,
MinAggregationOp,
SumAggregationOp,
FirstAggregationOp,
LastAggregationOp
)
from trane.ops.utils import get_aggregation_ops

Expand Down Expand Up @@ -56,12 +56,14 @@ def test_min_agg_op(df):
assert output == np.min(df["col"])
assert "the minimum <col> in all related records" in op.generate_description()


def test_first_agg_op(df):
op = FirstAggregationOp("col")
output = op(df)
assert output == df["col"].iloc[0]
assert "the first <col> in all related records" in op.generate_description()


def test_last_agg_op(df):
op = LastAggregationOp("col")
output = op(df)
Expand Down
4 changes: 2 additions & 2 deletions tests/ops/test_op_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
AvgAggregationOp,
CountAggregationOp,
ExistsAggregationOp,
FirstAggregationOp,
LastAggregationOp,
MajorityAggregationOp,
MaxAggregationOp,
MinAggregationOp,
SumAggregationOp,
FirstAggregationOp,
LastAggregationOp
)
from trane.ops.filter_ops import (
AllFilterOp,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
AvgAggregationOp,
CountAggregationOp,
ExistsAggregationOp,
FirstAggregationOp,
LastAggregationOp,
MajorityAggregationOp,
MaxAggregationOp,
MinAggregationOp,
SumAggregationOp,
FirstAggregationOp,
LastAggregationOp
)
from trane.ops.filter_ops import (
AllFilterOp,
Expand Down Expand Up @@ -249,6 +249,7 @@ def test_check_operations_cat():
result, modified_meta = _check_operations_valid(operations, table_meta)
assert result is True


def test_foreign_key():
table_meta = {
"id": ("Categorical", {"primary_key", "category"}),
Expand Down
1 change: 1 addition & 0 deletions trane/ops/aggregation_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def label_function(self, dataslice):
return None
return dataslice[self.column_name].iloc[0]


class LastAggregationOp(AggregationOpBase):
input_output_types = [("category", "category")]
description = " the last <{}> in all related records"
Expand Down