def test_index_comparision(): start, stop = 10, 34 rg = RangeIndex(start, stop) gi = Int64Index(np.arange(start, stop)) assert rg.equals(gi) assert gi.equals(rg) assert not rg[:-1].equals(gi) assert rg[:-1].equals(gi[:-1])
def test_index_immutable(): start, stop = 10, 34 rg = RangeIndex(start, stop) with pytest.raises(TypeError): rg[1] = 5 gi = Int64Index(np.arange(start, stop)) with pytest.raises(TypeError): gi[1] = 5
def test_index_find_label_range(): # Monotonic Index idx = Int64Index(np.asarray([4, 5, 6, 10])) assert idx.find_label_range(4, 6) == (0, 3) assert idx.find_label_range(5, 10) == (1, 4) assert idx.find_label_range(0, 6) == (0, 3) assert idx.find_label_range(4, 11) == (0, 4) # Non-monotonic Index idx_nm = Int64Index(np.asarray([5, 4, 6, 10])) assert idx_nm.find_label_range(4, 6) == (1, 3) assert idx_nm.find_label_range(5, 10) == (0, 4) # Last value not found with pytest.raises(ValueError) as raises: idx_nm.find_label_range(0, 6) raises.match("value not found") # Last value not found with pytest.raises(ValueError) as raises: idx_nm.find_label_range(4, 11) raises.match("value not found")
def test_index_rename_preserves_arg(): idx1 = Int64Index([1, 2, 3], name="orig_name") # this should be an entirely new object idx2 = idx1.rename("new_name", inplace=False) assert idx2.name == "new_name" assert idx1.name == "orig_name" # a new object but referencing the same data idx3 = as_index(idx1, name="last_name") assert idx3.name == "last_name" assert idx1.name == "orig_name"
def test_name(): idx = Int64Index(np.asarray([4, 5, 6, 10]), name="foo") assert idx.name == "foo"
def test_reductions(func): x = np.asarray([4, 5, 6, 10]) idx = Int64Index(np.asarray([4, 5, 6, 10])) assert func(x) == func(idx)