Skip to content

Backport PR #54504 on branch 2.1.x (Move Unit Tests for groupby.rolling.corr) #54513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3159,29 +3159,3 @@ def test_groupby_series_with_datetimeindex_month_name():
expected = Series([2, 1], name="jan")
expected.index.name = "jan"
tm.assert_series_equal(result, expected)


def test_rolling_corr_grouping_column_contains_tuples_1(df):
# GH 44078
df = DataFrame({"a": [(1,), (1,), (1,)], "b": [4, 5, 6]})
gb = df.groupby(["a"])
result = gb.rolling(2).corr(other=df)
index = MultiIndex.from_tuples([((1,), 0), ((1,), 1), ((1,), 2)], names=["a", None])
expected = DataFrame(
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
)
tm.assert_frame_equal(result, expected)


def test_rolling_corr_case_grrouping_column_contains_tuples_2(df):
# GH 44078
df = DataFrame({"a": [(1, 2), (1, 2), (1, 2)], "b": [4, 5, 6]})
gb = df.groupby(["a"])
result = gb.rolling(2).corr(other=df)
index = MultiIndex.from_tuples(
[((1, 2), 0), ((1, 2), 1), ((1, 2), 2)], names=["a", None]
)
expected = DataFrame(
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
)
tm.assert_frame_equal(result, expected)
44 changes: 44 additions & 0 deletions pandas/tests/window/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,3 +1230,47 @@ def test_dont_mutate_obj_after_slicing(self):
# This is the key test
result = grp.count()
tm.assert_frame_equal(result, expected_df)


def test_rolling_corr_with_single_integer_in_index():
# GH 44078
df = DataFrame({"a": [(1,), (1,), (1,)], "b": [4, 5, 6]})
gb = df.groupby(["a"])
result = gb.rolling(2).corr(other=df)
index = MultiIndex.from_tuples([((1,), 0), ((1,), 1), ((1,), 2)], names=["a", None])
expected = DataFrame(
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
)
tm.assert_frame_equal(result, expected)


def test_rolling_corr_with_tuples_in_index():
# GH 44078
df = DataFrame(
{
"a": [
(
1,
2,
),
(
1,
2,
),
(
1,
2,
),
],
"b": [4, 5, 6],
}
)
gb = df.groupby(["a"])
result = gb.rolling(2).corr(other=df)
index = MultiIndex.from_tuples(
[((1, 2), 0), ((1, 2), 1), ((1, 2), 2)], names=["a", None]
)
expected = DataFrame(
{"a": [np.nan, np.nan, np.nan], "b": [np.nan, 1.0, 1.0]}, index=index
)
tm.assert_frame_equal(result, expected)