Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Index.sort_values fails with TypeError #35584

Closed
2 of 3 tasks
galipremsagar opened this issue Aug 6, 2020 · 3 comments · Fixed by #35604
Closed
2 of 3 tasks

BUG: Index.sort_values fails with TypeError #35584

galipremsagar opened this issue Aug 6, 2020 · 3 comments · Fixed by #35604
Assignees
Labels
Bug Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@galipremsagar
Copy link

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

>>> import pandas as pd
>>> pd.__version__
'1.1.0'
>>> sr = pd.Series(['a',None,'c',None,'e'])
>>> sr.sort_values()
0       a
2       c
4       e
1    None
3    None
dtype: object
>>> idx = pd.Index(['a',None,'c',None,'e'])
>>> idx
Index(['a', None, 'c', None, 'e'], dtype='object')
>>> idx.sort_values()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/pgali/PycharmProjects/del/venv1/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4448, in sort_values
    _as = idx.argsort()
  File "/Users/pgali/PycharmProjects/del/venv1/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4563, in argsort
    return result.argsort(*args, **kwargs)
TypeError: '<' not supported between instances of 'NoneType' and 'str'

Problem description

Index.sort_values() fails when there are None values in it. However Series.sort_values performs sorting as expected in similar scenario.

Expected Output

We should be able to sort the values of an index similar to that of a series when there are None values.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.3.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8
pandas : 1.1.0
numpy : 1.19.0
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@galipremsagar galipremsagar added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 6, 2020
@AlexKirko AlexKirko added Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 6, 2020
@AlexKirko
Copy link
Member

Checked the issue on the last commit in master. It persists.

@AlexKirko
Copy link
Member

take

@AlexKirko
Copy link
Member

The culprit is not separating missing values before using argsort. Will post a PR with a fix attempt this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants