sort_index on a multiindexed DataFrame with sparse columns fills with NaNs #29735
Labels
good first issue
Needs Tests
Unit test(s) needed to prevent regressions
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Sparse
Sparse Data Type
Milestone
Code Sample, a copy-pastable example if possible
Problem description
When I create a MultiIndexed DataFrame with sparse columns, then call
sort_index()
, in the result0.0
(the sparse fill value) has been replaced withNaN
-- but it seems like only for columns which are all the fill value.It seems like this might also be an issue with
RangeIndex
as well, since if I make a simplerDataFrame
and callsort_index
, without any arguments it's ok but addinglevel=0
(or in factlevel=(anything)
as a kwarg will cause the frame to be filled withNaN
without raising any kind of warningI would expect the following behaviour:
MultiIndex
RangeIndex
, the level keyword should either be totally ignored (no impact on output) or should not be valid to pass in.I don't think this is a duplicate, I searched the tracker but the combination of sparse + multiindex seems to be rare
Expected Output
Actual Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.0.0-36-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 0.25.3
numpy : 1.17.4
pytz : 2019.3
dateutil : 2.8.1
pip : 19.2.2
setuptools : 41.0.1
Cython : 0.29.14
pytest : 3.10.1
hypothesis : None
sphinx : 2.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.9.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.2
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: