Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG: Int64Index.take and MultiIndex.take don't lost names, GH #262

  • Loading branch information...
commit 9ddfc57c383ae4ce36b81fa14a227a1e0037c552 1 parent 06130c6
@wesm wesm authored
View
2  RELEASE.rst
@@ -158,6 +158,8 @@ feedback on the library.
- `DataFrame.iteritems` and `DataFrame._series` not assigning name attribute
- Panel.__repr__ raised exception on length-0 major/minor axes
- `DataFrame.join` on key with empty DataFrame produced incorrect columns
+ - `Int64Index.take` and `MultiIndex.take` lost name field, fix downstream
+ issue GH #262
- `read_csv` / `read_table` fixes
- Be less aggressive about converting float->int in cases of floating point
representations of integers like 1.0, 2.0, etc.
View
5 pandas/core/index.py
@@ -759,7 +759,7 @@ def take(self, *args, **kwargs):
Analogous to ndarray.take
"""
taken = self.values.take(*args, **kwargs)
- return Int64Index(taken)
+ return Int64Index(taken, name=self.name)
class DateIndex(Index):
pass
@@ -1064,7 +1064,8 @@ def take(self, *args, **kwargs):
Analogous to ndarray.take
"""
new_labels = [lab.take(*args, **kwargs) for lab in self.labels]
- return MultiIndex(levels=self.levels, labels=new_labels)
+ return MultiIndex(levels=self.levels, labels=new_labels,
+ names=self.names)
def append(self, other):
"""
View
9 pandas/tests/test_index.py
@@ -556,6 +556,11 @@ def test_prevent_casting(self):
result = self.index.astype('O')
self.assert_(result.dtype == np.object_)
+ def test_take_preserve_name(self):
+ index = Int64Index([1,2,3,4], name='foo')
+ taken = index.take([3,0,1])
+ self.assertEqual(index.name, taken.name)
+
class TestMultiIndex(unittest.TestCase):
def setUp(self):
@@ -967,6 +972,10 @@ def test_insert(self):
# key wrong length
self.assertRaises(Exception, self.index.insert, 0, ('foo2',))
+ def test_take_preserve_name(self):
+ taken = self.index.take([3,0,1])
+ self.assertEqual(taken.names, self.index.names)
+
class TestFactor(unittest.TestCase):
def setUp(self):
View
4 pandas/tests/test_multilevel.py
@@ -75,6 +75,10 @@ def test_reindex_preserve_levels(self):
chunk = ymdT.ix[:, new_index]
self.assert_(chunk.columns is new_index)
+ def test_sort_index_preserve_levels(self):
+ result = self.frame.sort_index()
+ self.assertEquals(result.index.names, self.frame.index.names)
+
def test_repr_to_string(self):
repr(self.frame)
repr(self.ymd)
Please sign in to comment.
Something went wrong with that request. Please try again.