Skip to content

TST: Add test groupby transform no column #56935

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

Closed
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
10 changes: 10 additions & 0 deletions pandas/tests/groupby/transform/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,16 @@ def test_groupby_transform_with_nan_group():
expected = Series([1.0, 1.0, 2.0, 3.0, np.nan, 6.0, 6.0, 9.0, 9.0, 9.0], name="a")
tm.assert_series_equal(result, expected)

def test_groupby_transform_with_no_column():
# GH 49864
df = pd.DataFrame({0: [1.0]})
gb = df.groupby(pd.Series(["a"]), as_index=False)
msg = "A grouping was used that is not in the columns of the DataFrame"
with tm.assert_produces_warning(FutureWarning, match=msg):
result = gb.sum()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the linked issue, you want to be using .transform("sum") here.

tm.assert_frame_equal(result, df)



def test_transform_mixed_type():
index = MultiIndex.from_arrays([[0, 0, 0, 1, 1, 1], [1, 2, 3, 1, 2, 3]])
Expand Down