Skip to content

Commit

Permalink
Fix all unexecutable code examples I can find. (#693)
Browse files Browse the repository at this point in the history
A few old issues that are tasked for `22.10` involve fixing documentation that is incorrect. I worked through the existing nightly docs and executed all of the code samples, fixing and improving anything that had incorrect outputs or inputs.

closes #460
closes #63

Authors:
  - H. Thomson Comer (https://github.com/thomcom)

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

URL: #693
  • Loading branch information
thomcom authored Sep 27, 2022
1 parent b68d2ca commit 5d84d9e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/source/api_docs/geopandas_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ GeoPandas Compatibility

cuSpatial supports any geometry format supported by `GeoPandas`. Load geometry information from a `GeoPandas.GeoSeries` or `GeoPandas.GeoDataFrame`.

>>> gpdf = geopandas.read_file('arbitrary.txt')
cugpdf = cuspatial.from_geopandas(gpdf)
>>> host_dataframe = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
cugpdf = cuspatial.from_geopandas(host_dataframe)

or

Expand Down
3 changes: 2 additions & 1 deletion python/cuspatial/cuspatial/core/geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def _split_out_geometry_columns(self) -> Tuple:
"""
columns_mask = pd.Series(self.columns)
geocolumn_mask = pd.Series(
[isinstance(self[col], GeoSeries) for col in self.columns]
[isinstance(self[col], GeoSeries) for col in self.columns],
dtype="bool",
)
geo_columns = self[columns_mask[geocolumn_mask]]
# Send the rest of the columns to `cudf` to slice.
Expand Down
67 changes: 63 additions & 4 deletions python/cuspatial/cuspatial/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class GeoSeries(cudf.Series):
stored in the `GeoArrowBuffers` object, accessible with the `points`,
`multipoints`, `lines`, and `polygons` accessors.
>>> cuseries.points
xy:
>>> from shapely.geometry import Point
import geopandas
import cuspatial
cuseries = cuspatial.GeoSeries(geopandas.GeoSeries(Point(-1, 0)))
cuseries.points.xy
0 -1.0
1 0.0
dtype: float64
Expand Down Expand Up @@ -422,8 +425,64 @@ def to_shapely(self):
return results

def to_arrow(self):
# Arrow can't view an empty list, so we need to prep the buffers
# here.
"""
Convert to a GeoArrow Array.
Returns
-------
result: GeoArrow Union containing GeoArrow Arrays
Examples
--------
>>> from shapely.geometry import MultiLineString, LineString
>>> cugpdf = cuspatial.from_geopandas(geopandas.GeoSeries(
MultiLineString(
[
[(1, 0), (0, 1)],
[(0, 0), (1, 1)]
]
)))
>>> cugpdf.to_arrow()
<pyarrow.lib.UnionArray object at 0x7f7061c0e0a0>
-- is_valid: all not null
-- type_ids: [
2
]
-- value_offsets: [
0
]
-- child 0 type: list<item: null>
[]
-- child 1 type: list<item: null>
[]
-- child 2 type: list<item: list<item: list<item: double>>>
[
[
[
[
1,
0
],
[
0,
1
]
],
[
[
0,
0
],
[
1,
1
]
]
]
]
-- child 3 type: list<item: null>
[]
"""
points = self._column.points
mpoints = self._column.mpoints
lines = self._column.lines
Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/spatial/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def directed_hausdorff_distance(xs, ys, space_offsets):
>>> result = cuspatial.directed_hausdorff_distance(
[0, 1, 0, 0], # xs
[0, 0, 1, 2], # ys
[0, 2, 4], # space_offsets
[0, 2], # space_offsets
)
>>> print(result)
0 1
Expand Down
22 changes: 11 additions & 11 deletions python/cuspatial/cuspatial/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ def derive_trajectories(object_ids, xs, ys, timestamps):
Compute sorted objects and discovered trajectories
>>> objects, traj_offsets = cuspatial.derive_trajectories(
[0, 1, 2, 3], # object_id
[0, 1, 0, 1], # object_id
[0, 0, 1, 1], # x
[0, 0, 1, 1], # y
[0, 10, 0, 10] # timestamp
[0, 10000, 0, 10000] # timestamp
)
>>> print(traj_offsets)
0 0
1 2
>>> print(objects)
object_id x y timestamp
0 0 1 0 0
1 0 0 0 10
2 1 3 1 0
3 1 2 1 10
object_id x y timestamp
0 0 0.0 0.0 1970-01-01 00:00:00
1 0 1.0 1.0 1970-01-01 00:00:10
2 1 0.0 0.0 1970-01-01 00:00:00
3 1 1.0 1.0 1970-01-01 00:00:10
"""

object_ids = as_column(object_ids, dtype=np.int32)
Expand Down Expand Up @@ -103,7 +103,7 @@ def trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys):
--------
Compute the minimum bounding boxes of derived trajectories
>>> objects, traj_offsets = trajectory.derive_trajectories(
>>> objects, traj_offsets = cuspatial.derive_trajectories(
[0, 0, 1, 1], # object_id
[0, 1, 2, 3], # x
[0, 0, 1, 1], # y
Expand Down Expand Up @@ -168,10 +168,10 @@ def trajectory_distances_and_speeds(
objects['timestamp']
)
>>> print(dists_and_speeds)
distance speed
distance speed
trajectory_id
0 1000.0 100000.000000
1 1000.0 111111.109375
0 1414.213562 141.421356
1 1414.213562 141.421356
"""

object_ids = as_column(object_ids, dtype=np.int32)
Expand Down

0 comments on commit 5d84d9e

Please sign in to comment.