Skip to content

sort_index doesn't sort MultiIndex when .loc[] referred to non-existent label on other axis #12261

Closed
@toobaz

Description

@toobaz
In [2]: df = pd.DataFrame(0, columns=[], index=pd.MultiIndex.from_product([[], []]))

In [3]: df.loc['b', '2'] = 1

In [4]: df.loc['a', '3'] = 1

In [5]: df.sort_index()
Out[5]: 
      2    3
b   1.0  NaN
a   NaN  1.0

In [6]: df.sort_index().index.is_monotonic
Out[6]: False

Am I missing anything obvious?!
(Notice that this is not related to any of the two axes being initialized as empty)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions