def test_bagged_regressor_imputer(): imputer = BaggedRegressorImputer(random_state=42) trans = imputer.fit_transform(X) assert trans is not X assert pd.isnull(trans).values.sum() == 0 assert_array_almost_equal( trans.values, np.array([[1., 2.16, 3.1], [1.77, 2.3, 3.1], [2.1, 2.1, 3.1]]))
def test_bagged_regressor_single_predictor_valid(): # works because even though only 1 predictor, it's not in cols imputer = BaggedRegressorImputer(predictors=['a'], cols=['b', 'c'], random_state=42) trans = imputer.fit_transform(X) assert trans is not X # still a nan in there because we didn't impute A assert_array_almost_equal( trans.values, np.array([[1., 2.16, 3.1], [nan, 2.3, 3.1], [2.1, 2.1, 3.1]]))
def test_bagged_regressor_single_predictor_corner(): # fails because only one predictor, and it's in cols imputer = BaggedRegressorImputer(predictors=['a']) assert_raises(ValueError, imputer.fit, X)