Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept None and python list in GeoSeries constructor #686

Merged
merged 4 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions python/cuspatial/cuspatial/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from functools import cached_property
from numbers import Integral
from typing import Tuple, TypeVar, Union
from typing import Optional, Tuple, TypeVar, Union

import cupy as cp
import geopandas as gpd
Expand Down Expand Up @@ -46,14 +46,16 @@ class GeoSeries(cudf.Series):

def __init__(
self,
data: Union[gpd.GeoSeries, Tuple, T, pd.Series, GeoColumn],
data: Optional[
Union[gpd.GeoSeries, Tuple, T, pd.Series, GeoColumn, list]
],
index: Union[cudf.Index, pd.Index] = None,
dtype=None,
name=None,
nan_as_null=True,
):
# Condition data
if isinstance(data, pd.Series):
if data is None or isinstance(data, (pd.Series, list)):
data = gpGeoSeries(data)
# Create column
if isinstance(data, GeoColumn):
Expand Down
35 changes: 35 additions & 0 deletions python/cuspatial/cuspatial/tests/test_geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import pandas as pd
import pytest
from geopandas.testing import assert_geoseries_equal
from shapely.affinity import rotate
from shapely.geometry import (
LineString,
Expand Down Expand Up @@ -358,6 +359,39 @@ def test_loc(gs):
assert_eq_geo(gsslice, cugsslice.to_geopandas())


@pytest.mark.parametrize(
"data",
[
None,
[],
[
Point(1, 1),
MultiPoint([(2, 2), (3, 3)]),
Point(4, 4),
Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]),
],
gpd.GeoSeries(
[
MultiLineString(
[[(0, 0), (1, 2), (1, 0)], [(-1, -1), (-1, 3), (0, 0)]]
),
MultiPolygon(
[
Polygon([(0, 0), (1, 1), (0, 1), (0, 0)]),
Polygon([(2, 2), (2, 3), (3, 3), (2, 2)]),
]
),
]
),
],
)
def test_construction_from_foreign_object(data):
cugs = cuspatial.GeoSeries(data)
gps = gpd.GeoSeries(data)

assert_geoseries_equal(cugs.to_geopandas(), gps)


def test_shapefile_constructor():
host_dataframe = gpd.read_file(
gpd.datasets.get_path("naturalearth_lowres")
Expand All @@ -370,6 +404,7 @@ def test_shapefile_constructor():
gs.to_file("naturalearth_lowres_polygon")
data = cuspatial.read_polygon_shapefile("naturalearth_lowres_polygon")
cus = cuspatial.GeoSeries(data)

assert_eq_geo(gs.reset_index(drop=True), cus.to_geopandas())


Expand Down