Skip to content

Commit

Permalink
Update cudf table apis (#437)
Browse files Browse the repository at this point in the history
rapidsai/cudf#8687 changes the internals of cuDF and removes the means by which libcudf table objects are converted to cuDF Frames. This PR should be merged after that one to match those APIs. I have verified locally that this PR's Cython code compiles and runs against that branch of cuDF.

Authors:
  - Vyas Ramasubramani (https://github.com/vyasr)

Approvers:
  - Paul Taylor (https://github.com/trxcllnt)

URL: #437
  • Loading branch information
vyasr authored Aug 4, 2021
1 parent d97f8a4 commit 960894f
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 45 deletions.
4 changes: 2 additions & 2 deletions python/cuspatial/cuspatial/_lib/interpolate.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ from libcpp.utility cimport move

from cudf._lib.column cimport Column, column
from cudf._lib.table cimport Table, table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.interpolate cimport (
cubicspline_coefficients as cpp_cubicspline_coefficients,
Expand Down Expand Up @@ -32,8 +33,7 @@ cpdef cubicspline_coefficients(
prefixes_v
)
)
result = Table.from_unique_ptr(move(c_result), ["d3", "d2", "d1", "d0"])
return result
return data_from_unique_ptr(move(c_result), ["d3", "d2", "d1", "d0"])

cpdef cubicspline_interpolate(
Column points,
Expand Down
4 changes: 2 additions & 2 deletions python/cuspatial/cuspatial/_lib/polygon_bounding_boxes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.types cimport size_type
from cudf._lib.table cimport Table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.polygon_bounding_box cimport (
polygon_bounding_boxes as cpp_polygon_bounding_boxes,
Expand All @@ -28,7 +28,7 @@ cpdef polygon_bounding_boxes(Column poly_offsets,
result = move(cpp_polygon_bounding_boxes(
c_poly_offsets, c_ring_offsets, c_x, c_y
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["x_min", "y_min", "x_max", "y_max"]
)
4 changes: 2 additions & 2 deletions python/cuspatial/cuspatial/_lib/polyline_bounding_boxes.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.types cimport size_type
from cudf._lib.table cimport Table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.polyline_bounding_box cimport (
polyline_bounding_boxes as cpp_polyline_bounding_boxes,
Expand All @@ -27,7 +27,7 @@ cpdef polyline_bounding_boxes(Column poly_offsets,
result = move(cpp_polyline_bounding_boxes(
c_poly_offsets, c_x, c_y, R
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["x_min", "y_min", "x_max", "y_max"]
)
4 changes: 2 additions & 2 deletions python/cuspatial/cuspatial/_lib/quadtree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.types cimport size_type
from cudf._lib.table cimport Table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.quadtree cimport (
quadtree_on_points as cpp_quadtree_on_points,
Expand All @@ -32,7 +32,7 @@ cpdef quadtree_on_points(Column x, Column y,
))
return (
Column.from_unique_ptr(move(result.first)),
Table.from_unique_ptr(
data_from_unique_ptr(
move(result.second),
column_names=["key", "level", "is_quad", "length", "offset"]
)
Expand Down
7 changes: 4 additions & 3 deletions python/cuspatial/cuspatial/_lib/spatial_join.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from libcpp.utility cimport move
from cudf._lib.column cimport Column, column, column_view
from cudf._lib.cpp.types cimport size_type
from cudf._lib.table cimport Table, table, table_view
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.spatial_join cimport (
join_quadtree_and_bounding_boxes as cpp_join_quadtree_and_bounding_boxes,
Expand All @@ -33,7 +34,7 @@ cpdef join_quadtree_and_bounding_boxes(Table quadtree,
c_poly_bounding_boxes,
x_min, x_max, y_min, y_max, scale, max_depth
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["poly_offset", "quad_offset"]
)
Expand Down Expand Up @@ -70,7 +71,7 @@ cpdef quadtree_point_in_polygon(Table poly_quad_pairs,
c_poly_points_x,
c_poly_points_y
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["polygon_index", "point_index"]
)
Expand Down Expand Up @@ -104,7 +105,7 @@ cpdef quadtree_point_to_nearest_polyline(Table poly_quad_pairs,
c_poly_points_x,
c_poly_points_y
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["point_index", "polyline_index", "distance"]
)
6 changes: 3 additions & 3 deletions python/cuspatial/cuspatial/_lib/spatial_window.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

from cudf._lib.column cimport Column, column, column_view
from cudf._lib.table cimport Table, table
from cudf._lib.table cimport table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.spatial_window cimport (
points_in_spatial_window as cpp_points_in_spatial_window,
Expand Down Expand Up @@ -36,5 +37,4 @@ cpdef points_in_spatial_window(
)
)

table = Table.from_unique_ptr(move(c_result), column_names=["x", "y"])
return table
return data_from_unique_ptr(move(c_result), column_names=["x", "y"])
11 changes: 5 additions & 6 deletions python/cuspatial/cuspatial/_lib/trajectory.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.column.column_view cimport column_view
from cudf._lib.cpp.table.table cimport table
from cudf._lib.cpp.types cimport size_type
from cudf._lib.table cimport Table
from cudf._lib.utils cimport data_from_unique_ptr

from cuspatial._lib.cpp.trajectory cimport (
derive_trajectories as cpp_derive_trajectories,
Expand All @@ -27,11 +27,10 @@ cpdef derive_trajectories(Column object_id, Column x,
cdef pair[unique_ptr[table], unique_ptr[column]] result
with nogil:
result = move(cpp_derive_trajectories(c_id, c_x, c_y, c_ts))
table = Table.from_unique_ptr(
return data_from_unique_ptr(
move(result.first),
column_names=["object_id", "x", "y", "timestamp"]
)
return table, Column.from_unique_ptr(move(result.second))
), Column.from_unique_ptr(move(result.second))


cpdef trajectory_bounding_boxes(size_type num_trajectories,
Expand All @@ -44,7 +43,7 @@ cpdef trajectory_bounding_boxes(size_type num_trajectories,
result = move(cpp_trajectory_bounding_boxes(
num_trajectories, c_id, c_x, c_y
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["x_min", "y_min", "x_max", "y_max"]
)
Expand All @@ -62,7 +61,7 @@ cpdef trajectory_distances_and_speeds(size_type num_trajectories,
result = move(cpp_trajectory_distances_and_speeds(
num_trajectories, c_id, c_x, c_y, c_ts
))
return Table.from_unique_ptr(
return data_from_unique_ptr(
move(result),
column_names=["distance", "speed"]
)
8 changes: 4 additions & 4 deletions python/cuspatial/cuspatial/core/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ def polygon_bounding_boxes(poly_offsets, ring_offsets, xs, ys):
poly_offsets = as_column(poly_offsets, dtype="int32")
ring_offsets = as_column(ring_offsets, dtype="int32")
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
return DataFrame._from_table(
cpp_polygon_bounding_boxes(poly_offsets, ring_offsets, xs, ys)
return DataFrame._from_data(
*cpp_polygon_bounding_boxes(poly_offsets, ring_offsets, xs, ys)
)


Expand Down Expand Up @@ -322,6 +322,6 @@ def polyline_bounding_boxes(poly_offsets, xs, ys, expansion_radius):
"""
poly_offsets = as_column(poly_offsets, dtype="int32")
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
return DataFrame._from_table(
cpp_polyline_bounding_boxes(poly_offsets, xs, ys, expansion_radius)
return DataFrame._from_data(
*cpp_polyline_bounding_boxes(poly_offsets, xs, ys, expansion_radius)
)
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ def quadtree_on_points(
max_depth,
min_size,
)
return Series(key_to_point), DataFrame._from_table(quadtree)
return Series(key_to_point), DataFrame._from_data(*quadtree)
6 changes: 3 additions & 3 deletions python/cuspatial/cuspatial/core/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def _cubic_spline_coefficients(x, y, ids, prefix_sums):
y_c = y._column
ids_c = ids._column
prefix_c = prefix_sums._column
result_table = cubicspline_coefficients(x_c, y_c, ids_c, prefix_c)
result = DataFrame._from_table(result_table)
return result
return DataFrame._from_data(
*cubicspline_coefficients(x_c, y_c, ids_c, prefix_c)
)


def _cubic_spline_fit(points, points_ids, prefixes, original_t, c):
Expand Down
12 changes: 6 additions & 6 deletions python/cuspatial/cuspatial/core/spatial_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def join_quadtree_and_bounding_boxes(
+ "scale {}. Clamping to minimum scale".format(min_scale)
)

return DataFrame._from_table(
spatial_join.join_quadtree_and_bounding_boxes(
return DataFrame._from_data(
*spatial_join.join_quadtree_and_bounding_boxes(
quadtree,
poly_bounding_boxes,
x_min,
Expand Down Expand Up @@ -142,8 +142,8 @@ def quadtree_point_in_polygon(
as_column(poly_points_x),
as_column(poly_points_y),
)
return DataFrame._from_table(
spatial_join.quadtree_point_in_polygon(
return DataFrame._from_data(
*spatial_join.quadtree_point_in_polygon(
poly_quad_pairs,
quadtree,
as_column(point_indices, dtype="uint32"),
Expand Down Expand Up @@ -218,8 +218,8 @@ def quadtree_point_to_nearest_polyline(
as_column(poly_points_x),
as_column(poly_points_y),
)
return DataFrame._from_table(
spatial_join.quadtree_point_to_nearest_polyline(
return DataFrame._from_data(
*spatial_join.quadtree_point_to_nearest_polyline(
poly_quad_pairs,
quadtree,
as_column(point_indices, dtype="uint32"),
Expand Down
7 changes: 4 additions & 3 deletions python/cuspatial/cuspatial/core/spatial_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def points_in_spatial_window(min_x, max_x, min_y, max_y, xs, ys):
* Swaps ``min_y`` and ``max_y`` if ``min_y > max_y``
"""
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
result = spatial_window.points_in_spatial_window(
min_x, max_x, min_y, max_y, xs, ys
return DataFrame._from_data(
*spatial_window.points_in_spatial_window(
min_x, max_x, min_y, max_y, xs, ys
)
)
return DataFrame._from_table(result)
10 changes: 5 additions & 5 deletions python/cuspatial/cuspatial/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def derive_trajectories(object_ids, xs, ys, timestamps):
objects, traj_offsets = cpp_derive_trajectories(
object_ids, xs, ys, timestamps
)
return DataFrame._from_table(objects), Series(data=traj_offsets)
return DataFrame._from_data(*objects), Series(data=traj_offsets)


def trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys):
Expand Down Expand Up @@ -123,8 +123,8 @@ def trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys):

object_ids = as_column(object_ids, dtype=np.int32)
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
return DataFrame._from_table(
cpp_trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys)
return DataFrame._from_data(
*cpp_trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys)
)


Expand Down Expand Up @@ -177,8 +177,8 @@ def trajectory_distances_and_speeds(
object_ids = as_column(object_ids, dtype=np.int32)
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
timestamps = normalize_timestamp_column(as_column(timestamps))
df = DataFrame._from_table(
cpp_trajectory_distances_and_speeds(
df = DataFrame._from_data(
*cpp_trajectory_distances_and_speeds(
num_trajectories, object_ids, xs, ys, timestamps
)
)
Expand Down
4 changes: 1 addition & 3 deletions python/cuspatial/cuspatial/geometry/geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ def _copy_type_metadata(self, other, include_index: bool = True):
) and not isinstance(
self._index, cudf.core.index.CategoricalIndex
):
self._index = cudf.core.index.Index._from_table(
self._index
)
self._index = cudf.Index(self._index._column)

return self

Expand Down

0 comments on commit 960894f

Please sign in to comment.