REGR: Dataframe.agg no longer accepts positional arguments as of v1.1.0 #36948
Labels
Apply
Apply, Aggregate, Transform, Map
Bug
Regression
Functionality that used to work in a prior pandas version
Milestone
Currently, passing any positional arguments to the
*args
parameter ofDataFrame.agg
fails with aTypeError
, but the documented behavior is that positional and keyword arguments are passed on to the function that you are aggregating with. A minimal reproducer:This is a regression introduced in v1.1.0, which was introduced in 433c900 (GH-34377), and it was mainly because the previous code only incidentally worked. Prior to the "offending" commit, all
TypeErrors
were caught and.agg
would fall back toapply
. This was incidentally (as far as I can tell) catching theTypeError
raised from the fact that theself._aggregate
call passedaxis
as a keyword argument, so:This means that
aggregate
takesfunc
and the first positional argument from*args
asfunc
andaxis
, then takesaxis=1
to beaxis
, raisingTypeError
becauseaxis
is specified twice.I believe the solution here is to pass
axis
toself._aggregate
by position.The text was updated successfully, but these errors were encountered: