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

14 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-02-25 20:09 +0000

1"""MostRecentPurchaseDate feature""" 

2import pyspark.sql.functions as f 

3from pyspark.sql import Column 

4 

5from .max_feature import Max 

6 

7 

8class MostRecentPurchaseDate(Max): 

9 def column_expression(self) -> Column: 

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

11 

12 @property 

13 def description_subject(self) -> str: 

14 return "Most recent purchase date" 

15 

16 def default_value(self) -> Column: 

17 return f.lit(None) 

18 

19 @property 

20 def commentary(self) -> str: 

21 return ( 

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

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

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

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

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

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

28 + "features is most useful to you." 

29 )