-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
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
from numpy.testing import assert_array_equal
import numpy as np
import pandas as pd
N = 1500
M = 1000
df = pd.DataFrame(np.ones((N, M)))
s = pd.Series(np.linspace(1, N, N))
res = df.add(s, axis=0)
for i in range(M):
assert_array_equal(res.iloc[:, i], np.arange(2, N+2), err_msg=f'column {i} failed: {res.iloc[:, i]}')
Issue Description
Arithmetic (e.g. df.add(s, axis=0)
or df.div(s, axis=0)
) between a pd.DataFrame
and a row-aligned pd.Series
using axis=0
appears to mis-broadcast when numpy==2.3.x and when the frame has many columns (high M
in my example).
Early columns are correct (the first assertions in my example typically work fine); later columns contain incorrect values (mostly zeros for me in my example, but on the way to a minimal example I've had all kinds of garbage).
Note:
- The same code works fine on numpy==2.2.x.
- Small values like
M=10
work fine. - Bug seems to only happen for
N > M
.
Expected Behavior
-
The
res
dataframe from the example should be a dataframe with 1000 exactly matching columns, i.e. each column should contain the range from 2 to 1501. -
All assertions should pass.
Installed Versions
INSTALLED VERSIONS
commit : 9c8bc3e
python : 3.12.1
python-bits : 64
OS : Linux
OS-release : 6.12.44-3-MANJARO
Version : #1 SMP PREEMPT_DYNAMIC Mon, 01 Sep 2025 23:07:10 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 2.3.3
numpy : 2.3.3
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 25.2
Cython : 3.1.4
sphinx : 8.2.3
IPython : 9.5.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.14.0
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.6
numba : None
numexpr : 2.10.2
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 21.0.0
pyreadstat : None
pytest : 8.4.2
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.16.2
sqlalchemy : None
tables : 3.10.2
tabulate : 0.9.0
xarray : 2025.7.1
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None