def test_basic(npartitions): df = gpd.GeoDataFrame({'x': [1, 2], 'geometry': triangles}) ddf = dg.from_pandas(df, npartitions=npartitions) assert ddf.npartitions == npartitions assert_eq(ddf, df) assert_eq(ddf.x, df.x) assert_eq(ddf.x + 1, df.x + 1)
def test_unary_method(npartitions, op, args): df = gpd.GeoDataFrame({'x': [1, 2], 'geometry': triangles}) ddf = dg.from_pandas(df, npartitions=npartitions) def func(a): return getattr(a, op)(*args) point = Point(0.2, 0.2) assert_eq(func(ddf), func(df)) assert_eq(func(ddf.geometry), func(df.geometry))
def test_binary_singleton(npartitions, op): df = gpd.GeoDataFrame({'x': [1, 2], 'geometry': triangles}) ddf = dg.from_pandas(df, npartitions=npartitions) def func(a, b): return getattr(a, op)(b) point = Point(0.2, 0.2) result = func(ddf, point) assert_eq(func(ddf, point), func(df, point)) assert_eq(func(ddf.geometry, point), func(df.geometry, point))
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()
def test_drop(): df = dg.from_pandas(points_df, npartitions=4) assert_eq(df.drop('value', axis=1), points_df.drop('value', axis=1)) assert isinstance(df.drop('geometry', axis=1), dd.DataFrame) assert_eq(df.drop('geometry', axis=1), points_df.drop('geometry', axis=1))
def test_sjoin_dask_normal(): df = dg.from_pandas(points_df, npartitions=4) assert_eq(df.index, points_df.index)
def test_len(): df = points_df ddf = dg.from_pandas(df, npartitions=3) assert len(ddf) == len(df)
def test_repr(func): ddf = dg.from_pandas(points_df, npartitions=5) for x in [ddf, ddf.value, ddf.geometry]: text = func(x) assert '5' in text assert type(x).__name__ in text
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()))
def test_head(): ddf = dg.from_pandas(points_df, npartitions=5) head = ddf.head(5) assert isinstance(head, gpd.GeoDataFrame) assert_eq(head, points_df.head(5))