Crawford Collins

    Crawford Collins

    2 years ago
    how does everyone test the results of a task?
    with Flow("test_target_transformer") as f:
            te = fit_target_transformer(problem, target, train_data)
            df = target_encoder_transform(te, imputed_categorical_df)
     assert df.isna().sum() == 0
    I'm trying to test a @task that returns a dataframe, but assert statement errors on
    AttributeError: 'FunctionTask' object has no attribute 'isna'
    . How do I return this as a DataFrame and not a task?


    2 years ago
    To test the result of a task I believe you need run the flow and then can test based off of that state. e.g.:
    with Flow("task-results") as flow:
        v = get_value()
    state =
    assert state.result[v].result == ...

    Joe Schmid

    2 years ago
    @Crawford Collins Just to add to what @josh said: think of the
    with Flow()...
    code as defining the structure of the Flow. Without having ever run the Flow yet, there aren't any results available from your tasks, i.e.
    assert df...
    doesn't give what you might expect since
    is only a placeholder in the definition of the flow. Once you run your Flow, then you can examine the results of a Flow run. (This difference between a Flow and a Flow run can be a little confusing at first but once you understand it, it'll make sense.)
    Crawford Collins

    Crawford Collins

    2 years ago
    thanks. @josh @Joe Schmid this all makes sense.
    Jim Crist-Harif

    Jim Crist-Harif

    2 years ago
    If you're just trying to test individual task functions (in the absence of a flow), you could also call the task manually with the
    def my_function(a, b):
    res =, b)
    assert res.isna().sum() == 0