Skip to content

Commit 0fb9149

Browse files
Backport PR #54504 on branch 2.1.x (Move Unit Tests for groupby.rolling.corr) (#54513)
Backport PR #54504: Move Unit Tests for groupby.rolling.corr Co-authored-by: omar-elbaz <[email protected]>
1 parent 7f25175 commit 0fb9149

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

pandas/tests/groupby/test_groupby.py

-26
Original file line numberDiff line numberDiff line change
@@ -3159,29 +3159,3 @@ 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)

pandas/tests/window/test_groupby.py

+44
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,47 @@ def test_dont_mutate_obj_after_slicing(self):
12301230
# This is the key test
12311231
result = grp.count()
12321232
tm.assert_frame_equal(result, expected_df)
1233+
1234+
1235+
def test_rolling_corr_with_single_integer_in_index():
1236+
# GH 44078
1237+
df = DataFrame({"a": [(1,), (1,), (1,)], "b": [4, 5, 6]})
1238+
gb = df.groupby(["a"])
1239+
result = gb.rolling(2).corr(other=df)
1240+
index = MultiIndex.from_tuples([((1,), 0), ((1,), 1), ((1,), 2)], names=["a", None])
1241+
expected = DataFrame(
1242+
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
1243+
)
1244+
tm.assert_frame_equal(result, expected)
1245+
1246+
1247+
def test_rolling_corr_with_tuples_in_index():
1248+
# GH 44078
1249+
df = DataFrame(
1250+
{
1251+
"a": [
1252+
(
1253+
1,
1254+
2,
1255+
),
1256+
(
1257+
1,
1258+
2,
1259+
),
1260+
(
1261+
1,
1262+
2,
1263+
),
1264+
],
1265+
"b": [4, 5, 6],
1266+
}
1267+
)
1268+
gb = df.groupby(["a"])
1269+
result = gb.rolling(2).corr(other=df)
1270+
index = MultiIndex.from_tuples(
1271+
[((1, 2), 0), ((1, 2), 1), ((1, 2), 2)], names=["a", None]
1272+
)
1273+
expected = DataFrame(
1274+
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
1275+
)
1276+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)