示例#1
0
def test_copy():
    mp = MetaPartition(
        label="label_1",
        files={"core": "file"},
        data={"core": pd.DataFrame()},
        indices={"test": [1, 2, 3]},
        dataset_metadata={"dataset": "metadata"},
    )
    new_mp = mp.copy()

    # Check if the copy is identical
    assert new_mp == mp
    # ... but not the same object
    assert id(new_mp) != id(mp)

    new_mp = mp.copy(files={"new": "file"})
    assert id(new_mp) != id(mp)
    assert new_mp.files == {"new": "file"}

    new_mp = mp.copy(indices={"new": [1, 2, 3]})
    assert id(new_mp) != id(mp)
    assert new_mp.indices == {"new": [1, 2, 3]}

    new_mp = mp.copy(dataset_metadata={"new": "metadata"})
    assert id(new_mp) != id(mp)
    assert new_mp.dataset_metadata == {"new": "metadata"}
def test_nested_copy():
    mp = MetaPartition(
        label="label_1",
        file="file",
        data=pd.DataFrame({"test": [1, 2, 3]}),
        indices={"test": {
            1: "label_1",
            2: "label_2",
            3: "label_3"
        }},
    )

    mp_2 = MetaPartition(
        label="label_2",
        data=pd.DataFrame({"test": [4, 5, 6]}),
        indices={"test": [4, 5, 6]},
    )
    mp = mp.add_metapartition(mp_2)
    assert len(mp.metapartitions) == 2
    new_mp = mp.copy()

    # Check if the copy is identical
    assert len(new_mp.metapartitions) == len(mp.metapartitions)
    assert new_mp == mp
    # ... but not the same object
    assert id(new_mp) != id(mp)
示例#3
0
def test_copy():
    mp = MetaPartition(
        label="label_1", file="file", data=pd.DataFrame(), indices={"test": [1, 2, 3]}
    )
    new_mp = mp.copy()

    # Check if the copy is identical
    assert new_mp == mp
    # ... but not the same object
    assert id(new_mp) != id(mp)

    new_mp = mp.copy(file="new_file")
    assert id(new_mp) != id(mp)
    assert new_mp.file == "new_file"

    new_mp = mp.copy(indices={"new": [1, 2, 3]})
    assert id(new_mp) != id(mp)
    assert new_mp.indices == {"new": [1, 2, 3]}