def test_ni_merge(): ni1 = NamedIndex(["r1", "r2"], [[1, 2], [3, 4]]) ni2 = ni1.copy() ni2.add_name("r3", [5, 6]) with pytest.raises(ValueError): ni1.merge(ni2) with pytest.raises(ValueError): ni1.merge(ni2, duplicate="raise") with pytest.raises(ValueError): ni1.merge(ni2, duplicate="not something viable") ni3 = ni1.merge(ni2, offset=10, duplicate="union") assert len(ni3) == 3 assert len(ni3["r1"]) == 4 assert len(ni3["r2"]) == 4 assert len(ni3["r3"]) == 2 ni3 = ni1.merge(ni2, offset=10, duplicate="omit") assert len(ni3) == 1 ni3 = ni1.merge(ni2, offset=10, duplicate="left") assert len(ni3) == 3 assert np.array_equal(ni3["r1"], ni1["r1"]) assert np.array_equal(ni3["r2"], ni1["r2"]) assert np.array_equal(ni3["r3"], ni2["r3"] + 10) ni3 = ni1.merge(ni2, offset=10, duplicate="right") assert len(ni3) == 3 assert np.array_equal(ni3["r1"], ni2["r1"] + 10) assert np.array_equal(ni3["r2"], ni2["r2"] + 10) assert np.array_equal(ni3["r3"], ni2["r3"] + 10)
def test_ni_copy(): ni = NamedIndex() ni.add_name('name-1', [0]) ni.add_name('name-2', [1]) n2 = ni.copy() assert ni._name == n2._name