BUG: passing kwargs to Series.aggregate raises TypeError: f() got an unexpected keyword argument · Issue #43357 · pandas-dev/pandas (original) (raw)


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

#!/usr/bin/env python

import pandas as pd

def func(a, b, c=2): pass

if name == "main": s = pd.Series([1, 2, 3, 4])

s.aggregate(func, 0, 99, c=101)

Problem description

Prior to Pandas 1.3.0, it was possible to pass kwargs when using Series.aggregate, however it appears that Pandas now attempts to apply the arguments and keyword arguments twice (first currying them then using them to call the curried function).

Expected Output

Expect output is the program running normally and not throwing an exception.

Actual Output

Traceback (most recent call last): File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/apply.py", line 1068, in agg result = self.obj.apply(f, *args, **kwargs) File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/series.py", line 4357, in apply return SeriesApply(self, func, convert_dtype, args, kwargs).apply() File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/apply.py", line 1043, in apply return self.apply_standard() File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/apply.py", line 1099, in apply_standard mapped = lib.map_infer( File "pandas/_libs/lib.pyx", line 2859, in pandas._libs.lib.map_infer File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/apply.py", line 131, in f return func(x, *args, **kwargs) TypeError: f() got an unexpected keyword argument 'c'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/jake/./pd_test.py", line 11, in s.aggregate(func, 0, 99, c=101) File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/series.py", line 4227, in aggregate result = op.agg() File "/home/jake/pandas-env/lib/python3.9/site-packages/pandas/core/apply.py", line 1070, in agg result = f(self.obj, *args, **kwargs) TypeError: f() got an unexpected keyword argument 'c'

Output of pd.show_versions()


INSTALLED VERSIONS
------------------
commit           : 5f648bf1706dd75a9ca0d29f26eadfbb595fe52b
python           : 3.9.6.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.13.5-arch1-1
Version          : #1 SMP PREEMPT Sun, 25 Jul 2021 18:02:58 +0000
machine          : x86_64
processor        : 
byteorder        : little
LC_ALL           : None
LANG             : en_AU.UTF-8
LOCALE           : en_AU.UTF-8

pandas           : 1.3.2
numpy            : 1.21.2
pytz             : 2021.1
dateutil         : 2.8.2
pip              : 21.1.3
setuptools       : 56.0.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : None
IPython          : None
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None