@@ -33,8 +33,11 @@ class ActionBase(metaclass=abc.ABCMeta):
3333 Base class for actions
3434 """
3535
36- def __init__ (self , action_type : ActionType ) -> None :
36+ def __init__ (self , column_name : str , action_type : ActionType ) -> None :
37+ self .column_name = column_name
3738 self .action_type = action_type
39+ self .idx = None
40+ self .key = (self .column_name , self .action_type )
3841
3942 @abc .abstractmethod
4043 def act (self , ** ops ) -> None :
@@ -77,8 +80,8 @@ class ActionIdentity(ActionBase):
7780 Implements the identity action
7881 """
7982
80- def __init__ (self ) -> None :
81- super (ActionIdentity , self ).__init__ (action_type = ActionType .IDENTITY )
83+ def __init__ (self , column_name : str ) -> None :
84+ super (ActionIdentity , self ).__init__ (column_name = column_name , action_type = ActionType .IDENTITY )
8285
8386 def act (self , ** ops ):
8487 """
@@ -93,8 +96,8 @@ class ActionTransform(ActionBase):
9396 """
9497 Implements the transform action
9598 """
96- def __init__ (self ):
97- super (ActionTransform , self ).__init__ (action_type = ActionType .TRANSFORM )
99+ def __init__ (self , column_name : str ):
100+ super (ActionTransform , self ).__init__ (column_name = column_name , action_type = ActionType .TRANSFORM )
98101
99102 def act (self , ** ops ):
100103 """
@@ -109,8 +112,8 @@ class ActionSuppress(ActionBase, _WithTable):
109112 """
110113 Implements the suppress action
111114 """
112- def __init__ (self , suppress_table = None ):
113- super (ActionSuppress , self ).__init__ (action_type = ActionType .SUPPRESS )
115+ def __init__ (self , column_name : str , suppress_table = None ):
116+ super (ActionSuppress , self ).__init__ (column_name = column_name , action_type = ActionType .SUPPRESS )
114117
115118 if suppress_table is not None :
116119 self .table = suppress_table
@@ -136,36 +139,47 @@ def act(self, **ops) -> None:
136139 move_next (iterators = self .iterators )
137140
138141
139- class ActionGeneralize (ActionBase ):
142+ class ActionGeneralize (ActionBase , _WithTable ):
140143 """
141144 Implements the generalization action
142145 """
143146
144- def __init__ (self ):
145- super (ActionGeneralize , self ).__init__ (action_type = ActionType .GENERALIZE )
146- self .generalization_table = {}
147+ def __init__ (self , column_name : str , generalization_table : dict = None ):
148+ super (ActionGeneralize , self ).__init__ (column_name = column_name , action_type = ActionType .GENERALIZE )
149+
150+ if generalization_table is not None :
151+ self .table = generalization_table
152+
153+ # fill in the iterators
154+ self .iterators = [iter (self .table [item ]) for item in self .table ]
147155
148156 def act (self , ** ops ):
149157 """
150158 Perform an action
151159 :return:
152160 """
161+
162+ # get the values of the column
163+ col_vals = ops ['data' ].values
164+
153165 # generalize the data given
154- for item in ops [ "data" ] :
166+ for i , item in enumerate ( col_vals ) :
155167
168+ #print(item)
156169 # How do we update the generalizations?
157- value = self .generalization_table [item ].value
158- item = value
170+ value = self .table [item ].value
171+ col_vals [ i ] = value
159172
160- # update the generalization
161- self ._move_next ()
173+ ops ["data" ] = col_vals
162174
163- def add_generalization (self , key : str , values : HierarchyBase ) -> None :
164- self .generalization_table [key ] = values
175+ # update the generalization iterators
176+ # so next time we visit we update according to
177+ # the new values
178+ move_next (iterators = self .iterators )
179+ return ops ['data' ]
165180
166- def _move_next (self ):
181+ def add_generalization (self , key : str , values : HierarchyBase ) -> None :
182+ self .table [key ] = values
167183
168- for item in self .generalization_table :
169- next (self .generalization_table [item ])
170184
171185
0 commit comments