@@ -316,7 +316,27 @@ def test_inverse_with_mapping(self):
316316 return_df = True ,
317317 )
318318 df [categoricals ] = enc .fit_transform (df [categoricals ])
319- print ("ord mapping after fit" )
320- print (enc .mapping )
321319 recovered = enc .inverse_transform (df [categoricals ])
322320 pd .testing .assert_frame_equal (X [categoricals ], recovered )
321+
322+ def test_validate_mapping (self ):
323+ custom_mapping = [
324+ {
325+ "col" : "col1" ,
326+ "mapping" : {np .NaN : 0 , "a" : 1 , "b" : 2 },
327+ }, # The mapping from the documentation
328+ {"col" : "col2" , "mapping" : {np .NaN : - 3 , "x" : 11 , "y" : 2 }},
329+ ]
330+ expected_valid_mapping = [
331+ {
332+ "col" : "col1" ,
333+ "mapping" : pd .Series ({np .NaN : 0 , "a" : 1 , "b" : 2 }),
334+ }, # The mapping from the documentation
335+ {"col" : "col2" , "mapping" : pd .Series ({np .NaN : - 3 , "x" : 11 , "y" : 2 })},
336+ ]
337+ enc = encoders .OrdinalEncoder ()
338+ actual_valid_mapping = enc ._validate_supplied_mapping (custom_mapping )
339+ self .assertEqual (len (actual_valid_mapping ), len (expected_valid_mapping ))
340+ for idx in range (len (actual_valid_mapping )):
341+ self .assertEqual (actual_valid_mapping [idx ]["col" ], expected_valid_mapping [idx ]["col" ])
342+ pd .testing .assert_series_equal (actual_valid_mapping [idx ]["mapping" ], expected_valid_mapping [idx ]["mapping" ])
0 commit comments