Coverage for jstark / features / most_recent_purchase_date.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-23 22:34 +0000

1"""MostRecentPurchaseDate feature""" 

2 

3import pyspark.sql.functions as f 

4from pyspark.sql import Column 

5 

6from jstark.features.max_feature import Max 

7 

8 

9class MostRecentPurchaseDate(Max): 

10 def column_expression(self) -> Column: 

11 return f.to_date(f.col("Timestamp")) 

12 

13 @property 

14 def description_subject(self) -> str: 

15 return "Most recent purchase date" 

16 

17 def default_value(self) -> Column: 

18 return f.lit(None) 

19 

20 @property 

21 def commentary(self) -> str: 

22 return ( 

23 "It is useful to be able to see when something was most recently " 

24 + "purchased.For example, grouping by Store and filtering where " 

25 + "MostRecentPurchaseDate is more than 2 days ago could be a useful " 

26 + "indicator of things which might not be available for purchase." 

27 + "Also note that this is very similar to " 

28 + f"RecencyDays_{self.feature_period.mnemonic} so consider which of these " 

29 + "features is most useful to you." 

30 )