A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/46479 below:

groupby.apply doesn't allow passing args/kwargs with a str func · Issue #46479 · pandas-dev/pandas · GitHub

import numpy as np
import pandas as pd

df = pd.DataFrame({"A": np.random.randint(0, 3, 10), "B": 1, "C": 'x'})
gb = df.groupby("A")
result = gb.agg("sum", numeric_only=True)
expected = gb.sum(numeric_only=True)
pd.testing.assert_frame_equal(result, expected)

This raises on the result = ... line. However, it works with agg and transform. E.g.

df = pd.DataFrame({"A": np.random.randint(0, 3, 10), "B": 1, "C": 'x'})
gb = df.groupby("A")
print(gb.agg("sum", numeric_only=False))
print(gb.transform("sum", numeric_only=False))

produces

   B     C
A         
0  3   xxx
1  4  xxxx
2  3   xxx
   B     C
0  3   xxx
1  4  xxxx
2  3   xxx
3  3   xxx
4  4  xxxx
5  4  xxxx
6  4  xxxx
7  3   xxx
8  3   xxx
9  3   xxx

I ran into this while working on #46072. There are tests which use apply that would raise a warning about the changing default; at the current state a user would not be able to silence the warning.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4