Exemplo n.º 1
0
def test_read_sql_query(setup_fixture):
    setup, csvdf, _ = setup_fixture

    con = sqlite3.connect(fpd.SQLITE_NAME)
    df = fpd.read_sql_query(f"select * from {csvdf.tablename}", con)
    con.close()
    assert_df_equal(csvdf, df)
    assert_df_equal(setup, df)
Exemplo n.º 2
0
def test_head(setup_fixture):
    setup, df, _ = setup_fixture
    assert_df_equal(setup.head(), df.head())
    assert_df_equal(setup.head(2), df.head(2))
    assert_df_equal(setup.head(1), df.head(1))
    # Series head test
    assert_df_equal(setup['A'].head(), df['A'].head())
    assert_df_equal(setup['D'].head(2), df['D'].head(2))
Exemplo n.º 3
0
def test_getter_virtual(setup_fixture):
    setup, _, test_file_name = setup_fixture
    setup_df = setup.copy() # setting items on a copy
    df = fpd.read_csv(test_file_name)

    setup_df['K'] = 20
    df['K'] = 20
    assert(isinstance(df['K'], fpd.core._VirtualSeries))
    assert_df_equal(setup_df["K"], df['K'])
Exemplo n.º 4
0
def test_concat_csv(setup_fixture):
    setup, _, test_file_name = setup_fixture
    filenames = [test_file_name, test_file_name]
    for f in filenames:
        setup.to_csv(f, index=False)
        setup.to_csv(f, index=False)
    df = fpd.concat_csv(filenames)
    setup_concat = pd.concat([setup, setup])
    assert_df_equal(setup_concat, df)
Exemplo n.º 5
0
def test_mask_virtual(setup_fixture):
    setup, _, test_file_name = setup_fixture
    setup_df = setup.copy() # setting items on a copy
    df = fpd.read_csv(test_file_name)

    setup_df['Virtual'] = (setup_df['B'] + 10) * setup_df['C']
    df['Virtual'] = (df['B'] + 10) * df['C']

    pd_mask = (setup_df['Virtual']>45) & (setup_df['Virtual']<979)
    fpd_mask = (df['Virtual']>45) & (df['Virtual']<979)
    assert_df_equal(setup_df[pd_mask], df[fpd_mask])
Exemplo n.º 6
0
def test_arith_constants(setup_fixture):
    setup, _, test_file_name = setup_fixture
    setup_df = setup.copy()  # setting items on a copy
    df = fpd.read_csv(test_file_name)

    setup_df['const_int'] = 20
    setup_df['P'] = (setup_df['B'] + 1) * setup_df['const_int'] % 5
    df['const_int'] = 20
    df['P'] = (df['B'] + 1) * df['const_int'] % 5

    assert_df_equal(setup_df, df)
Exemplo n.º 7
0
def test_constants(setup_fixture):
    setup, _, test_file_name = setup_fixture
    setup_df = setup.copy()  # setting items on a copy
    df = fpd.read_csv(test_file_name)

    setup_df['const_int'] = 20
    df['const_int'] = 20

    setup_df['const_str'] = "test_string"
    df['const_str'] = "test_string"

    # setup_df['const_bool'] = True
    # df['const_bool'] = True
    # assert(setup_df.equals(df.read_into_mem()))
    assert_df_equal(setup_df, df)
Exemplo n.º 8
0
def test_mask2(setup_fixture):
    setup, df, _ = setup_fixture

    pd_mask = (setup['D']=='man') & (setup['A']==2)
    fpd_mask = (df['D']=='man') & (df['A']==2)
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = (setup['D']=='man') | (setup['A']==2)
    fpd_mask = (df['D']=='man') | (df['A']==2)
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    assert_df_equal(setup[~pd_mask], df[~fpd_mask])
Exemplo n.º 9
0
def test_getter_column_name(setup_fixture):
    setup, df, _ = setup_fixture
    A = df["A"]
    assert(isinstance(A, fpd.core._Series))
    assert_df_equal(setup['A'], A)
Exemplo n.º 10
0
def test_mask(setup_fixture):
    setup, df, _ = setup_fixture

    pd_mask = setup['D'] == 'man'
    fpd_mask = df['D'] == 'man'
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] == 5
    fpd_mask = df['B'] == 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] != 5
    fpd_mask = df['B'] != 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] > 5
    fpd_mask = df['B'] > 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] >= 5
    fpd_mask = df['B'] >= 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] < 5
    fpd_mask = df['B'] < 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])

    pd_mask = setup['B'] <= 5
    fpd_mask = df['B'] <= 5
    assert_df_equal(setup[pd_mask], df[fpd_mask])
