def test_explainable_simple_imputer_unfitted():
    label_col = 'label'

    imputer = SimpleImputer(['features'], label_col, is_explainable=True)

    assert imputer.is_explainable

    try:
        imputer.explain('some class')
        raise pytest.fail(
            'imputer.explain should fail with an appropriate error message')
    except ValueError as exception:
        assert exception.args[0] == 'Need to call .fit() before'

    instance = pd.Series({'features': 'some feature text'})
    try:
        imputer.explain_instance(instance)
        raise pytest.fail(
            'imputer.explain_instance should fail with an appropriate error message'
        )
    except ValueError as exception:
        assert exception.args[0] == 'Need to call .fit() before'
def test_explainable_simple_imputer(test_dir, data_frame):
    label_col = 'label'
    df = data_frame(n_samples=100, label_col=label_col)

    output_path = os.path.join(test_dir, "tmp")
    imputer = SimpleImputer(['features'],
                            label_col,
                            output_path=output_path,
                            is_explainable=True).fit(df)

    assert imputer.is_explainable

    assert isinstance(imputer.imputer.data_encoders[0],
                      column_encoders.TfIdfEncoder)

    # explain should not raise an exception
    _ = imputer.explain(df[label_col].unique()[0])

    # explain_instance should not raise an exception
    instance = pd.Series({'features': 'some feature text'})
    _ = imputer.explain_instance(instance)

    assert True