From 2788bd756d5fdb27472446f577ceb6b914b8b7d2 Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Thu, 26 Nov 2020 16:22:56 +0100 Subject: [PATCH] Update reference in test. Add pandas test. --- timely_beliefs/tests/test_belief_io.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/timely_beliefs/tests/test_belief_io.py b/timely_beliefs/tests/test_belief_io.py index b0592896..3beac050 100644 --- a/timely_beliefs/tests/test_belief_io.py +++ b/timely_beliefs/tests/test_belief_io.py @@ -395,11 +395,11 @@ def test_agg_resampling_retains_metadata(resolution): def test_groupby_retains_metadata(): - """ Test whether grouping by index level retains the metadata. + """Test whether grouping by index level retains the metadata. Succeeds with pandas==1.0.0 Fails with pandas==1.1.0 - Should be fixed with https://github.com/pandas-dev/pandas/pull/35688 + Should be fixed with https://github.com/pandas-dev/pandas/pull/37461 """ df = example_df metadata = {md: getattr(example_df, md) for md in METADATA} @@ -415,3 +415,13 @@ def assert_function(x): assert isinstance(df, tb.BeliefsDataFrame) for md in metadata: assert getattr(df, md) == metadata[md] + + +def test_groupby_retains_attribute(): + df = pd.DataFrame([[1, 2], [3, 4]], columns=["x", "y"]) + df.a = "b" + assert df.a == "b" + df = df.groupby("x").apply(lambda x: x) + assert df.a == "b" + df = df.groupby("x").sum() + assert df.a == "b"