Exemplo n.º 11
0
def test_getter_columns(setup_fixture):
    setup, df, _ = setup_fixture
    cols = ['A', 'B']
    assert_df_equal(setup[cols], df[cols])
Exemplo n.º 12
0
def test_loc_getter(setup_fixture):
    setup, df, _ = setup_fixture

    setup_row_mask = (setup['A']==2)
    df_row_mask = (df['A']==2)
    assert_df_equal(setup.loc[setup_row_mask], df.loc[df_row_mask])

    setup_row_mask = (setup['A']>=2) & (setup['D']=='man')
    df_row_mask = (df['A']>=2) & (df['D']=='man')
    assert_df_equal(setup.loc[setup_row_mask], df.loc[df_row_mask])
    assert_df_equal(setup.loc[setup_row_mask, ], df.loc[df_row_mask, ])

    assert_df_equal(setup.loc[3], df.loc[3])
    assert_df_equal(setup.loc[3,], df.loc[3,])

    assert(setup.loc[3, "A"]==df.loc[3, "A"])
    assert_df_equal(setup.loc[3, ["A"]], df.loc[3, ["A"]])
    assert_df_equal(setup.loc[3, ["A", "D"]], df.loc[3, ["A", "D"]])

    assert_df_equal(setup.loc[setup_row_mask, ["A", "D"]], df.loc[df_row_mask, ["A", "D"]])

    assert_df_equal(setup.loc[2:7:2,], df.loc[2:7:2,])
    assert_df_equal(setup.loc[::2, ["A", "D"]], df.loc[::2, ["A", "D"]])
Exemplo n.º 13
0
def test_mask_slice(setup_fixture):
    setup, df, _ = setup_fixture

    assert_df_equal(setup[5:], df[5:])
    assert_df_equal(setup[2:6], df[2:6])
    assert_df_equal(setup[:7:3], df[:7:3])
    assert_df_equal(setup[2:7:2], df[2:7:2])
    assert_df_equal(setup[::5], df[::5])
    assert_df_equal(setup[::], df[::])
    assert_df_equal(setup[::-1], df[::-1])
    assert_df_equal(setup[7:2:-1], df[7:2:-1])
    print(setup[::-2], df[::-2])
Exemplo n.º 14
0
def test_arith_columns(setup_fixture):
    setup, _, test_file_name = setup_fixture
    setup_df = setup.copy()  # setting items on a copy
    df = fpd.read_csv(test_file_name)

    setup_df['Add'] = setup_df['B'] + setup_df['C']
    df['Add'] = df['B'] + df['C']
    assert_df_equal(setup_df["Add"], df['Add'])

    setup_df['Sub'] = setup_df['Add'] - setup_df['C']
    df['Sub'] = df['Add'] - df['C']
    assert_df_equal(setup_df["Sub"], df['Sub'])

    setup_df['Div'] = setup_df['Sub'] / setup_df['C']
    df['Div'] = df['Sub'] / df['C']
    assert_df_equal(setup_df["Div"], df['Div'])

    setup_df['Mult'] = setup_df['Div'] * setup_df['C']
    df['Mult'] = df['Div'] * df['C']
    assert_df_equal(setup_df["Mult"], df['Mult'])

    setup_df['Mod'] = setup_df['Mult'] % setup_df['C']
    df['Mod'] = df['Mult'] % df['C']
    assert_df_equal(setup_df["Mod"], df['Mod'])

    setup_df['A'] = setup_df['A'] + setup_df['A']
    df['A'] = df['A'] + df['A']
    assert_df_equal(setup_df["A"], df['A'])

    setup_df['Y'] = setup_df['B']
    df['Y'] = df['B']
    assert_df_equal(setup_df["Y"], df['Y'])

    setup_df['Z'] = setup_df['Div']
    df['Z'] = df['Div']
    assert_df_equal(setup_df["Z"], df['Z'])

    assert_df_equal(setup_df, df)
Exemplo n.º 15
0
def test_read_csv(setup_fixture):
    setup, _, test_file_name = setup_fixture
    df = fpd.read_csv(test_file_name)
    assert_df_equal(setup, df)