def test_csv(): df = fpd.concat_csv(["csv1.csv", "csv1.csv"]) print(df) filtered = df[df['A']==2] filtered['const_int'] = 20 filtered['const_bool'] = True filtered['const_str'] = "PPPooo" filtered['P'] = (filtered['B'] + 1) * filtered['const_int'] print(filtered) print(filtered.get_sql()) print() P = filtered['P'] print(P[0]) print(type(P)) print() cols = set(['A', 'B', 'A']) print(df[cols].head()) filtered = df.loc[(df['A']==2), ["A", "D"]] print(filtered) print(filtered.get_sql()) print() print(df.loc[3, ["A", "D"]]) pddf = pd.read_csv("csv1.csv") df = fpd.read_csv("csv1.csv") print(pddf[7:2:-1]) sliced = df[7:2:-1] print(sliced) print(sliced.get_sql())
def setup_fixture(): df = pd.read_csv(StringIO(csv_file)) test_file_name = "test_demo.csv" df.to_csv(test_file_name, index=False) fdf = fpd.read_csv(test_file_name) yield df, fdf, test_file_name if os.path.isfile(test_file_name): os.remove(test_file_name)
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'])
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])
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)
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)
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)
def test_read_csv(setup_fixture): setup, _, test_file_name = setup_fixture df = fpd.read_csv(test_file_name) assert_df_equal(setup, df)