Skip to content

Commit 3d90958

Browse files
committed
rewrite basketWeeks expression
Previous implementation wrapped each addition operation in an unnecessary set of parentheses therefore the expression looked like this: [Column<'coalesce( ((((((((((((((((((((((((((((((((((((((((((((((((((((( 0 + CASE WHEN (coalesce(count(CASE WHEN ...)))) + CASE WHEN (coalesce(count(CASE WHEN ...)))) + etc... which was quite annoyinf. SO I've rewritten it so that doesn't happen.
1 parent b0a7ec4 commit 3d90958

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

jstark/features/basket_periods.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ class BasketPeriods(DerivedFeature):
1212
"""BasketPeriods feature"""
1313

1414
def column_expression(self) -> Column:
15-
expr = f.lit(0)
15+
exprs = []
1616
for period in range(self.feature_period.end, self.feature_period.start + 1):
17-
expr = expr + f.when(
18-
BasketCount(
19-
as_at=self.as_at,
20-
feature_period=FeaturePeriod(
21-
self.feature_period.period_unit_of_measure, period, period
22-
),
23-
).column
24-
> 0,
25-
1,
26-
).otherwise(0)
27-
return expr
17+
exprs.append(
18+
f.when(
19+
BasketCount(
20+
as_at=self.as_at,
21+
feature_period=FeaturePeriod(
22+
self.feature_period.period_unit_of_measure, period, period
23+
),
24+
).column
25+
> 0,
26+
1,
27+
).otherwise(0)
28+
)
29+
return sum(exprs)
2830

2931
def default_value(self) -> Column:
3032
return f.lit(None)

0 commit comments

Comments
 (0)