From 50c5f41c0626f1d66044a26aca64ccbdb58043f2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:21:25 -0800 Subject: [PATCH 1/2] Use public cudf APIs where possible --- .../core/binpreds/contains_geometry_processor.py | 8 +++----- python/cuspatial/cuspatial/core/geodataframe.py | 6 ++++-- python/cuspatial/cuspatial/core/geoseries.py | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py b/python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py index 8a1996613..fb8af71af 100644 --- a/python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py +++ b/python/cuspatial/cuspatial/core/binpreds/contains_geometry_processor.py @@ -3,8 +3,6 @@ import cupy as cp import cudf -from cudf.core.dataframe import DataFrame -from cudf.core.series import Series from cuspatial.core._column.geocolumn import GeoColumn from cuspatial.core.binpreds.binpred_interface import ( @@ -117,7 +115,7 @@ def _convert_quadtree_result_from_part_to_polygon_indices( ["polygon_index", "point_index"] ] - def _reindex_allpairs(self, lhs, op_result) -> DataFrame: + def _reindex_allpairs(self, lhs, op_result) -> cudf.DataFrame: """Prepare the allpairs result of a contains_properly call as the first step of postprocessing. An allpairs result is reindexed by replacing the polygon index with the original index of the @@ -154,7 +152,7 @@ def _reindex_allpairs(self, lhs, op_result) -> DataFrame: # Replace the polygon index with the original index allpairs_result["polygon_index"] = allpairs_result[ "polygon_index" - ].replace(Series(lhs.index, index=cp.arange(len(lhs.index)))) + ].replace(cudf.Series(lhs.index, index=cp.arange(len(lhs.index)))) return allpairs_result @@ -202,7 +200,7 @@ def _postprocess_multipoint_rhs( point_indices = preprocessor_result.point_indices allpairs_result = self._reindex_allpairs(lhs, op_result) - if isinstance(allpairs_result, Series): + if isinstance(allpairs_result, cudf.Series): return allpairs_result # Hits is the number of calculated points in each polygon # Expected count is the sizes of the features in the right-hand diff --git a/python/cuspatial/cuspatial/core/geodataframe.py b/python/cuspatial/cuspatial/core/geodataframe.py index 3e58a5d60..f75a3b26f 100644 --- a/python/cuspatial/cuspatial/core/geodataframe.py +++ b/python/cuspatial/cuspatial/core/geodataframe.py @@ -1,17 +1,19 @@ # Copyright (c) 2020-2022, NVIDIA CORPORATION -from typing import Dict, Tuple, TypeVar, Union +from typing import TYPE_CHECKING, Dict, Tuple, TypeVar, Union import pandas as pd from geopandas import GeoDataFrame as gpGeoDataFrame from geopandas.geoseries import is_geometry_type as gp_is_geometry_type import cudf -from cudf.core.copy_types import BooleanMask, GatherMap from cuspatial.core._column.geocolumn import GeoColumn, GeoMeta from cuspatial.core.geoseries import GeoSeries from cuspatial.io.geopandas_reader import GeoPandasReader +if TYPE_CHECKING: + from cudf.core.copy_types import BooleanMask, GatherMap + T = TypeVar("T", bound="GeoDataFrame") diff --git a/python/cuspatial/cuspatial/core/geoseries.py b/python/cuspatial/cuspatial/core/geoseries.py index 64a977ec5..27ad564d8 100644 --- a/python/cuspatial/cuspatial/core/geoseries.py +++ b/python/cuspatial/cuspatial/core/geoseries.py @@ -2,7 +2,7 @@ from functools import cached_property from numbers import Integral -from typing import Optional, Tuple, TypeVar, Union +from typing import TYPE_CHECKING, Optional, Tuple, TypeVar, Union import cupy as cp import geopandas as gpd @@ -23,7 +23,6 @@ import cudf from cudf._typing import ColumnLike from cudf.core.column.column import as_column -from cudf.core.copy_types import GatherMap import cuspatial.io.pygeoarrow as pygeoarrow from cuspatial.core._column.geocolumn import ColumnType, GeoColumn @@ -48,6 +47,9 @@ contains_only_polygons, ) +if TYPE_CHECKING: + from cudf.core.copy_types import GatherMap + T = TypeVar("T", bound="GeoSeries") From 97b9ccac9a4f174d724a837af9bef84449f056f1 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:34:42 -0800 Subject: [PATCH 2/2] Remove typing checking guard --- python/cuspatial/cuspatial/core/geodataframe.py | 6 ++---- python/cuspatial/cuspatial/core/geoseries.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/python/cuspatial/cuspatial/core/geodataframe.py b/python/cuspatial/cuspatial/core/geodataframe.py index f75a3b26f..3e58a5d60 100644 --- a/python/cuspatial/cuspatial/core/geodataframe.py +++ b/python/cuspatial/cuspatial/core/geodataframe.py @@ -1,19 +1,17 @@ # Copyright (c) 2020-2022, NVIDIA CORPORATION -from typing import TYPE_CHECKING, Dict, Tuple, TypeVar, Union +from typing import Dict, Tuple, TypeVar, Union import pandas as pd from geopandas import GeoDataFrame as gpGeoDataFrame from geopandas.geoseries import is_geometry_type as gp_is_geometry_type import cudf +from cudf.core.copy_types import BooleanMask, GatherMap from cuspatial.core._column.geocolumn import GeoColumn, GeoMeta from cuspatial.core.geoseries import GeoSeries from cuspatial.io.geopandas_reader import GeoPandasReader -if TYPE_CHECKING: - from cudf.core.copy_types import BooleanMask, GatherMap - T = TypeVar("T", bound="GeoDataFrame") diff --git a/python/cuspatial/cuspatial/core/geoseries.py b/python/cuspatial/cuspatial/core/geoseries.py index 27ad564d8..64a977ec5 100644 --- a/python/cuspatial/cuspatial/core/geoseries.py +++ b/python/cuspatial/cuspatial/core/geoseries.py @@ -2,7 +2,7 @@ from functools import cached_property from numbers import Integral -from typing import TYPE_CHECKING, Optional, Tuple, TypeVar, Union +from typing import Optional, Tuple, TypeVar, Union import cupy as cp import geopandas as gpd @@ -23,6 +23,7 @@ import cudf from cudf._typing import ColumnLike from cudf.core.column.column import as_column +from cudf.core.copy_types import GatherMap import cuspatial.io.pygeoarrow as pygeoarrow from cuspatial.core._column.geocolumn import ColumnType, GeoColumn @@ -47,9 +48,6 @@ contains_only_polygons, ) -if TYPE_CHECKING: - from cudf.core.copy_types import GatherMap - T = TypeVar("T", bound="GeoSeries")