Skip to content

Commit

Permalink
Use ListColumn instead of build_list_column (#1327)
Browse files Browse the repository at this point in the history
This API is planned for removal in cudf: rapidsai/cudf#14786

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Mark Harris (https://github.com/harrism)
  - Michael Wang (https://github.com/isVoid)

URL: #1327
  • Loading branch information
mroeschke authored Feb 1, 2024
1 parent 534b267 commit 6113f5f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
45 changes: 25 additions & 20 deletions python/cuspatial/cuspatial/core/_column/geocolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pyarrow as pa

import cudf
from cudf.core.column import ColumnBase, as_column, build_list_column
from cudf.core.column import ColumnBase, ListColumn, as_column

from cuspatial.core._column.geometa import Feature_Enum, GeoMeta
from cuspatial.utils.column_utils import empty_geometry_column
Expand Down Expand Up @@ -178,10 +178,11 @@ def _from_multipoints_xy(
if not multipoints_xy.dtype.kind == "f":
raise ValueError("Coordinates must be floating point numbers.")

multipoint_col = build_list_column(
indices=geometry_offsets,
elements=_xy_as_variable_sized_list(multipoints_xy),
multi_elements = _xy_as_variable_sized_list(multipoints_xy)
multipoint_col = ListColumn(
dtype=cudf.ListDtype(multi_elements.dtype),
size=len(geometry_offsets) - 1,
children=(geometry_offsets, multi_elements),
)
num_multipoints = len(multipoint_col)

Expand Down Expand Up @@ -232,15 +233,16 @@ def _from_linestrings_xy(
if not linestrings_xy.dtype.kind == "f":
raise ValueError("Coordinates must be floating point numbers.")

parts_col = build_list_column(
indices=part_offsets,
elements=_xy_as_variable_sized_list(linestrings_xy),
parts_elements = _xy_as_variable_sized_list(linestrings_xy)
parts_col = ListColumn(
dtype=cudf.ListDtype(parts_elements.dtype),
size=len(part_offsets) - 1,
children=(part_offsets, parts_elements),
)
linestrings_col = build_list_column(
indices=geometry_offsets,
elements=parts_col,
linestrings_col = ListColumn(
dtype=cudf.ListDtype(parts_col.dtype),
size=len(geometry_offsets) - 1,
children=(geometry_offsets, parts_col),
)
num_linestrings = len(linestrings_col)

Expand Down Expand Up @@ -292,20 +294,21 @@ def _from_polygons_xy(
if not polygons_xy.dtype.kind == "f":
raise ValueError("Coordinates must be floating point numbers.")

rings_col = build_list_column(
indices=ring_offsets,
elements=_xy_as_variable_sized_list(polygons_xy),
ring_elements = _xy_as_variable_sized_list(polygons_xy)
rings_col = ListColumn(
dtype=cudf.ListDtype(ring_elements.dtype),
size=len(ring_offsets) - 1,
children=(ring_offsets, ring_elements),
)
parts_col = build_list_column(
indices=part_offsets,
elements=rings_col,
parts_col = ListColumn(
dtype=cudf.ListDtype(rings_col.dtype),
size=len(part_offsets) - 1,
children=(part_offsets, rings_col),
)
polygons_col = build_list_column(
indices=geometry_offsets,
elements=parts_col,
polygons_col = ListColumn(
dtype=cudf.ListDtype(parts_col.dtype),
size=len(geometry_offsets) - 1,
children=(geometry_offsets, parts_col),
)
num_polygons = len(polygons_col)

Expand Down Expand Up @@ -365,4 +368,6 @@ def _xy_as_variable_sized_list(xy: ColumnBase):

num_points = len(xy) // 2
indices = as_column(range(0, num_points * 2 + 1, 2), dtype="int32")
return build_list_column(indices=indices, elements=xy, size=num_points)
return ListColumn(
dtype=cudf.ListDtype(xy.dtype), size=num_points, children=(indices, xy)
)
19 changes: 11 additions & 8 deletions python/cuspatial/cuspatial/core/binops/intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import TYPE_CHECKING

import cudf
from cudf.core.column import as_column, build_list_column
from cudf.core.column import ListColumn, as_column

from cuspatial._lib.intersection import (
pairwise_linestring_intersection as c_pairwise_linestring_intersection,
Expand Down Expand Up @@ -84,18 +84,21 @@ def pairwise_linestring_intersection(

# Organize the look back ids into list column
(lhs_linestring_id, lhs_segment_id, rhs_linestring_id, rhs_segment_id,) = [
build_list_column(
indices=geometry_collection_offset,
elements=id_,
ListColumn(
dtype=cudf.ListDtype(id_.dtype),
size=len(geometry_collection_offset) - 1,
children=(geometry_collection_offset, id_),
)
for id_ in look_back_ids
]

linestring_column = build_list_column(
indices=as_column(range(0, len(segments) + 1), dtype="int32"),
elements=segments,
size=len(segments),
linestring_column = ListColumn(
dtype=cudf.ListDtype(segments.dtype),
size=segments.size,
children=(
as_column(range(0, len(segments) + 1), dtype="int32"),
segments,
),
)

coord_dtype = points.dtype.leaf_type
Expand Down

0 comments on commit 6113f5f

Please sign in to comment.