class IndexEquals: def setup(self): idx_large_fast = RangeIndex(100000) idx_small_slow = date_range(start="1/1/2012", periods=1) self.mi_large_slow = MultiIndex.from_product( [idx_large_fast, idx_small_slow]) self.idx_non_object = RangeIndex(1) def time_non_object_equals_multiindex(self): self.idx_non_object.equals(self.mi_large_slow)
def test_constructor_same(self): # pass thru w and w/o copy index = RangeIndex(1, 5, 2) result = RangeIndex(index, copy=False) self.assertTrue(result.identical(index)) result = RangeIndex(index, copy=True) self.assertTrue(result.equals(index)) result = RangeIndex(index) self.assertTrue(result.equals(index)) self.assertRaises(TypeError, lambda: RangeIndex(index, dtype='float64'))
def test_constructor_corner(self): arr = np.array([1, 2, 3, 4], dtype=object) index = RangeIndex(1, 5) self.assertEqual(index.values.dtype, np.int64) self.assertTrue(index.equals(arr)) # non-int raise Exception self.assertRaises(TypeError, RangeIndex, '1', '10', '1') self.assertRaises(TypeError, RangeIndex, 1.1, 10.2, 1.3) # invalid passed type self.assertRaises(TypeError, lambda: RangeIndex(1, 5, dtype='float64'))