def test_parse_metadata_df(self): mini_gctoo = mini_gctoo_for_testing.make() # convert row_metadata to np.nan mini_row_meta = mini_gctoo.row_metadata_df.replace([-666, "-666", -666.0], [np.nan, np.nan, np.nan]) logger.debug("mini_row_meta.shape: {}".format(mini_row_meta.shape)) logger.debug("mini_row_meta.index: {}".format(mini_row_meta.index)) logger.debug("mini_row_meta.columns: {}".format(mini_row_meta.columns)) logger.debug("mini_row_meta.dtypes: {}".format(mini_row_meta.dtypes)) gctx_file = h5py.File("functional_tests/mini_gctoo_for_testing.gctx", "r") row_dset = gctx_file[row_meta_group_node] col_dset = gctx_file[col_meta_group_node] # with convert_neg_666 row_df = parse_gctx.parse_metadata_df("row", row_dset, True) logger.debug("row_df.dtypes: {}".format(row_df.dtypes)) pandas_testing.assert_frame_equal(mini_row_meta, row_df) # no convert_neg_666 mini_gctoo_with_neg_666 = mini_gctoo_for_testing.make(convert_neg_666=False) col_df = parse_gctx.parse_metadata_df("col", col_dset, False) pandas_testing.assert_frame_equal(mini_gctoo_with_neg_666.col_metadata_df, col_df) # test that ID's are not converted to numeric expected_rids = [str(i) for i in range(3)] row_dset = {"id": MockHdf5Dset(expected_rids, str), "other_meta": MockHdf5Dset(range(3, 6), str)} r = parse_gctx.parse_metadata_df("row", row_dset, True) logger.debug("test that ID's are not converted to numeric - r: {}".format(r)) logger.debug("r.index: {}".format(r.index)) self.assertEqual(set(expected_rids), set(r.index))
def test_parse_metadata_df(self): mini_gctoo = mini_gctoo_for_testing.make() # convert row_metadata to np.nan mini_row_meta = mini_gctoo.row_metadata_df.replace([-666, "-666", -666.0], [np.nan, np.nan, np.nan]) gctx_file = h5py.File("functional_tests/mini_gctoo_for_testing.gctx", "r") row_dset = gctx_file[row_meta_group_node] col_dset = gctx_file[col_meta_group_node] # with convert_neg_666 row_df = parse_gctx.parse_metadata_df("row", row_dset, True) assert_frame_equal(mini_row_meta, row_df) # no convert_neg_666 mini_gctoo_with_neg_666 = mini_gctoo_for_testing.make(convert_neg_666=False) col_df = parse_gctx.parse_metadata_df("col", col_dset, False) assert_frame_equal(mini_gctoo_with_neg_666.col_metadata_df, col_df)