Ejemplo n.º 1
0
def test_pipeline_error(time):
    """Test exceptions at pipeline level"""

    # test fit
    df = _test_df()
    func = lambda df: df['num1'] == df['num3']
    pipeline = PdPipeline([ColByFrameFunc("Equality", func), ColDrop("B")])
    with pytest.raises(PipelineApplicationError):
        pipeline.fit(df, verbose=True, time=time)

    # test transform
    df = _test_df()
    with pytest.raises(PipelineApplicationError):
        pipeline.transform(df, verbose=True, time=time)

    # test fit_transform
    df = _test_df()
    with pytest.raises(PipelineApplicationError):
        pipeline.fit_transform(df, verbose=True, time=time)
Ejemplo n.º 2
0
def test_two_stage_pipeline_stage(time):
    """Testing something."""
    drop_num1 = SilentDropStage('num1')
    drop_num2 = SilentDropStage('num2')
    pipeline = PdPipeline([drop_num1, drop_num2])
    assert len(pipeline) == 2
    df = _test_df()
    res_df = pipeline.apply(df, verbose=True)
    assert 'num1' not in res_df.columns
    assert 'num2' not in res_df.columns
    assert 'char' in res_df.columns
    str(pipeline)
    pipeline.memory_report()

    # test fit
    df = _test_df()
    res_df = pipeline.fit(df, verbose=True, time=time)
    for x in ['num1', 'num2', 'char']:
        assert x in res_df.columns

    # test transform
    df = _test_df()
    res_df = pipeline.transform(df, verbose=True, time=time)
    assert 'num1' not in res_df.columns
    assert 'num2' not in res_df.columns
    assert 'char' in res_df.columns

    # test fit_transform
    df = _test_df()
    res_df = pipeline.fit_transform(df, verbose=True, time=time)

    # test get_transformer
    trs = lambda pipline: pipeline[:1]  # noqa: E731
    pipeline = PdPipeline([drop_num1, drop_num2], transformer_getter=trs)
    transformer = pipeline.get_transformer()
    res_df = transformer(df, verbose=True)
    assert 'num1' not in res_df.columns
    assert 'num2' in res_df.columns
    assert 'char' in res_df.columns