Skip to content

Commit 815938b

Browse files
code sample for pandas-dev#45648
1 parent 33cb4a9 commit 815938b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bisect/45648.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# BUG: groupby transform doesn't respect Series index anymore #45648
2+
3+
import pandas as pd
4+
5+
print(pd.__version__)
6+
7+
df = pd.DataFrame(
8+
{
9+
"A": ["foo", "bar", "foo", "bar", "bar", "foo", "foo"],
10+
"C": [2.1, 1.9, 3.6, 4.0, 1.9, 7.8, 2.8],
11+
}
12+
)
13+
grp = df.groupby("A")["C"]
14+
15+
# sort C within groups defined by A
16+
result = grp.transform(pd.Series.sort_values)
17+
print(result)
18+
19+
expected = grp.transform(lambda x: x.sort_values().values)
20+
pd.testing.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)