Skip to content

BUG: DataFrame.div() ignores axis #64428

@torext

Description

@torext

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 numpy as np
import pandas as pd

x = pd.DataFrame(
    np.arange(30).reshape(5, 6),
    columns=pd.MultiIndex.from_product((list("XY"), list("ABC"))),
)
y = pd.DataFrame(np.arange(15).reshape(5, 3), columns=list("ABC"))
print(x.div(y, axis=1, level=1))

Issue Description

Pandas v3.0.1 gives the below output, seemingly ignoring the axis kwarg:


    X           Y        
    A   B   C   A   B   C
0 NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN

In Pandas v2.3.2 instead this was the (as expected) output:


     X                             Y                    
     A         B         C         A         B         C
0  NaN  1.000000  1.000000       inf  4.000000  2.500000
1  2.0  1.750000  1.600000  3.000000  2.500000  2.200000
2  2.0  1.857143  1.750000  2.500000  2.285714  2.125000
3  2.0  1.900000  1.818182  2.333333  2.200000  2.090909
4  2.0  1.923077  1.857143  2.250000  2.153846  2.071429

Expected Behavior


     X                             Y                    
     A         B         C         A         B         C
0  NaN  1.000000  1.000000       inf  4.000000  2.500000
1  2.0  1.750000  1.600000  3.000000  2.500000  2.200000
2  2.0  1.857143  1.750000  2.500000  2.285714  2.125000
3  2.0  1.900000  1.818182  2.333333  2.200000  2.090909
4  2.0  1.923077  1.857143  2.250000  2.153846  2.071429

Installed Versions

Details

INSTALLED VERSIONS

commit : e04b26f
python : 3.12.11
python-bits : 64
OS : Linux
OS-release : 4.18.0-553.97.1.el8_10.x86_64
Version : #1 SMP Mon Jan 26 05:26:16 EST 2026
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 3.0.1
numpy : 2.3.3
dateutil : 2.9.0.post0
pip : None
Cython : None
sphinx : None
IPython : 9.5.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.5
bottleneck : None
fastparquet : None
fsspec : 2025.9.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.6
lxml.etree : 6.0.2
matplotlib : 3.10.6
numba : 0.62.0
numexpr : None
odfpy : None
openpyxl : 3.1.5
psycopg2 : 2.9.10
pymysql : None
pyarrow : 17.0.0
pyiceberg : None
pyreadstat : None
pytest : 8.4.2
python-calamine : None
pytz : 2025.2
pyxlsb : None
s3fs : 2025.9.0
scipy : 1.16.2
sqlalchemy : 2.0.43
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions