Skip to content

BUG: Division results in 0 values for large dfs with numpy==2.3.5 #63320

@tilyevsky12

Description

@tilyevsky12

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

# Set dimensions
n_rows = 5000
n_cols = 4097

# Create column names
cols = [f"col_{i}" for i in range(1, n_cols + 1)]

# Generate random DataFrame
df = pd.DataFrame(np.random.randn(n_rows, n_cols), columns=cols)

# Generate Series with same column index
series = pd.Series(np.ones(n_cols), index=cols)

# Divide DataFrame by Series (broadcasting across rows)
result = df.div(series)

df_from_np = pd.DataFrame(df.values/series.values, index=df.index, columns=df.columns)

print (df.equals(result))# -> False when n_cols > 4096
print (df.equals(df_from_np))# -> True

Issue Description

If you have a df with more than 4096 columns, dividing it by a series (row/element wise division), you can get 0s in the result for random entries in the df. However, doing this in numpy directly and then converting back into a df works no problem. I have confirmed that downgrading numpy to 1.26.4 resolves the issue about equals statements will print True.

Expected Behavior

After dividing a df by a series of ones, it should equal itself and not have any 0s in the output.

Installed Versions

Details

INSTALLED VERSIONS

commit : 9c8bc3e
python : 3.11.7
python-bits : 64
OS : Linux
OS-release : 5.14.0-503.40.1.el9_5.x86_64
Version : #1 SMP PREEMPT_DYNAMIC Wed Apr 30 17:38:54 UTC 2025
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.3.3
numpy : 2.3.5
pytz : 2023.4
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : 3.0.12
sphinx : None
IPython : 9.0.2
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.5
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : 2024.11.0
fsspec : 2025.3.2
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : None
matplotlib : 3.10.1
numba : 0.63.0
numexpr : 2.10.2
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : 1.4.6
pyarrow : 19.0.1
pyreadstat : None
pytest : 8.3.5
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.3
sqlalchemy : 2.0.44
tables : 3.10.2
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : 0.23.0
tzdata : 2025.2
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugUpstream issueIssue related to pandas dependency

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions