Skip to content

Commit 59c4a42

Browse files
omar-elbazmroeschke
authored andcommitted
Unit test for groupby.rolling.corr (pandas-dev#54499)
1 parent d51bff1 commit 59c4a42

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

pandas/tests/groupby/test_groupby.py

+26
Original file line numberDiff line numberDiff line change
@@ -3159,3 +3159,29 @@ def test_groupby_series_with_datetimeindex_month_name():
31593159
expected = Series([2, 1], name="jan")
31603160
expected.index.name = "jan"
31613161
tm.assert_series_equal(result, expected)
3162+
3163+
3164+
def test_rolling_corr_grouping_column_contains_tuples_1(df):
3165+
# GH 44078
3166+
df = DataFrame({"a": [(1,), (1,), (1,)], "b": [4, 5, 6]})
3167+
gb = df.groupby(["a"])
3168+
result = gb.rolling(2).corr(other=df)
3169+
index = MultiIndex.from_tuples([((1,), 0), ((1,), 1), ((1,), 2)], names=["a", None])
3170+
expected = DataFrame(
3171+
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
3172+
)
3173+
tm.assert_frame_equal(result, expected)
3174+
3175+
3176+
def test_rolling_corr_case_grrouping_column_contains_tuples_2(df):
3177+
# GH 44078
3178+
df = DataFrame({"a": [(1, 2), (1, 2), (1, 2)], "b": [4, 5, 6]})
3179+
gb = df.groupby(["a"])
3180+
result = gb.rolling(2).corr(other=df)
3181+
index = MultiIndex.from_tuples(
3182+
[((1, 2), 0), ((1, 2), 1), ((1, 2), 2)], names=["a", None]
3183+
)
3184+
expected = DataFrame(
3185+
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
3186+
)
3187+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)