Skip to content

BUG: already mixed indexes should not sort #7327

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

Merged
merged 1 commit into from
Jun 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import datetime
import warnings
from functools import partial
import warnings
from pandas.compat import range, zip, lrange, lzip, u, reduce
from pandas import compat
import numpy as np
Expand All @@ -29,6 +28,9 @@
__all__ = ['Index']


_unsortable_types = frozenset(('mixed', 'mixed-integer'))


def _try_get_item(x):
try:
return x.item()
Expand Down Expand Up @@ -1011,7 +1013,10 @@ def union(self, other):
warnings.warn("%s, sort order is undefined for "
"incomparable objects" % e, RuntimeWarning)
else:
result.sort()
types = frozenset((self.inferred_type,
other.inferred_type))
if not types & _unsortable_types:
result.sort()

else:
result = self.values
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ def test_tuple_union_bug(self):

# union broken
union_idx = idx1.union(idx2)
expected = pandas.Index(sorted(set(idx1) | set(idx2)))
expected = idx2
self.assertEqual(union_idx.ndim, 1)
self.assertTrue(union_idx.equals(expected))

Expand Down