def test_selective_imputer_multi_strategy(): imputer = SelectiveImputer(strategy=('mean', (lambda *args: -999.), 'most_frequent')) trans = imputer.fit_transform(X) assert trans is not X values = trans.values assert_array_almost_equal( values, np.array([[1., -999., 3.1], [1.55, 2.3, 3.1], [2.1, 2.1, 3.1]]))
def test_selective_imputer_dict_strategies(): # case where cols not specified, and strategy has fewer cols than present imputer = SelectiveImputer(strategy={'a': 'mean'}) trans = imputer.fit_transform(X) # show it worked... assert trans is not X # it's a copy assert_array_almost_equal( trans.values, np.array([[1., nan, 3.1], [1.55, 2.3, nan], [2.1, 2.1, 3.1]])) # assert on the strategies stored assert 'a' in imputer.strategy_ assert len(imputer.strategy_) == 1