|
11 | 11 | make_privacy_loss_block, |
12 | 12 | make_privacy_unit_block, |
13 | 13 | ) |
14 | | -from dp_wizard.utils.code_generators.analyses import histogram |
15 | 14 | from dp_wizard.utils.dp_helper import confidence |
16 | 15 | from dp_wizard.utils.shared.bins import make_cut_points |
17 | 16 |
|
@@ -147,12 +146,13 @@ def bin_template(GROUPS, BIN_NAME): |
147 | 146 | DefaultsTemplate(basic_template) |
148 | 147 | .fill_values(GROUPS=groups, MAX_ROWS=max_rows) |
149 | 148 | .finish() |
150 | | - ] + [ |
151 | | - DefaultsTemplate(bin_template) |
152 | | - .fill_values(GROUPS=groups, BIN_NAME=bin_name) |
153 | | - .finish() |
154 | | - for bin_name in bin_names |
155 | 149 | ] |
| 150 | + for bin_name in bin_names: |
| 151 | + margins.append( |
| 152 | + DefaultsTemplate(bin_template) |
| 153 | + .fill_values(GROUPS=groups, BIN_NAME=bin_name) |
| 154 | + .finish() |
| 155 | + ) |
156 | 156 |
|
157 | 157 | margins_list = "[" + ", ".join(margins) + "\n ]" |
158 | 158 | return margins_list |
@@ -248,30 +248,23 @@ def _make_partial_stats_context(self): |
248 | 248 | for name, plan in self.analysis_plan.analysis_columns.items() |
249 | 249 | if has_bins(get_statistic_by_name(plan[0].statistic_name)) |
250 | 250 | ] |
| 251 | + all_groups_have_keys = all( |
| 252 | + len(group_keys) > 0 for group_keys in self.analysis_plan.groups.values() |
| 253 | + ) |
251 | 254 |
|
252 | 255 | privacy_unit_block = make_privacy_unit_block( |
253 | 256 | contributions=self.analysis_plan.contributions, |
254 | 257 | contributions_entity=self.analysis_plan.contributions_entity, |
255 | 258 | ) |
256 | 259 | privacy_loss_block = make_privacy_loss_block( |
257 | | - pure=False, |
| 260 | + pure=all_groups_have_keys, |
258 | 261 | epsilon=self.analysis_plan.epsilon, |
259 | 262 | max_rows=self.analysis_plan.max_rows, |
260 | 263 | ) |
261 | | - |
262 | | - is_just_histograms = all( |
263 | | - plan_column[0].statistic_name == histogram.name |
264 | | - for plan_column in self.analysis_plan.analysis_columns.values() |
265 | | - ) |
266 | | - margins_list = ( |
267 | | - # Histograms don't need margins. |
268 | | - "[]" |
269 | | - if is_just_histograms |
270 | | - else self._make_margins_list( |
271 | | - bin_names=[f"{name}_bin" for name in bin_column_names], |
272 | | - groups=self.analysis_plan.groups, |
273 | | - max_rows=self.analysis_plan.max_rows, |
274 | | - ) |
| 264 | + margins_list = self._make_margins_list( |
| 265 | + bin_names=[f"{name}_bin" for name in bin_column_names], |
| 266 | + groups=self.analysis_plan.groups, |
| 267 | + max_rows=self.analysis_plan.max_rows, |
275 | 268 | ) |
276 | 269 | extra_columns = ", ".join( |
277 | 270 | [ |
|
0 commit comments