BUG: Series.agg()
with axis=1 inconsistent with Series.groupby.agg
with axis=1
#46581
Open
3 tasks done
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
I must admit there were similar complaints before, here I present my analysis and solution. (ex. API: Signature of UDF methods, Higher Order Methods API)
Reproducible Example
Call it bug or inconsistency or poor design?
Issue Description
Basically, in consistency's term,
pd.Series.agg()
andpd.Series.groupby().agg()
should act the same way.Anyway as I read the the code(the code is in the bottom), I found parameter axis for
Series.aggregate()
seems useless(or am I missing something here?)Even if it really needs a named paramter, it'd better be named something like
_axis_
to avoid conflicting names withfunctions to apply. For example
np.mean()
has a parameter namedaxis=
and user might name a parameteraxis
(for example,lambda x, axis: np.mean(x, axis=axis)
).As far as I know, we do not need
axis=0
andself._get_axis_number(axis)
for Series at least(DataFrame has similar signature, and I think it should be renamed to something like_axis_
or_axis
or__axis__
).So I propose deleting
axis
parameter from Series.aggregate and renamingaxis
to_axis
for DataFrame.aggreate.Expected Behavior
dat['carat'].groupby(dat['color']).agg(lambda x: np.mean(x))
anddat['carat']..agg(lambda x: np.mean(x))
works similarlyInstalled Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.8.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Korean_Korea.949
pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 60.9.3
Cython : 0.29.28
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.1
pandas_datareader: None
bs4 : 4.10.0
bottleneck : None
fastparquet : None
fsspec : 2022.02.0
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : 1.0.9
s3fs : None
scipy : 1.8.0
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: