Skip to content

BUG: sum with axis=None does not apply the aggregation across both axes. #52977

Closed
@arnaudlegout

Description

@arnaudlegout

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.

Reproducible Example

import pandas as pd
import numpy as np
a = np.random.randint(1, 20, 9).reshape(3,3)
p = pd.DataFrame(a, index=['a', 'b', 'c'], columns=['x', 'y', 'z'])
p.sum(axis=None)
>>>
x    42
y    24
z    20
dtype: int64

Issue Description

According to the documentation of DataFrame.sum using axis=None should apply the aggregation across both axes.
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sum.html

This is not the case in the given example.

Expected Behavior

returns the aggregation across both axes, that is, return 86

Installed Versions

INSTALLED VERSIONS

commit : 37ea63d
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-1033-gcp
Version : #40~20.04.1-Ubuntu SMP Tue Jun 14 00:44:12 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : C.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.1
numpy : 1.22.1
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.6.1
pip : 23.1
Cython : 0.29.30
pytest : 7.1.3
hypothesis : 6.72.0
sphinx : 6.1.3
blosc : None
feather : None
xlsxwriter : 3.0.8
lxml.etree : 4.8.0
html5lib : 1.1
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.1.2
IPython : 7.34.0
pandas_datareader: 0.10.0
bs4 : 4.8.2
bottleneck : 1.3.2
brotli : 1.0.9
fastparquet : None
fsspec : 2022.5.0
gcsfs : 2022.5.0
matplotlib : 3.6.3
numba : 0.56.4
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.9
pandas_gbq : 0.19.1
pyarrow : 10.0.1
pyreadstat : 1.1.9
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : 1.4.39
tables : 3.7.0
tabulate : 0.8.10
xarray : 2022.6.0
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : 2.1.0
pyqt5 : None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions