Esempio n. 1
0
def test_sjoin(translate):
    if translate:
        triangles2 = [
            shapely.affinity.translate(t, 0.00001, 0) for t in triangles
        ]
    else:
        triangles2 = triangles

    l = dg.repartition(points_df, triangles2)
    r = dg.repartition(grid_df, coarse_grid)

    result = dg.sjoin(l, r, how='inner', op='intersects')
    expected = gpd.sjoin(points_df, grid_df, how='inner', op='intersects')
    assert len(result) == len(expected)
    assert (result._regions.area < (coarse_delta + 0.1)**2).all()
Esempio n. 2
0
def test_repartition_single_element():
    df = gpd.GeoDataFrame({
        'x': [1, 2],
        'geometry': [Point(0, 0), Point(1, 1)]
    })
    gdf = dg.repartition(df, triangles)
    assert len(df) == 2
Esempio n. 3
0
def test_sjoin_dask_normal():
    df = dg.repartition(points_df, triangles)

    result = dg.sjoin(df, grid_df, buffer=0)
    expected = gpd.sjoin(points_df, grid_df)
    assert_eq(result, expected)

    df._regions.name = None

    assert_eq(result._regions, df._regions)
Esempio n. 4
0
def test_repartition_polys():
    with dask.set_options(get=dask.get):
        df = dg.from_pandas(grid_df, npartitions=3)
        assert len(df) == len(grid_df)
        df = dg.repartition(df, triangles)
        # assert len(df) == len(grid_df)  # fails because touches fails
        df = df.persist()

        assert df.npartitions == 2

        for i in range(df.npartitions):
            part = df.get_partition(i)
            geoms = part.geometry.compute()
            assert geoms.within(part._regions.iloc[0]).all()
Esempio n. 5
0
def test_repartition_pandas_expands_regions(translate):
    if translate:
        triangles2 = [
            shapely.affinity.translate(t, 0.00001, 0) for t in triangles
        ]
    else:
        triangles2 = triangles

    df = dg.repartition(grid_df, triangles2)

    for i in range(df.npartitions):
        part = df.get_partition(i)
        geoms = part.geometry.compute()
        assert geoms.within(part._regions.iloc[0]).all()

    assert len(df) == len(grid_df)
Esempio n. 6
0
def test_repartition():
    df = points_df
    df = dg.repartition(df, triangles).persist()
    assert df.npartitions == 2
    assert len(df) == len(points_df)
    assert df._regions.iloc[0].equals(triangles[0])
    assert df._regions.iloc[1].equals(triangles[1])

    for i in range(df.npartitions):
        part = df.get_partition(i)
        geoms = part.geometry.compute()
        assert geoms.within(part._regions.iloc[0]).all()

    df2 = df.repartition(grid).persist()
    assert len(df2) == len(points_df)
    assert df2.npartitions == len(grid)

    for i in range(df2.npartitions):
        part = df2.get_partition(i)
        geoms = part.geometry.compute()
        assert geoms.within(part._regions.iloc[0]).all()
Esempio n. 7
0
def test_sjoin_dask_normal():
    df = dg.repartition(points_df, triangles)
    assert isinstance(df.value, dd.Series)
    assert isinstance(df[['value']], dd.DataFrame)
    assert_eq((df.value > 0.5).value_counts(),
              (points_df.value > 0.5).value_counts())
Esempio n. 8
0
def test_repartition_trim():
    polys = triangles + [Polygon([(10, 10), (10, 20), (20, 10)])]
    df = dg.repartition(grid_df, polys)

    assert df.npartitions == 2
Esempio n. 9
0
def test_persist():
    df = dg.from_pandas(points_df, npartitions=5)
    df = dg.repartition(df, triangles)

    df2 = df.persist()
    assert not any(map(dask.core.istask, df2.dask.values()))