Пример #1
0
    def test_assemble_col_metadata(self):
        #simple happy path
        full_df = pd.DataFrame(
            [["id", "rhd1", "rhd2", "cid1", "cid2"],
             ["chd1", "", "", "a", "b"],
             ["chd2", "", "", "50", "60"],
             ["chd3", "", "", "1.0", np.nan],
             ["rid1", "C", "D", "0.3", "0.2"],
             ["rid2", "1.0", "2.0", np.nan, "0.9"]])
        full_df_dims = [2, 2, 2, 3]
        e_col_df = pd.DataFrame([["a", 50, 1.0], ["b", 60, np.nan]],
                                index=["cid1", "cid2"],
                                columns=["chd1", "chd2", "chd3"])
        col_df = pg.assemble_col_metadata(full_df, full_df_dims[3],
                                          full_df_dims[2], full_df_dims[1])
        logger.debug("simple happy path - col_df:  {}".format(col_df))

        self.assertTrue(col_df.equals(e_col_df))

        #test that CID's are strings - using number within str
        full_df.iloc[0,3] = "13"
        full_df.iloc[0,4] = "17"
        col_df = pg.assemble_col_metadata(full_df, full_df_dims[3],
                                          full_df_dims[2], full_df_dims[1])
        logger.debug("test that CID's are strings - col_df:  {}".format(col_df))
        self.assertEqual({"13", "17"}, set(col_df.index))
Пример #2
0
 def test_assemble_col_metadata(self):
     full_df = pd.DataFrame(
         [["id", "rhd1", "rhd2", "cid1", "cid2"],
          ["chd1", "", "", "a", "b"],
          ["chd2", "", "", "50", "60"],
          ["chd3", "", "", "1.0", np.nan],
          ["rid1", "C", "D", "0.3", "0.2"],
          ["rid2", "1.0", "2.0", np.nan, "0.9"]])
     full_df_dims = [2, 2, 2, 3]
     e_col_df = pd.DataFrame([["a", 50, 1.0], ["b", 60, np.nan]],
                             index=["cid1", "cid2"],
                             columns=["chd1", "chd2", "chd3"])
     col_df = pg.assemble_col_metadata(full_df, full_df_dims[3],
                                       full_df_dims[2], full_df_dims[1])
     self.assertTrue(col_df.equals(e_col_df))