コード例 #1
0
def test_reset_index_multiple_resources_referenced(fixture):
    reset_index(fixture, "csv-multiple")

    array, _ = fixture.get_resource("array.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([14, 15, 15]))

    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([11, 11, 13]))
    assert np.allclose(array["col"], np.array([2, 3, 3]))
コード例 #2
0
def test_reset_index_multiple_calls(fixture):
    reset_index(fixture, "vector-csv-rows")

    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([14, 15, 15]))

    # New CSV file, so indexing starts over
    reset_index(fixture, "vector-csv-cols")
    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([0, 1, 1]))

    dp_unchanged()
コード例 #3
0
def test_reset_index_modified(fixture):
    assert not fixture._modified

    reset_index(fixture, "vector-csv-rows")
    assert fixture._modified == set([fixture._get_index("vector.indices")])

    fixture = load_datapackage(
        OSFS(str(Path(__file__).parent.resolve() / "fixtures" / "indexing")))
    assert not fixture._modified

    reset_index(fixture, "csv-multiple")
    assert fixture._modified == set([
        fixture._get_index("vector.indices"),
        fixture._get_index("array.indices")
    ])
コード例 #4
0
def test_reset_index_metadata_name_error(fixture):
    with pytest.raises(KeyError):
        reset_index(fixture, "foo")

    with pytest.raises(ValueError):
        reset_index(fixture, "vector.indices")
コード例 #5
0
def test_reset_index_return_object(fixture):
    dp = reset_index(fixture, "vector-csv-rows")

    array, _ = dp.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([14, 15, 15]))
コード例 #6
0
def test_reset_index_pass_array(fixture):
    reset_index(fixture, "array-csv-both")

    array, _ = fixture.get_resource("array.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([2, 3, 3]))
コード例 #7
0
def test_reset_index_pass_datapackage(fixture):
    reset_index(fixture, "vector-csv-rows")

    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([14, 15, 15]))
コード例 #8
0
def test_reset_index_pass_only_cols(fixture):
    reset_index(fixture, "vector-csv-cols")

    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([11, 11, 13]))
    assert np.allclose(array["col"], np.array([0, 1, 1]))
コード例 #9
0
def test_reset_index_both_row_col(fixture):
    reset_index(fixture, "vector-csv-both")

    array, _ = fixture.get_resource("vector.indices")
    assert np.allclose(array["row"], np.array([0, 0, 1]))
    assert np.allclose(array["col"], np.array([2, 3, 3]))