Skip to content

BUG: sort_values should have consistent behavior irrespective of the number of sort columns #57312

Open
@arpit-goel

Description

@arpit-goel

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 datetime
df = pd.DataFrame([["", 1], [datetime.date.today(), 2]], columns=['a', 'b']) # column a contains mixed data
df.sort_values(['a']) # raises error
df.sort_values(['a', 'b'])  # no error
df.sort_values(['a', 'a'])  # no error

Issue Description

When using sort_values on a data frame where at least one column contains mixed data, it should handle it gracefully or raise appropriate errors. It raises an error if a mixed-type column is used for sorting and succeeds if multiple columns are used, where one of them is a mixed-type column.

Expected Behavior

The behvior should be consistent irrespective of the number of columns being used for sorting.

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.9.16.final.0
python-bits : 64
OS : Darwin
OS-release : 22.5.0
Version : Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.3
numpy : 1.24.3
pytz : 2022.1
dateutil : 2.8.2
setuptools : 65.5.1
pip : 22.0.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.3
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 3.0.1
IPython : 8.10.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.5.0
gcsfs : None
matplotlib : 3.7.0
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : 14.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
zstandard : None
tzdata : 2022.1
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugSortinge.g. sort_index, sort_values

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions