Skip to content

BUG: TypeError for dataframe arithmetic combining empty and mixed type column indexes #57048

Closed
@doraut

Description

@doraut

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 

first = pd.DataFrame()
second = pd.DataFrame(columns=["test"])
third = pd.DataFrame(columns=["foo", ("bar", "baz")])

first + second  # works
second + third  # works
first + third   # raises TypeError: '<' not supported between instances of 'tuple' and 'str'

Issue Description

Calling any arithmetic function with two DataFrames as input where one has an empty column index and the other one has a column index which is not sortable throws a TypeError. Error seems to come from the argsort call introduced here

Expected Behavior

The expected output for the example would be:

Empty DataFrame
Columns: [foo, (bar, baz)]
Index: []

This was the behavior in version 2.1.4.

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.11.0.final.0
python-bits : 64
OS : Linux
OS-release : 6.7.0-arch3-1
Version : #1 SMP PREEMPT_DYNAMIC Sat, 13 Jan 2024 14:37:14 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.0
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.2.1
Cython : None
pytest : 7.4.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operationsRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions