def test_densify_dataframe_integers(): index = [("one", 1), ("one", 3), ("two", 2), ("three", 1), ("three", 2)] index = pd.MultiIndex.from_tuples(index, names=["foo", "bar"]) df = pd.DataFrame({'A': np.arange(5, 0, -1), 'B': list("abcde")}, index=index) out_df = bdf.densify_dataframe(df, {"bar": list(range(1, 4))}) assert len(out_df) == 9 assert out_df.loc[("one", 2)].isna().all() assert out_df.loc[("two", 1)].isna().all() assert out_df.loc[("two", 3)].isna().all() assert out_df.loc[("three", 3)].isna().all()
def test_densify_dataframe_intervals(): index = [("one", 1), ("one", 3), ("two", 2), ("three", 1), ("three", 2)] index = [(a, pd.Interval(b, b + 1)) for a, b in index] index = pd.MultiIndex.from_tuples(index, names=["foo", "bar"]) df = pd.DataFrame({'A': np.arange(5, 0, -1), 'B': list("abcde")}, index=index) out_df = bdf.densify_dataframe(df, {"bar": pd.IntervalIndex.from_breaks(range(1, 5))}) print(df) print(out_df) assert len(out_df) == 9 assert out_df.loc[("one", pd.Interval(2, 3))].isna().all() assert out_df.loc[("two", pd.Interval(1, 2))].isna().all() assert out_df.loc[("two", pd.Interval(3, 4))].isna().all() assert out_df.loc[("three", pd.Interval(3, 4))].isna().all()