sort_index with sort_remaining=False does not work with int level · Issue #21052 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
import pandas as pd mi = pd.MultiIndex.from_tuples([[2,2],[2,1],[1,2],[1,1]], names=list('AB')) a = pd.Series([1,2,3,4], index=mi) a.sort_index(level=0, sort_remaining=False)
returns:
A B
1 1 4
2 3
2 1 2
2 1
dtype: int64
Problem description
Besides A (level 0), also B (level 1) is sorted. This, despite the fact that sort_remaining is set to False.
Expected Output
By comparison, the correct result is obtained when specifying the level by its name:
a.sort_index(level='A', sort_remaining=False)
with
A B
1 2 3
1 4
2 2 1
1 2
dtype: int64
Exactly the same result should be expected when using level=0
instead of level='A'
.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 2.7.13.final.0
python-bits: 32
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.22.0
pytest: None
pip: 9.0.3
setuptools: 36.4.0
Cython: None
numpy: 1.14.1
scipy: 1.0.0
pyarrow: None
xarray: 0.10.0
IPython: 5.3.0
sphinx: 1.6.3
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: 2.5.0
xlrd: 1.0.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.2.3
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None