def test_from_geopandas_polygon_hole(): gs = gpd.GeoSeries( Polygon( ((0.0, 0.0), (0.0, 1.0), (1.0, 0.0)), [((1.0, 1.0), (1.0, 0.0), (0.0, 0.0))], )) cugs = cuspatial.from_geopandas(gs) assert_eq( cugs.polygons.xy, cudf.Series([ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, ]), ) assert_eq(cugs.polygons.polys, cudf.Series([0, 2])) assert_eq(cugs.polygons.rings, cudf.Series([0, 8, 16]))
def test_from_geopandas_multipoint(): gs = gpd.GeoSeries(MultiPoint([(1.0, 2.0), (3.0, 4.0)])) cugs = cuspatial.from_geopandas(gs) cudf.testing.assert_series_equal(cugs.multipoints.xy, cudf.Series([1.0, 2.0, 3.0, 4.0])) cudf.testing.assert_series_equal(cugs.multipoints.offsets, cudf.Series([0, 4]))
def test_interleaved_point(gs, polys): cugs = cuspatial.from_geopandas(gs) assert_eq(cugs.points.x, gs[gs.type == "Point"].x.reset_index(drop=True)) assert_eq(cugs.points.y, gs[gs.type == "Point"].y.reset_index(drop=True)) assert_eq( cugs.multipoints.x, pd.Series( np.array([np.array(p)[:, 0] for p in gs[gs.type == "MultiPoint"]]).flatten()), ) assert_eq( cugs.multipoints.y, pd.Series( np.array([np.array(p)[:, 1] for p in gs[gs.type == "MultiPoint"]]).flatten()), ) assert_eq( cugs.lines.x, pd.Series( np.array([range(11, 34, 2)]).flatten(), dtype="float64", ), ) assert_eq( cugs.lines.y, pd.Series( np.array([range(12, 35, 2)]).flatten(), dtype="float64", ), ) assert_eq(cugs.polygons.x, pd.Series(polys[:, 0], dtype="float64")) assert_eq(cugs.polygons.y, pd.Series(polys[:, 1], dtype="float64"))
def test_from_geopandas_multipolygon(): gs = gpd.GeoSeries( MultiPolygon([( ((0.0, 0.0), (0.0, 1.0), (1.0, 0.0)), [((1.0, 1.0), (1.0, 0.0), (0.0, 0.0))], )])) cugs = cuspatial.from_geopandas(gs) cudf.testing.assert_series_equal( cugs.polygons.xy, cudf.Series([ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, ]), ) cudf.testing.assert_series_equal(cugs.polygons.polys, cudf.Series([0, 2])) cudf.testing.assert_series_equal(cugs.polygons.rings, cudf.Series([0, 8, 16]))
def test_from_geoseries_complex(gs): cugs = cuspatial.from_geopandas(gs) assert cugs.points.xy.sum() == 18 assert cugs.lines.xy.sum() == 540 assert cugs.multipoints.xy.sum() == 36 assert cugs.polygons.xy.sum() == 7436 assert cugs.polygons.polys.sum() == 38 assert cugs.polygons.rings.sum() == 654
def test_getitem_points(): p0 = Point([1, 2]) p1 = Point([3, 4]) p2 = Point([5, 6]) gps = gpd.GeoSeries([p0, p1, p2]) cus = cuspatial.from_geopandas(gps).to_pandas() assert_eq_point(cus[0], p0) assert_eq_point(cus[1], p1) assert_eq_point(cus[2], p2)
def test_to_shapely_random(): geos_list = [] for i in range(250): geo = generator(3) geos_list.append(geo) gi = gpd.GeoSeries(geos_list) cugs = cuspatial.from_geopandas(gi) cugs_back = cugs.to_geopandas() assert_eq_geo(gi, cugs_back)
def test_getitem_lines(): p0 = LineString([[1, 2], [3, 4]]) p1 = LineString([[1, 2], [3, 4], [5, 6], [7, 8]]) p2 = LineString([[1, 2], [3, 4], [5, 6]]) gps = gpd.GeoSeries([p0, p1, p2]) cus = cuspatial.from_geopandas(gps).to_pandas() assert_eq_linestring(cus[0], p0) assert_eq_linestring(cus[1], p1) assert_eq_linestring(cus[2], p2)
def test_from_geopandas_polygon(): gs = gpd.GeoSeries( Polygon(((0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)), )) cugs = cuspatial.from_geopandas(gs) cudf.testing.assert_series_equal( cugs.polygons.xy, cudf.Series([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0]), ) cudf.testing.assert_series_equal(cugs.polygons.polys, cudf.Series([0, 1])) cudf.testing.assert_series_equal(cugs.polygons.rings, cudf.Series([0, 8]))
def test_from_geopandas_multilinestring(): gs = gpd.GeoSeries( MultiLineString(( ((1.0, 2.0), (3.0, 4.0)), ((5.0, 6.0), (7.0, 8.0)), ))) cugs = cuspatial.from_geopandas(gs) assert_eq( cugs.lines.xy, cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), ) assert_eq(cugs.lines.offsets, cudf.Series([0, 4, 8]))
def test_to_shapely_random(): geos_list = [] for i in range(250): geo = generator(3) geos_list.append(geo) gi = gpd.GeoDataFrame({ "geometry": geos_list, "integer": range(len(geos_list)) }) cugpdf = cuspatial.from_geopandas(gi) cugpdf_back = cugpdf.to_geopandas() assert_eq_geo_df(gi, cugpdf_back)
def test_interleaved_point(gpdf, polys): cugpdf = cuspatial.from_geopandas(gpdf) cugs = cugpdf["geometry"] gs = gpdf["geometry"] pd.testing.assert_series_equal( cugs.points.x.to_pandas(), gs[gs.type == "Point"].x.reset_index(drop=True), ) pd.testing.assert_series_equal( cugs.points.y.to_pandas(), gs[gs.type == "Point"].y.reset_index(drop=True), ) cudf.testing.assert_series_equal( cugs.multipoints.x, cudf.Series( np.array([np.array(p)[:, 0] for p in gs[gs.type == "MultiPoint"]]).flatten()), ) cudf.testing.assert_series_equal( cugs.multipoints.y, cudf.Series( np.array([np.array(p)[:, 1] for p in gs[gs.type == "MultiPoint"]]).flatten()), ) cudf.testing.assert_series_equal( cugs.lines.x, cudf.Series( np.array([range(11, 34, 2)]).flatten(), dtype="float64", ), ) cudf.testing.assert_series_equal( cugs.lines.y, cudf.Series( np.array([range(12, 35, 2)]).flatten(), dtype="float64", ), ) cudf.testing.assert_series_equal(cugs.polygons.x, cudf.Series(polys[:, 0], dtype="float64")) cudf.testing.assert_series_equal(cugs.polygons.y, cudf.Series(polys[:, 1], dtype="float64"))
def test_sort_values(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) sort_gpdf = gpdf.sort_values("random") sort_cugpdf = cugpdf.sort_values("random").to_pandas() pd.testing.assert_frame_equal(sort_gpdf, sort_cugpdf)
def test_from_geopandas_linestring(): gs = gpd.GeoSeries(LineString(((4.0, 3.0), (2.0, 1.0)))) cugs = cuspatial.from_geopandas(gs) assert_eq(cugs.lines.xy, cudf.Series([4.0, 3.0, 2.0, 1.0])) assert_eq(cugs.lines.offsets, cudf.Series([0, 4]))
def test_from_geopandas_point(): gs = gpd.GeoSeries(Point(1.0, 2.0)) cugs = cuspatial.from_geopandas(gs) assert_eq(cugs.points.xy, cudf.Series([1.0, 2.0]))
def test_groupby(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) pd.testing.assert_frame_equal( gpdf.groupby("key").min().sort_index(), cugpdf.groupby("key").min().sort_index().to_pandas(), )
def test_select_multiple_columns(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) assert_eq(cugpdf[["geometry", "key"]], gpdf[["geometry", "key"]])
def test_to_shapely(gs, series_slice): geometries = gs[series_slice] gi = gpd.GeoSeries(geometries) cugs = cuspatial.from_geopandas(gi) cugs_back = cugs.to_geopandas() assert_eq_geo(gi, cugs_back)
def test_type_persistence(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) assert type(cugpdf["geometry"]) == cuspatial.geometry.geoseries.GeoSeries
def test_groupby(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) assert_eq( gpdf.groupby("key").min().sort_index(), cugpdf.groupby("key").min().sort_index(), )
def test_sort_values(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) sort_gpdf = gpdf.sort_values("random") sort_cugpdf = cugpdf.sort_values("random") assert_eq(sort_gpdf, sort_cugpdf)
def test_mixed_dataframe(gs): gpdf = gpd.GeoDataFrame({"a": list(range(100, 100 + len(gs))), "b": gs}) cgdf = cuspatial.from_geopandas(gpdf) assert_eq(gpdf["a"], cgdf["a"].to_pandas()) assert gpdf["b"].equals(cgdf["b"].to_pandas()) assert_eq(gpdf, cgdf)
def test_dataframe_column_access(gs): gpdf = gpd.GeoDataFrame({"a": list(range(0, len(gs))), "b": gs}) cgdf = cuspatial.from_geopandas(gpdf) assert gpdf["b"].equals(cgdf["b"].to_pandas())
def test_to_shapely(gpdf, series_slice): geometries = gpdf.iloc[series_slice, :] gi = gpd.GeoDataFrame(geometries) cugpdf = cuspatial.from_geopandas(gi) cugpdf_back = cugpdf.to_geopandas() assert_eq_geo_df(gi, cugpdf_back)
def test_select_multiple_columns(gpdf): cugpdf = cuspatial.from_geopandas(gpdf) pd.testing.assert_frame_equal(cugpdf[["geometry", "key"]].to_pandas(), gpdf[["geometry", "key"]])
def test_size(gs, series_slice): geometries = gs[series_slice] gi = gpd.GeoSeries(geometries) cugs = cuspatial.from_geopandas(gi) assert len(gi) == len(cugs)
def test_geobuffer_len(gs): cugs = cuspatial.from_geopandas(gs) assert len(cugs._column._geo) == 12