Esempio n. 1
0
def stateapply_raises(
    hyperparams: typing.Mapping[str, int],
    train_input: str,
    label_input: str,
    apply_input,
    exception: spec.Scenario.Exception,
) -> spec.Scenario:
    """Scenario fixture."""
    return (testing.Case(**hyperparams).train(
        train_input,
        label_input).apply(apply_input).raises(exception.kind,
                                               exception.message))
Esempio n. 2
0
class TestTitleParser(testing.operator(preprocessing.parse_title)):
    """Unit testing the stateless TitleParser transformer."""

    # Dataset fixtures
    INPUT = pandas.DataFrame({
        'Name':
        ['Smith, Mr. John', 'Black, Ms. Jane', 'Brown, Mrs. Jo', 'White, Ian']
    })
    EXPECTED = pandas.concat(
        (INPUT, pandas.DataFrame({'Title': ['Mr', 'Ms', 'Mrs', 'Unknown']})),
        axis='columns')

    # Test scenarios
    invalid_params = testing.Case(foo='bar').raises(
        TypeError, "got an unexpected keyword argument 'foo'")
    invalid_source = testing.Case(source='Foo',
                                  target='Bar').apply(INPUT).raises(
                                      KeyError, 'Foo')
    valid_parsing = testing.Case(source='Name',
                                 target='Title').apply(INPUT).returns(
                                     EXPECTED, dataframe_equals)
Esempio n. 3
0
class TestNaNImputer(testing.operator(preprocessing.NaNImputer)):
    """NaNImputer unit tests."""

    # Dataset fixtures
    TRAINSET = pandas.DataFrame({
        'foo': [1.0, 2.0, 3.0],
        'bar': ['a', 'b', 'b']
    })
    TESTSET = pandas.DataFrame({
        'foo': [1.0, 4.0, None],
        'bar': [None, 'c', 'a']
    })
    EXPECTED = pandas.DataFrame({
        'foo': [1.0, 4.0, 2.0],
        'bar': ['b', 'c', 'a']
    })

    # Test scenarios
    invalid_params = testing.Case('foo').raises(
        TypeError, 'takes 1 positional argument but 2 were given')
    not_trained = testing.Case().apply(TESTSET).raises(
        ValueError, "Must specify a fill 'value' or 'method'")
    valid_imputation = testing.Case().train(TRAINSET).apply(TESTSET).returns(
        EXPECTED, dataframe_equals)
Esempio n. 4
0
def plainapply_raises(hyperparams: typing.Mapping[str, int], apply_input: str,
                      exception: spec.Scenario.Exception) -> spec.Scenario:
    """Scenario fixture."""
    return testing.Case(**hyperparams).apply(apply_input).raises(
        exception.kind, exception.message)
Esempio n. 5
0
def init_raises(hyperparams: typing.Mapping[str, int],
                exception: spec.Scenario.Exception) -> spec.Scenario:
    """Scenario fixture."""
    return testing.Case(**hyperparams).raises(exception.kind,
                                              exception.message)
Esempio n. 6
0
def stateapply_returns(hyperparams: typing.Mapping[str, int], train_input: str,
                       label_input: str, apply_input: str,
                       apply_output: str) -> spec.Scenario:
    """Scenario fixture."""
    return testing.Case(**hyperparams).train(
        train_input, label_input).apply(apply_input).returns(apply_output)
Esempio n. 7
0
def plainapply_returns(hyperparams: typing.Mapping[str, int], apply_input: str,
                       apply_output: str) -> spec.Scenario:
    """Scenario fixture."""
    return testing.Case(**hyperparams).apply(apply_input).returns(apply_output)