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))
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)
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)
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)
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)
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)
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)