Skip to content

Commit 92bc165

Browse files
committed
Merge pull request #7327 from cpcloud/fix-unorderables-mixed-union
BUG: already mixed indexes should not sort
2 parents 3b0c542 + 43e9373 commit 92bc165

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

pandas/core/index.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import datetime
33
import warnings
44
from functools import partial
5-
import warnings
65
from pandas.compat import range, zip, lrange, lzip, u, reduce
76
from pandas import compat
87
import numpy as np
@@ -29,6 +28,9 @@
2928
__all__ = ['Index']
3029

3130

31+
_unsortable_types = frozenset(('mixed', 'mixed-integer'))
32+
33+
3234
def _try_get_item(x):
3335
try:
3436
return x.item()
@@ -1011,7 +1013,10 @@ def union(self, other):
10111013
warnings.warn("%s, sort order is undefined for "
10121014
"incomparable objects" % e, RuntimeWarning)
10131015
else:
1014-
result.sort()
1016+
types = frozenset((self.inferred_type,
1017+
other.inferred_type))
1018+
if not types & _unsortable_types:
1019+
result.sort()
10151020

10161021
else:
10171022
result = self.values

pandas/tests/test_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ def test_tuple_union_bug(self):
793793

794794
# union broken
795795
union_idx = idx1.union(idx2)
796-
expected = pandas.Index(sorted(set(idx1) | set(idx2)))
796+
expected = idx2
797797
self.assertEqual(union_idx.ndim, 1)
798798
self.assertTrue(union_idx.equals(expected))
799799

0 commit comments

Comments
 (0)