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

Disallow GeoSeries from accepting a column in favor of _from_column #1434

Merged
merged 5 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 17 additions & 17 deletions python/cuspatial/cuspatial/core/_column/geocolumn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2023 NVIDIA CORPORATION
# Copyright (c) 2021-2024, NVIDIA CORPORATION

from enum import Enum
from functools import cached_property
Expand Down Expand Up @@ -153,14 +153,14 @@ def _from_points_xy(cls, points_xy: ColumnBase):
coord_dtype = points_xy.dtype
return cls(
(
cudf.Series(point_col),
cudf.Series(
cudf.Series._from_column(point_col),
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.MULTIPOINT, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.LINESTRING, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POLYGON, coord_dtype)
),
),
Expand Down Expand Up @@ -205,14 +205,14 @@ def _from_multipoints_xy(

return cls(
(
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POINT, coord_dtype)
),
cudf.Series(multipoint_col),
cudf.Series(
cudf.Series._from_column(multipoint_col),
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.LINESTRING, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POLYGON, coord_dtype)
),
),
Expand Down Expand Up @@ -265,14 +265,14 @@ def _from_linestrings_xy(

return cls(
(
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POINT, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.MULTIPOINT, coord_dtype)
),
cudf.Series(linestrings_col),
cudf.Series(
cudf.Series._from_column(linestrings_col),
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POLYGON, coord_dtype)
),
),
Expand Down Expand Up @@ -331,16 +331,16 @@ def _from_polygons_xy(

return cls(
(
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POINT, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.MULTIPOINT, coord_dtype)
),
cudf.Series(
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.LINESTRING, coord_dtype)
),
cudf.Series(polygons_col),
cudf.Series._from_column(polygons_col),
),
meta,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2024, NVIDIA CORPORATION

import cudf
from cudf.core.column import as_column

Expand Down Expand Up @@ -200,4 +202,4 @@ def __call__(self):
# If `align==False`, geopandas preserves lhs index.
index = None if self._align else self._res_index

return cudf.Series(result, index=index, nan_as_null=False)
return cudf.Series._from_column(result, index=index)
4 changes: 2 additions & 2 deletions python/cuspatial/cuspatial/core/binops/equals_count.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

import cudf

Expand Down Expand Up @@ -76,4 +76,4 @@ def pairwise_multipoint_equals_count(lhs, rhs):
rhs_column = rhs._column.mpoints._column
result = c_pairwise_multipoint_equals_count(lhs_column, rhs_column)

