From 43e9373c7f78f68bf113701738edda57e607e7fe Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Tue, 3 Jun 2014 18:58:11 -0400 Subject: [PATCH] BUG: already mixed indexes should not sort --- pandas/core/index.py | 9 +++++++-- pandas/tests/test_index.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pandas/core/index.py b/pandas/core/index.py index 146b7cd0eb503..8b2c7bde44782 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -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 @@ -29,6 +28,9 @@ __all__ = ['Index'] +_unsortable_types = frozenset(('mixed', 'mixed-integer')) + + def _try_get_item(x): try: return x.item() @@ -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 diff --git a/pandas/tests/test_index.py b/pandas/tests/test_index.py index 5def2039c5ee8..29aed792bfe11 100644 --- a/pandas/tests/test_index.py +++ b/pandas/tests/test_index.py @@ -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))