@@ -106,27 +106,27 @@ def expected_results_pair_items_df(self) -> pd.DataFrame:
106
106
107
107
def test_calc_association_all_single_items (self , transactions_df , expected_results_single_items_df ):
108
108
"""Test calculating association rules for a single item versus another of item for all items."""
109
- associations_df = ProductAssociation . _calc_association (
109
+ associations_df = ProductAssociation (
110
110
df = transactions_df ,
111
111
value_col = "product" ,
112
112
group_col = cols .transaction_id ,
113
113
)
114
-
115
- pd .testing .assert_frame_equal (associations_df , expected_results_single_items_df )
114
+ result = associations_df . df
115
+ pd .testing .assert_frame_equal (result , expected_results_single_items_df )
116
116
117
117
def test_calc_association_target_single_items (self , transactions_df , expected_results_single_items_df ):
118
118
"""Test calculating association rules for target single item versus another of item."""
119
119
target_item = "bread"
120
120
121
- calc_df = ProductAssociation . _calc_association (
121
+ calc_df = ProductAssociation (
122
122
df = transactions_df ,
123
123
value_col = "product" ,
124
124
group_col = cols .transaction_id ,
125
125
target_item = target_item ,
126
126
)
127
-
127
+ result = calc_df . df
128
128
pd .testing .assert_frame_equal (
129
- calc_df ,
129
+ result ,
130
130
expected_results_single_items_df [expected_results_single_items_df ["product_1" ] == target_item ].reset_index (
131
131
drop = True ,
132
132
),
@@ -136,15 +136,16 @@ def test_calc_association_min_occurrences(self, transactions_df, expected_result
136
136
"""Test calculating association rules with a min occurrences level."""
137
137
min_occurrences = 2
138
138
139
- calc_df = ProductAssociation . _calc_association (
139
+ calc_df = ProductAssociation (
140
140
df = transactions_df ,
141
141
value_col = "product" ,
142
142
group_col = cols .transaction_id ,
143
143
min_occurrences = min_occurrences ,
144
144
)
145
145
146
+ result = calc_df .df
146
147
pd .testing .assert_frame_equal (
147
- calc_df ,
148
+ result ,
148
149
expected_results_single_items_df [
149
150
(expected_results_single_items_df ["occurrences_1" ] >= min_occurrences )
150
151
& (expected_results_single_items_df ["occurrences_2" ] >= min_occurrences )
@@ -155,15 +156,16 @@ def test_calc_association_min_cooccurrences(self, transactions_df, expected_resu
155
156
"""Test calculating association rules with a min occurrences level."""
156
157
min_cooccurrences = 2
157
158
158
- calc_df = ProductAssociation . _calc_association (
159
+ calc_df = ProductAssociation (
159
160
df = transactions_df ,
160
161
value_col = "product" ,
161
162
group_col = cols .transaction_id ,
162
163
min_cooccurrences = min_cooccurrences ,
163
164
)
164
165
166
+ result = calc_df .df
165
167
pd .testing .assert_frame_equal (
166
- calc_df ,
168
+ result ,
167
169
expected_results_single_items_df [
168
170
(expected_results_single_items_df ["cooccurrences" ] >= min_cooccurrences )
169
171
].reset_index (drop = True ),
@@ -173,15 +175,16 @@ def test_calc_association_min_support(self, transactions_df, expected_results_si
173
175
"""Test calculating association rules with a min occurrences level."""
174
176
min_support = 0.25
175
177
176
- calc_df = ProductAssociation . _calc_association (
178
+ calc_df = ProductAssociation (
177
179
df = transactions_df ,
178
180
value_col = "product" ,
179
181
group_col = cols .transaction_id ,
180
182
min_support = min_support ,
181
183
)
182
184
185
+ result = calc_df .df
183
186
pd .testing .assert_frame_equal (
184
- calc_df ,
187
+ result ,
185
188
expected_results_single_items_df [(expected_results_single_items_df ["support" ] >= min_support )].reset_index (
186
189
drop = True ,
187
190
),
@@ -191,15 +194,16 @@ def test_calc_association_min_confidence(self, transactions_df, expected_results
191
194
"""Test calculating association rules with a min occurrences level."""
192
195
min_confidence = 0.25
193
196
194
- calc_df = ProductAssociation . _calc_association (
197
+ calc_df = ProductAssociation (
195
198
df = transactions_df ,
196
199
value_col = "product" ,
197
200
group_col = cols .transaction_id ,
198
201
min_confidence = min_confidence ,
199
202
)
200
203
204
+ result = calc_df .df
201
205
pd .testing .assert_frame_equal (
202
- calc_df ,
206
+ result ,
203
207
expected_results_single_items_df [
204
208
(expected_results_single_items_df ["confidence" ] >= min_confidence )
205
209
].reset_index (drop = True ),
@@ -209,15 +213,16 @@ def test_calc_association_min_uplift(self, transactions_df, expected_results_sin
209
213
"""Test calculating association rules with a min occurrences level."""
210
214
min_uplift = 1
211
215
212
- calc_df = ProductAssociation . _calc_association (
216
+ calc_df = ProductAssociation (
213
217
df = transactions_df ,
214
218
value_col = "product" ,
215
219
group_col = cols .transaction_id ,
216
220
min_uplift = min_uplift ,
217
221
)
218
222
223
+ result = calc_df .df
219
224
pd .testing .assert_frame_equal (
220
- calc_df ,
225
+ result ,
221
226
expected_results_single_items_df [(expected_results_single_items_df ["uplift" ] >= min_uplift )].reset_index (
222
227
drop = True ,
223
228
),
0 commit comments