Example #1
0
def check_df(name, undefined_msg=MSG_UNDEFINED, not_instance_msg=MSG_NOT_INSTANCE, state=None):

    # test defined
    child = check_object(name, undefined_msg, state=state, typestr="pandas DataFrame")
    is_instance(pd.DataFrame, not_instance_msg, state=child)  # test instance

    return child
Example #2
0
def test_dictionary(name,
                    keys=None,
                    undefined_msg=None,
                    not_dictionary_msg=None,
                    key_missing_msg=None,
                    incorrect_value_msg=None,
                    state=None):
    """Test the contents of a dictionary.
    """

    rep = Reporter.active_reporter
    rep.set_tag("fun", "test_dictionary")

    child = check_object(name,
                         undefined_msg or MSG_UNDEFINED,
                         expand_msg="",
                         state=state,
                         typestr="dictionary")
    is_instance(dict, not_dictionary_msg or MSG_NOT_INSTANCE,
                state=child)  # test instance

    # set keys or check if manual keys are valid
    if not keys:
        keys = getKeysInProcess(name, state.solution_process)

    for key in keys:
        # check if key in dictionary
        has_equal_key(key,
                      incorrect_value_msg or MSG_INCORRECT_VAL,
                      key_missing_msg or MSG_KEY_MISSING,
                      state=child)
Example #3
0
def test_data_frame(name,
                    columns=None,
                    undefined_msg=None,
                    not_data_frame_msg=None,
                    undefined_cols_msg=None,
                    incorrect_msg=None,
                    state=None):
    """Test a pandas dataframe.
    """

    rep = Reporter.active_reporter
    rep.set_tag("fun", "test_data_frame")

    child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg="", state=state, typestr="pandas DataFrame")
    is_instance(pd.DataFrame, not_data_frame_msg or MSG_NOT_INSTANCE, state=child)  # test instance

    sol_cols = getColumnsInProcess(name, child.solution_process)
    if sol_cols is None:
        raise ValueError("Something went wrong in figuring out the columns for %s in the solution process" % name)

    # set columns or check if manual columns are valid
    if columns is None: columns = sol_cols

    for col in columns:
        # check if column available
        has_equal_key(col, incorrect_msg or MSG_INCORRECT_VAL, undefined_cols_msg or MSG_KEY_MISSING, state=child)
Example #4
0
def check_dict(name, undefined_msg=MSG_UNDEFINED, not_instance_msg=MSG_NOT_INSTANCE, expand_msg="", state=None):

    # test defined
    child = check_object(name, undefined_msg, state=state, typestr="dictionary")
    is_instance(dict, not_instance_msg, state=child)   # test instance

    return child
Example #5
0
def check_df(name,
             undefined_msg=MSG_UNDEFINED,
             not_instance_msg=MSG_NOT_INSTANCE,
             state=None):

    # test defined
    child = check_object(name,
                         undefined_msg,
                         state=state,
                         typestr="pandas DataFrame")
    is_instance(pd.DataFrame, not_instance_msg, state=child)  # test instance

    return child
Example #6
0
def check_dict(name,
               undefined_msg=MSG_UNDEFINED,
               not_instance_msg=MSG_NOT_INSTANCE,
               expand_msg="",
               state=None):

    # test defined
    child = check_object(name,
                         undefined_msg,
                         state=state,
                         typestr="dictionary")
    is_instance(dict, not_instance_msg, state=child)  # test instance

    return child
Example #7
0
def test_dictionary(name,
                    keys=None,
                    undefined_msg=None,
                    not_dictionary_msg=None,
                    key_missing_msg=None,
                    incorrect_value_msg=None,
                    state=None):
    """Test the contents of a dictionary.
    """

    rep = Reporter.active_reporter
    rep.set_tag("fun", "test_dictionary")

    child = check_object(name, undefined_msg or MSG_UNDEFINED, expand_msg = "", state=state, typestr="dictionary")
    is_instance(dict, not_dictionary_msg or MSG_NOT_INSTANCE, state=child)   # test instance

    # set keys or check if manual keys are valid
    if not keys: 
        keys = getKeysInProcess(name, state.solution_process)

    for key in keys:
        # check if key in dictionary
        has_equal_key(key, incorrect_value_msg or MSG_INCORRECT_VAL, key_missing_msg or MSG_KEY_MISSING, state=child)
Example #8
0
def test_data_frame(name,
                    columns=None,
                    undefined_msg=None,
                    not_data_frame_msg=None,
                    undefined_cols_msg=None,
                    incorrect_msg=None,
                    state=None):
    """Test a pandas dataframe.
    """

    rep = Reporter.active_reporter
    rep.set_tag("fun", "test_data_frame")

    child = check_object(name,
                         undefined_msg or MSG_UNDEFINED,
                         expand_msg="",
                         state=state,
                         typestr="pandas DataFrame")
    is_instance(pd.DataFrame,
                not_data_frame_msg or MSG_NOT_INSTANCE,
                state=child)  # test instance

    sol_cols = getColumnsInProcess(name, child.solution_process)
    if sol_cols is None:
        raise ValueError(
            "Something went wrong in figuring out the columns for %s in the solution process"
            % name)

    # set columns or check if manual columns are valid
    if columns is None: columns = sol_cols

    for col in columns:
        # check if column available
        has_equal_key(col,
                      incorrect_msg or MSG_INCORRECT_VAL,
                      undefined_cols_msg or MSG_KEY_MISSING,
                      state=child)