Exemplo n.º 1
0
def test_my_spread_na():
    '''When key column contains NaN, do not add NaN as a column name'''

    d0_test = miniTidyPy.my_spread(sample_df_na, key = 'time', value = 'value')
    assert d0_test.equals(output_na), "key column contains NaN"

    # when the whole dataframe contains NaN
    assert miniTidyPy.my_spread(all_na, key = 'a', value = 'b').equals(pd.DataFrame({}))
Exemplo n.º 2
0
def test_my_spread_wrong_key():
    '''When the input key is not included, should return the original dataframe'''

    # input is a list
    d2_test = miniTidyPy.my_spread(sample_df, key = [], value = 'value')
    assert d2_test.equals(sample_df), "key is a list"

    # input is an integer
    d3_test = miniTidyPy.my_spread(sample_df, key = 2, value = 'value')
    assert d3_test.equals(sample_df), "key is an integer"
Exemplo n.º 3
0
def test_my_spread_wrong_df():
    '''When the input df is not a dataframe, should return None'''

    d4_test = miniTidyPy.my_spread(2, key = 'foo', value = 'foo')
    assert d4_test is None, "input dataframe type incorrect"
Exemplo n.º 4
0
def test_my_spread_normal():
    '''Test on a normal dataframe'''

    # spread the selected column
    d1_test = miniTidyPy.my_spread(sample_df, key = 'time', value = 'value')
    assert d1_test.equals(output1), "normal dataframe"