DEPR: dropping nuisance columns in DataFrameGroupby apply, agg, transform by jbrockmendel · Pull Request #41475 · pandas-dev/pandas (original) (raw)

In groupby._transform, I think we can always use _wrap_transform_fast_result in the case of a string aggregator instead of falling back to _transform_general for certain cases. The only thing stopping this now is it removes the warnings added here. Digging into it, I'm finding some inconsistencies:

df = DataFrame(
    {
        "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
        "B": ["one", "one", "two", "three", "two", "two", "one", "three"],
        "C": np.random.randn(8),
        "D": np.random.randn(8),
    }
)
df.groupby("A").mean()
df.groupby("A").agg("mean")
df.groupby("A").agg(np.mean)
df.groupby("A").transform("mean")  # <--- warns
df.groupby("A").transform(np.mean)  # <--- warns
df.groupby("A").apply("mean")
df.groupby("A").apply(np.mean)  # <--- warns

Should all, just the np.mean, or none of these warn? From the whatsnew note, it seemed to me that all of these should warn.