22
33import math
44import random
5+ from typing import Optional
56
67import numpy as np
78import numpy .typing as npt
@@ -31,12 +32,17 @@ def __init__(
3132 counters_factory : CountersFactory ,
3233 pids : DataFrame ,
3334 data : DataFrame ,
35+ value_safe_columns_array : Optional [list [bool ]] = None ,
3436 ) -> None :
3537 self .anonymization_params = anonymization_params
3638 self .bucketization_params = bucketization_params
3739 self .counters_factory = counters_factory
3840 self .orig_pids = pids
3941 self .orig_data = data
42+ if value_safe_columns_array is None :
43+ self .value_safe_columns_array = [False ] * len (data .columns )
44+ else :
45+ self .value_safe_columns_array = value_safe_columns_array
4046 self .unsafe_rng = random .Random (0 )
4147
4248 assert len (pids ) == len (data )
@@ -73,7 +79,7 @@ def __init__(
7379 snapped_intervals = list (self .snapped_intervals )
7480 for i in range (self .dimensions ):
7581 combination = (ColumnId (i ),)
76- tree = self ._build_tree (combination ).push_down_1dim_root ()
82+ tree = self ._build_tree (combination , self . value_safe_columns_array [ i ] ).push_down_1dim_root ()
7783 snapped_intervals [i ] = tree .snapped_intervals [0 ]
7884 self ._tree_cache [combination ] = tree # Cache the flattened version of the tree.
7985 self .snapped_intervals = tuple (snapped_intervals )
@@ -86,7 +92,7 @@ def _get_subnodes(self, upper_combination: Combination) -> Subnodes:
8692 for sub_combination in sub_combinations
8793 )
8894
89- def _build_tree (self , combination : Combination ) -> Node :
95+ def _build_tree (self , combination : Combination , value_safe_flag : bool = False ) -> Node :
9096 subnodes = self ._get_subnodes (combination )
9197
9298 # Hash column names into the tree's base bucket seed.
@@ -112,6 +118,7 @@ def _build_tree(self, combination: Combination) -> Node:
112118 self .bucketization_params ,
113119 row_limit ,
114120 self .counters_factory ,
121+ value_safe_flag ,
115122 )
116123
117124 root_intervals = get_items_combination (combination , self .snapped_intervals )
0 commit comments