|
12 | 12 | import numpy as np
|
13 | 13 | from numpy.testing import assert_array_equal
|
14 | 14 |
|
15 |
| -from pandas.core.index import Index, Float64Index, Int64Index, MultiIndex, InvalidIndexError |
| 15 | +from pandas.core.index import (Index, Float64Index, Int64Index, MultiIndex, |
| 16 | + InvalidIndexError) |
16 | 17 | from pandas.core.frame import DataFrame
|
17 | 18 | from pandas.core.series import Series
|
18 | 19 | from pandas.util.testing import (assert_almost_equal, assertRaisesRegexp,
|
@@ -75,7 +76,10 @@ def test_set_name_methods(self):
|
75 | 76 | self.assertEqual(ind.names, [name])
|
76 | 77 |
|
77 | 78 | def test_hash_error(self):
|
78 |
| - self.assertRaises(TypeError, hash, self.strIndex) |
| 79 | + with tm.assertRaisesRegexp(TypeError, |
| 80 | + "unhashable type: %r" % |
| 81 | + type(self.strIndex).__name__): |
| 82 | + hash(self.strIndex) |
79 | 83 |
|
80 | 84 | def test_new_axis(self):
|
81 | 85 | new_index = self.dateIndex[None, :]
|
@@ -661,6 +665,12 @@ def setUp(self):
|
661 | 665 | self.mixed = Float64Index([1.5, 2, 3, 4, 5])
|
662 | 666 | self.float = Float64Index(np.arange(5) * 2.5)
|
663 | 667 |
|
| 668 | + def test_hash_error(self): |
| 669 | + with tm.assertRaisesRegexp(TypeError, |
| 670 | + "unhashable type: %r" % |
| 671 | + type(self.float).__name__): |
| 672 | + hash(self.float) |
| 673 | + |
664 | 674 | def check_is_index(self, i):
|
665 | 675 | self.assert_(isinstance(i, Index) and not isinstance(i, Float64Index))
|
666 | 676 |
|
@@ -736,6 +746,7 @@ def test_astype(self):
|
736 | 746 | self.assert_(i.equals(result))
|
737 | 747 | self.check_is_index(result)
|
738 | 748 |
|
| 749 | + |
739 | 750 | class TestInt64Index(unittest.TestCase):
|
740 | 751 | _multiprocess_can_split_ = True
|
741 | 752 |
|
@@ -779,6 +790,12 @@ def test_constructor_corner(self):
|
779 | 790 | arr = np.array([1, '2', 3, '4'], dtype=object)
|
780 | 791 | self.assertRaises(TypeError, Int64Index, arr)
|
781 | 792 |
|
| 793 | + def test_hash_error(self): |
| 794 | + with tm.assertRaisesRegexp(TypeError, |
| 795 | + "unhashable type: %r" % |
| 796 | + type(self.index).__name__): |
| 797 | + hash(self.index) |
| 798 | + |
782 | 799 | def test_copy(self):
|
783 | 800 | i = Int64Index([], name='Foo')
|
784 | 801 | i_copy = i.copy()
|
@@ -1155,6 +1172,12 @@ def setUp(self):
|
1155 | 1172 | labels=[major_labels, minor_labels],
|
1156 | 1173 | names=self.index_names)
|
1157 | 1174 |
|
| 1175 | + def test_hash_error(self): |
| 1176 | + with tm.assertRaisesRegexp(TypeError, |
| 1177 | + "unhashable type: %r" % |
| 1178 | + type(self.index).__name__): |
| 1179 | + hash(self.index) |
| 1180 | + |
1158 | 1181 | def test_set_names_and_rename(self):
|
1159 | 1182 | # so long as these are synonyms, we don't need to test set_names
|
1160 | 1183 | self.assert_(self.index.rename == self.index.set_names)
|
@@ -2231,6 +2254,7 @@ def test_get_combined_index():
|
2231 | 2254 | result = _get_combined_index([])
|
2232 | 2255 | assert(result.equals(Index([])))
|
2233 | 2256 |
|
| 2257 | + |
2234 | 2258 | if __name__ == '__main__':
|
2235 | 2259 | nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
|
2236 | 2260 | exit=False)
|
0 commit comments