def test_assemble_row_metadata(self): #simple happy path full_df = pd.DataFrame( [["id", "rhd1", "id", "cid1", "cid2"], ["chd1", "", "", "a", "b"], ["chd2", "", "", "55", "61"], ["chd3", "", "", "nah", "nope"], ["rid1", "C", "1.0", "0.3", "0.2"], ["rid2", "D", "2.0", np.nan, "0.9"]]) full_df_dims = [2, 2, 2, 3] row_index = pd.Index(["rid1", "rid2"], name="rid") col_index = pd.Index(["rhd1", "id"], name="rhd") e_row_df = pd.DataFrame([["C", 1.0], ["D", 2.0]], index = row_index, columns = col_index) row_df = pg.assemble_row_metadata(full_df, full_df_dims[3], full_df_dims[0], full_df_dims[2]) logger.debug("simple happy path - row_df: {}".format(row_df)) self.assertTrue(row_df.equals(e_row_df), ( "\nrow_df:\n{}\ne_row_df:\n{}").format(row_df, e_row_df)) #test that RID's are strings - using number within str full_df.iloc[4,0] = "13" full_df.iloc[5,0] = "17" row_df = pg.assemble_row_metadata(full_df, full_df_dims[3], full_df_dims[0], full_df_dims[2]) logger.debug("test that RID's are strings - row_df: {}".format(row_df)) self.assertEqual({"13", "17"}, set(row_df.index))
def test_assemble_row_metadata(self): full_df = pd.DataFrame( [["id", "rhd1", "id", "cid1", "cid2"], ["chd1", "", "", "a", "b"], ["chd2", "", "", "55", "61"], ["chd3", "", "", "nah", "nope"], ["rid1", "C", "1.0", "0.3", "0.2"], ["rid2", "D", "2.0", np.nan, "0.9"]]) full_df_dims = [2, 2, 2, 3] row_index = pd.Index(["rid1", "rid2"], name="rid") col_index = pd.Index(["rhd1", "id"], name="rhd") e_row_df = pd.DataFrame([["C", 1.0], ["D", 2.0]], index = row_index, columns = col_index) row_df = pg.assemble_row_metadata(full_df, full_df_dims[3], full_df_dims[0], full_df_dims[2]) self.assertTrue(row_df.equals(e_row_df), ( "\nrow_df:\n{}\ne_row_df:\n{}").format(row_df, e_row_df))