return cudf.Series(result)
return cudf.Series._from_column(result)
10 changes: 5 additions & 5 deletions python/cuspatial/cuspatial/core/binops/intersection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -112,12 +112,12 @@ def pairwise_linestring_intersection(
geometries = GeoSeries(
GeoColumn(
(
cudf.Series(points),
cudf.Series(
cudf.Series._from_column(points),
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.MULTIPOINT, coord_dtype)
),
cudf.Series(linestring_column),
cudf.Series(
cudf.Series._from_column(linestring_column),
cudf.Series._from_column(
empty_geometry_column(Feature_Enum.POLYGON, coord_dtype)
),
),
Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/binpreds/contains.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _pairwise_contains_properly(points, polygons):
# point) pair where the point is contained properly by the polygon. We can
# use this to create a dataframe with only (polygon, point) pairs that
# satisfy the relationship.
pip_result = cudf.Series(result_column, dtype="bool")
pip_result = cudf.Series._from_column(result_column).astype("bool")
trues = pip_result[pip_result].index
true_pairs = cudf.DataFrame(
{
Expand Down
9 changes: 4 additions & 5 deletions python/cuspatial/cuspatial/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
data: Optional[
Union[gpd.GeoSeries, Tuple, T, pd.Series, GeoColumn, list]
],
index: Union[cudf.Index, pd.Index] = None,
index: Union[cudf.Index, pd.Index, None] = None,
dtype=None,
name=None,
nan_as_null=True,
Expand All @@ -86,16 +86,15 @@ def __init__(
if data is None or isinstance(data, (pd.Series, list)):
data = gpGeoSeries(data)
# Create column
if isinstance(data, GeoColumn):
if isinstance(data, GeoSeries):
column = data
elif isinstance(data, GeoSeries):
column = data._column
elif isinstance(data, gpGeoSeries):
from cuspatial.io.geopandas_reader import GeoPandasReader

adapter = GeoPandasReader(data)
pandas_meta = GeoMeta(adapter.get_geopandas_meta())
column = GeoColumn(adapter._get_geotuple(), pandas_meta)
geocolumn = GeoColumn(adapter._get_geotuple(), pandas_meta)
column = type(self)._from_column(geocolumn)
else:
raise TypeError(
f"Incompatible object passed to GeoSeries ctor {type(data)}"
Expand Down
34 changes: 15 additions & 19 deletions python/cuspatial/cuspatial/core/spatial/distance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

import cudf
from cudf import DataFrame, Series
Expand Down Expand Up @@ -217,15 +217,13 @@ def pairwise_point_distance(points1: GeoSeries, points2: GeoSeries):
rhs_point_collection_type,
) = _extract_point_column_and_collection_type(points2)

return Series._from_data(
{
None: cpp_pairwise_point_distance(
lhs_point_collection_type,
rhs_point_collection_type,
lhs_column,
rhs_column,
)
}
return Series._from_column(
cpp_pairwise_point_distance(
lhs_point_collection_type,
rhs_point_collection_type,
lhs_column,
rhs_column,
)
)


Expand Down Expand Up @@ -293,13 +291,11 @@ def pairwise_linestring_distance(
if len(multilinestrings1) == 0:
return cudf.Series(dtype="float64")

return Series._from_data(
{
None: cpp_pairwise_linestring_distance(
multilinestrings1.lines.column(),
multilinestrings2.lines.column(),
)
}
return Series._from_column(
cpp_pairwise_linestring_distance(
multilinestrings1.lines.column(),
multilinestrings2.lines.column(),
)
)


Expand Down Expand Up @@ -583,8 +579,8 @@ def pairwise_linestring_polygon_distance(
linestrings_column = linestrings.lines.column()
polygon_column = polygons.polygons.column()

return Series._from_data(
{None: c_pairwise_line_poly_dist(linestrings_column, polygon_column)}
return Series._from_column(
c_pairwise_line_poly_dist(linestrings_column, polygon_column)
)


Expand Down
28 changes: 18 additions & 10 deletions python/cuspatial/cuspatial/tests/test_from_geopandas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2021, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
import geopandas as gpd
import pandas as pd
from shapely.geometry import (
Expand Down Expand Up @@ -63,7 +63,9 @@ def test_from_geopandas_multipoint():
cudf.Series([1.0, 2.0, 3.0, 4.0], dtype="float64"),
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.mpoints._column.base_children[0]),
cudf.Series._from_column(
cugs._column.mpoints._column.base_children[0]
),
cudf.Series([0, 2], dtype="int32"),
)

Expand All @@ -75,7 +77,7 @@ def test_from_geopandas_linestring():
cugs.lines.xy, cudf.Series([4.0, 3.0, 2.0, 1.0], dtype="float64")
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.lines._column.base_children[0]),
cudf.Series._from_column(cugs._column.lines._column.base_children[0]),
cudf.Series([0, 1], dtype="int32"),
)

Expand All @@ -95,7 +97,7 @@ def test_from_geopandas_multilinestring():
cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], dtype="float64"),
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.lines._column.base_children[0]),
cudf.Series._from_column(cugs._column.lines._column.base_children[0]),
cudf.Series([0, 2], dtype="int32"),
)

Expand All @@ -112,11 +114,13 @@ def test_from_geopandas_polygon():
cudf.Series([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0], dtype="float64"),
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.polygons._column.base_children[0]),
cudf.Series._from_column(
cugs._column.polygons._column.base_children[0]
),
cudf.Series([0, 1], dtype="int32"),
)
cudf.testing.assert_series_equal(
cudf.Series(
cudf.Series._from_column(
cugs._column.polygons._column.base_children[1].base_children[0]
),
cudf.Series([0, 1], dtype="int32"),
Expand Down Expand Up @@ -156,11 +160,13 @@ def test_from_geopandas_polygon_hole():
),
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.polygons._column.base_children[0]),
cudf.Series._from_column(
cugs._column.polygons._column.base_children[0]
),
cudf.Series([0, 1], dtype="int32"),
)
cudf.testing.assert_series_equal(
cudf.Series(
cudf.Series._from_column(
cugs._column.polygons._column.base_children[1].base_children[0]
),
cudf.Series([0, 2], dtype="int32"),
Expand Down Expand Up @@ -204,11 +210,13 @@ def test_from_geopandas_multipolygon():
),
)
cudf.testing.assert_series_equal(
cudf.Series(cugs._column.polygons._column.base_children[0]),
cudf.Series._from_column(
cugs._column.polygons._column.base_children[0]
),
cudf.Series([0, 1], dtype="int32"),
)
cudf.testing.assert_series_equal(
cudf.Series(
cudf.Series._from_column(
cugs._column.polygons._column.base_children[1].base_children[0]
),
cudf.Series([0, 2], dtype="int32"),
Expand Down
Loading