@@ -142,15 +142,12 @@ def fit(self, X, y=None, **kwargs):
142142 if X [self .cols ].isnull ().any ().any ():
143143 raise ValueError ('Columns to be encoded can not contain null' )
144144
145- # TODO: when these are settled, make the code sleeker
146- if self .handle_missing == 'error' :
147- oe_missing_strat = 'error'
148- elif self .handle_missing == 'return_nan' :
149- oe_missing_strat = 'return_nan'
150- elif self .handle_missing == 'value' :
151- oe_missing_strat = 'value'
152- elif self .handle_missing == 'indicator' :
153- oe_missing_strat = 'return_nan'
145+ oe_missing_strat = {
146+ 'error' : 'error' ,
147+ 'return_nan' : 'return_nan' ,
148+ 'value' : 'value' ,
149+ 'indicator' : 'return_nan' ,
150+ }[self .handle_missing ]
154151
155152 self .ordinal_encoder = OrdinalEncoder (
156153 verbose = self .verbose ,
@@ -194,12 +191,12 @@ def generate_mapping(self):
194191 index = []
195192 new_columns = []
196193
197- add_me_to_the_end = False
194+ append_nan_to_index = False
198195 for cat_name , class_ in values .iteritems ():
199196 if pd .isna (cat_name ) and self .handle_missing == 'return_nan' :
200197 # we don't want a mapping column if return_nan
201198 # but do add the index to the end
202- add_me_to_the_end = class_
199+ append_nan_to_index = class_
203200 continue
204201 if self .use_cat_names :
205202 n_col_name = str (col ) + '_%s' % (cat_name ,)
@@ -221,8 +218,8 @@ def generate_mapping(self):
221218 new_columns .append (n_col_name )
222219 index .append (- 1 )
223220
224- if add_me_to_the_end :
225- index .append (add_me_to_the_end )
221+ if append_nan_to_index :
222+ index .append (append_nan_to_index )
226223
227224 base_matrix = np .eye (N = len (index ), M = len (new_columns ), dtype = int )
228225 base_df = pd .DataFrame (data = base_matrix , columns = new_columns , index = index )
0 commit comments