Exemplo n.º 1
0
def test_dataframe_to_array_all_categorical_with_missing_vals():
    s_1 = pd.Series([-1, 0, 2, 1, float('NaN')])
    s_2 = pd.Series(['one', 'two', 'three', 'four', float('NaN')])
    df = pd.concat([s_1, s_2], axis=1)

    dtypes = ['categorical']*2
    metadata = dict()

    valmaps = du.gen_valmaps(df, dtypes, metadata)
    data = du.dataframe_to_array(df, valmaps)

    assert data.shape == df.shape
    assert 'float' in str(data.dtype)

    assert data[0, 0] == 0
    assert data[1, 0] == 1
    assert data[2, 0] == 3
    assert data[3, 0] == 2
    assert np.isnan(data[4, 0])

    assert data[0, 1] == 1
    assert data[1, 1] == 3
    assert data[2, 1] == 2
    assert data[3, 1] == 0
    assert np.isnan(data[4, 1])
Exemplo n.º 2
0
def test_dataframe_to_array_all_continuous():
    n_cols = 5
    df = pd.DataFrame(np.random.rand(30, n_cols))
    valmaps = dict()

    data = du.dataframe_to_array(df, valmaps)

    assert data.shape == df.shape
    assert 'float' in str(data.dtype)