diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d62b0ba51..093c2ba30 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: types: [text] types_or: [python, cython] - repo: https://github.com/ambv/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black files: python/cuspatial/.* diff --git a/cpp/src/interpolate/cubic_spline.cu b/cpp/src/interpolate/cubic_spline.cu index ae6d632ef..c213496aa 100644 --- a/cpp/src/interpolate/cubic_spline.cu +++ b/cpp/src/interpolate/cubic_spline.cu @@ -407,7 +407,7 @@ std::unique_ptr cubicspline_coefficients(cudf::column_view const& t // pBuffer: get size of thisu by gtsv2_bufferSizeExt cusparseHandle_t handle; - CUDA_TRY(cudaMalloc(&handle, sizeof(cusparseHandle_t))); + CUDF_CUDA_TRY(cudaMalloc(&handle, sizeof(cusparseHandle_t))); CUSPARSE_TRY(cusparseCreate(&handle)); size_t pBufferSize; diff --git a/cpp/src/join/quadtree_point_to_nearest_polyline.cu b/cpp/src/join/quadtree_point_to_nearest_polyline.cu index 41693daf7..ba9924c40 100644 --- a/cpp/src/join/quadtree_point_to_nearest_polyline.cu +++ b/cpp/src/join/quadtree_point_to_nearest_polyline.cu @@ -248,7 +248,8 @@ struct compute_quadtree_point_to_nearest_polyline { rmm::device_uvector distances(point_x.size(), stream); // Fill distances with 0 - CUDA_TRY(cudaMemsetAsync(distances.data(), 0, distances.size() * sizeof(T), stream.value())); + CUDF_CUDA_TRY( + cudaMemsetAsync(distances.data(), 0, distances.size() * sizeof(T), stream.value())); // Reduce the intermediate point/polyline indices to lists of point/polyline index pairs and // distances, selecting the polyline index closest to each point. diff --git a/cpp/src/spatial/hausdorff.cu b/cpp/src/spatial/hausdorff.cu index faebc6b2c..6a696ab9b 100644 --- a/cpp/src/spatial/hausdorff.cu +++ b/cpp/src/spatial/hausdorff.cu @@ -178,7 +178,7 @@ struct hausdorff_functor { space_offsets.begin(), result_view.begin()); - CUDA_TRY(cudaGetLastError()); + CUDF_CUDA_TRY(cudaGetLastError()); return result; } diff --git a/cpp/src/trajectory/trajectory_bounding_boxes.cu b/cpp/src/trajectory/trajectory_bounding_boxes.cu index dc382035d..588d9d1fa 100644 --- a/cpp/src/trajectory/trajectory_bounding_boxes.cu +++ b/cpp/src/trajectory/trajectory_bounding_boxes.cu @@ -97,7 +97,7 @@ struct dispatch_element { }); // check for errors - CHECK_CUDA(stream.value()); + CUDF_CHECK_CUDA(stream.value()); return std::make_unique(std::move(cols)); } diff --git a/cpp/src/trajectory/trajectory_distances_and_speeds.cu b/cpp/src/trajectory/trajectory_distances_and_speeds.cu index c5c3fcf9f..206c05cb5 100644 --- a/cpp/src/trajectory/trajectory_distances_and_speeds.cu +++ b/cpp/src/trajectory/trajectory_distances_and_speeds.cu @@ -166,7 +166,7 @@ struct dispatch_timestamp { }); // check for errors - CHECK_CUDA(stream.value()); + CUDF_CHECK_CUDA(stream.value()); return std::make_unique(std::move(cols)); } diff --git a/python/cuspatial/cuspatial/core/gis.py b/python/cuspatial/cuspatial/core/gis.py index ada531f5e..0e12d8783 100644 --- a/python/cuspatial/cuspatial/core/gis.py +++ b/python/cuspatial/cuspatial/core/gis.py @@ -87,7 +87,9 @@ def directed_hausdorff_distance(xs, ys, space_offsets): return DataFrame() xs, ys = normalize_point_columns(as_column(xs), as_column(ys)) result = cpp_directed_hausdorff_distance( - xs, ys, as_column(space_offsets, dtype="uint32"), + xs, + ys, + as_column(space_offsets, dtype="uint32"), ) result = result.data_array_view result = result.reshape(num_spaces, num_spaces) @@ -95,7 +97,7 @@ def directed_hausdorff_distance(xs, ys, space_offsets): def haversine_distance(p1_lon, p1_lat, p2_lon, p2_lat): - """ Compute the haversine distances between an arbitrary list of lon/lat + """Compute the haversine distances between an arbitrary list of lon/lat pairs Parameters @@ -166,7 +168,7 @@ def point_in_polygon( poly_points_x, poly_points_y, ): - """ Compute from a set of points and a set of polygons which points fall + """Compute from a set of points and a set of polygons which points fall within which polygons. Note that `polygons_(x,y)` must be specified as closed polygons: the first and last coordinate of each polygon must be the same. diff --git a/python/cuspatial/cuspatial/core/indexing.py b/python/cuspatial/cuspatial/core/indexing.py index 115faaede..75b9b30f6 100644 --- a/python/cuspatial/cuspatial/core/indexing.py +++ b/python/cuspatial/cuspatial/core/indexing.py @@ -14,7 +14,7 @@ def quadtree_on_points( xs, ys, x_min, x_max, y_min, y_max, scale, max_depth, min_size ): - """ Construct a quadtree from a set of points for a given area-of-interest + """Construct a quadtree from a set of points for a given area-of-interest bounding box. Parameters diff --git a/python/cuspatial/cuspatial/core/spatial_join.py b/python/cuspatial/cuspatial/core/spatial_join.py index 004abd5bd..a0b6dcddc 100644 --- a/python/cuspatial/cuspatial/core/spatial_join.py +++ b/python/cuspatial/cuspatial/core/spatial_join.py @@ -12,7 +12,7 @@ def join_quadtree_and_bounding_boxes( quadtree, poly_bounding_boxes, x_min, x_max, y_min, y_max, scale, max_depth ): - """ Search a quadtree for polygon or polyline bounding box intersections. + """Search a quadtree for polygon or polyline bounding box intersections. Parameters ---------- @@ -87,7 +87,7 @@ def quadtree_point_in_polygon( poly_points_x, poly_points_y, ): - """ Test whether the specified points are inside any of the specified + """Test whether the specified points are inside any of the specified polygons. Uses the table of (polygon, quadrant) pairs returned by @@ -167,7 +167,7 @@ def quadtree_point_to_nearest_polyline( poly_points_x, poly_points_y, ): - """ Finds the nearest polyline to each point in a quadrant, and computes + """Finds the nearest polyline to each point in a quadrant, and computes the distances between each point and polyline. Uses the table of (polyline, quadrant) pairs returned by diff --git a/python/cuspatial/cuspatial/core/spatial_window.py b/python/cuspatial/cuspatial/core/spatial_window.py index 3967adba5..b4c1788bb 100644 --- a/python/cuspatial/cuspatial/core/spatial_window.py +++ b/python/cuspatial/cuspatial/core/spatial_window.py @@ -8,7 +8,7 @@ def points_in_spatial_window(min_x, max_x, min_y, max_y, xs, ys): - """ Return only the subset of coordinates that fall within a + """Return only the subset of coordinates that fall within a rectangular window. A point `(x, y)` is inside the query window if and only if diff --git a/python/cuspatial/cuspatial/core/trajectory.py b/python/cuspatial/cuspatial/core/trajectory.py index 7cd6df27f..d0d6ee84a 100644 --- a/python/cuspatial/cuspatial/core/trajectory.py +++ b/python/cuspatial/cuspatial/core/trajectory.py @@ -72,7 +72,7 @@ def derive_trajectories(object_ids, xs, ys, timestamps): def trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys): - """ Compute the bounding boxes of sets of trajectories. + """Compute the bounding boxes of sets of trajectories. Parameters ---------- diff --git a/python/cuspatial/cuspatial/geometry/geoarrowbuffers.py b/python/cuspatial/cuspatial/geometry/geoarrowbuffers.py index 6ffea98ab..6071c2d6a 100644 --- a/python/cuspatial/cuspatial/geometry/geoarrowbuffers.py +++ b/python/cuspatial/cuspatial/geometry/geoarrowbuffers.py @@ -550,7 +550,10 @@ def __repr__(self): def copy(self, deep=True): base = super().copy(deep) result = LineArray( - base.xy, base.offsets, self.mlines.copy(deep), base.z, + base.xy, + base.offsets, + self.mlines.copy(deep), + base.z, ) return result diff --git a/python/cuspatial/cuspatial/io/geopandas_adapter.py b/python/cuspatial/cuspatial/io/geopandas_adapter.py index f75eda3f7..dc518bf44 100644 --- a/python/cuspatial/cuspatial/io/geopandas_adapter.py +++ b/python/cuspatial/cuspatial/io/geopandas_adapter.py @@ -114,7 +114,11 @@ def _load_geometry_offsets(self, geoseries: gpGeoSeries) -> dict: ) return offsets - def _read_geometries(self, geoseries: gpGeoSeries, offsets: dict,) -> dict: + def _read_geometries( + self, + geoseries: gpGeoSeries, + offsets: dict, + ) -> dict: """ Creates a set of buffers sized to fit all of the geometries and iteratively populates them with geometry coordinate values. diff --git a/python/cuspatial/cuspatial/tests/conftest.py b/python/cuspatial/cuspatial/tests/conftest.py index 49af5e33f..f9688409c 100644 --- a/python/cuspatial/cuspatial/tests/conftest.py +++ b/python/cuspatial/cuspatial/tests/conftest.py @@ -24,7 +24,9 @@ def gs(): g5 = MultiLineString((((15, 16), (17, 18)), ((19, 20), (21, 22)))) g6 = MultiLineString((((23, 24), (25, 26)), ((27, 28), (29, 30)))) g7 = LineString(((31, 32), (33, 34))) - g8 = Polygon(((35, 36), (37, 38), (39, 40), (41, 42)),) + g8 = Polygon( + ((35, 36), (37, 38), (39, 40), (41, 42)), + ) g9 = MultiPolygon( [ ( diff --git a/python/cuspatial/cuspatial/tests/test_from_geopandas.py b/python/cuspatial/cuspatial/tests/test_from_geopandas.py index 1ec2241a7..352cad9d2 100644 --- a/python/cuspatial/cuspatial/tests/test_from_geopandas.py +++ b/python/cuspatial/cuspatial/tests/test_from_geopandas.py @@ -72,11 +72,17 @@ def test_from_geopandas_linestring(): def test_from_geopandas_multilinestring(): gs = gpd.GeoSeries( - MultiLineString((((1.0, 2.0), (3.0, 4.0)), ((5.0, 6.0), (7.0, 8.0)),)) + MultiLineString( + ( + ((1.0, 2.0), (3.0, 4.0)), + ((5.0, 6.0), (7.0, 8.0)), + ) + ) ) cugs = cuspatial.from_geopandas(gs) cudf.testing.assert_series_equal( - cugs.lines.xy, cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), + cugs.lines.xy, + cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]), ) cudf.testing.assert_series_equal( cugs.lines.offsets, cudf.Series([0, 4, 8]) @@ -85,7 +91,9 @@ def test_from_geopandas_multilinestring(): def test_from_geopandas_polygon(): gs = gpd.GeoSeries( - Polygon(((0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)),) + Polygon( + ((0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)), + ) ) cugs = cuspatial.from_geopandas(gs) cudf.testing.assert_series_equal( diff --git a/python/cuspatial/cuspatial/tests/test_geodataframe.py b/python/cuspatial/cuspatial/tests/test_geodataframe.py index 2a2b0cf5c..c53336a19 100644 --- a/python/cuspatial/cuspatial/tests/test_geodataframe.py +++ b/python/cuspatial/cuspatial/tests/test_geodataframe.py @@ -154,11 +154,17 @@ def test_interleaved_point(gpdf, polys): ) cudf.testing.assert_series_equal( cugs.lines.x, - cudf.Series(np.array([range(11, 34, 2)]).flatten(), dtype="float64",), + cudf.Series( + np.array([range(11, 34, 2)]).flatten(), + dtype="float64", + ), ) cudf.testing.assert_series_equal( cugs.lines.y, - cudf.Series(np.array([range(12, 35, 2)]).flatten(), dtype="float64",), + cudf.Series( + np.array([range(12, 35, 2)]).flatten(), + dtype="float64", + ), ) cudf.testing.assert_series_equal( cugs.polygons.x, cudf.Series(polys[:, 0], dtype="float64") diff --git a/python/cuspatial/cuspatial/tests/test_geoseries.py b/python/cuspatial/cuspatial/tests/test_geoseries.py index e0721c033..8b7c5900d 100644 --- a/python/cuspatial/cuspatial/tests/test_geoseries.py +++ b/python/cuspatial/cuspatial/tests/test_geoseries.py @@ -139,11 +139,17 @@ def test_interleaved_point(gs, polys): ) cudf.testing.assert_series_equal( cugs.lines.x, - cudf.Series(np.array([range(11, 34, 2)]).flatten(), dtype="float64",), + cudf.Series( + np.array([range(11, 34, 2)]).flatten(), + dtype="float64", + ), ) cudf.testing.assert_series_equal( cugs.lines.y, - cudf.Series(np.array([range(12, 35, 2)]).flatten(), dtype="float64",), + cudf.Series( + np.array([range(12, 35, 2)]).flatten(), + dtype="float64", + ), ) cudf.testing.assert_series_equal( cugs.polygons.x, cudf.Series(polys[:, 0], dtype="float64") diff --git a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py index c32a10b6f..0d6815181 100644 --- a/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py +++ b/python/cuspatial/cuspatial/tests/test_hausdorff_distance.py @@ -36,14 +36,18 @@ def test_zeros(): def test_empty_x(): with pytest.raises(RuntimeError): cuspatial.directed_hausdorff_distance( - [], [0.0], [0], + [], + [0.0], + [0], ) def test_empty_y(): with pytest.raises(RuntimeError): cuspatial.directed_hausdorff_distance( - [0.0], [], [0], + [0.0], + [], + [0], ) diff --git a/python/cuspatial/cuspatial/tests/test_haversine_distance.py b/python/cuspatial/cuspatial/tests/test_haversine_distance.py index 51318e5c9..312f87c6f 100644 --- a/python/cuspatial/cuspatial/tests/test_haversine_distance.py +++ b/python/cuspatial/cuspatial/tests/test_haversine_distance.py @@ -15,7 +15,7 @@ def test_zeros(): cudf.Series([0.0]), cudf.Series([0.0]), ) - assert distance[0] == 0 + assert distance.element_indexing(0) == 0 def test_empty_x1(): diff --git a/python/cuspatial/cuspatial/tests/test_spatial_join.py b/python/cuspatial/cuspatial/tests/test_spatial_join.py index e8fe9603f..976a55273 100644 --- a/python/cuspatial/cuspatial/tests/test_spatial_join.py +++ b/python/cuspatial/cuspatial/tests/test_spatial_join.py @@ -226,7 +226,11 @@ def test_empty(dtype): ) # empty should not throw intersections = cuspatial.join_quadtree_and_bounding_boxes( - quadtree, poly_bboxes, *bbox_1, 1, 1, # bbox # scale # max_depth + quadtree, + poly_bboxes, + *bbox_1, + 1, + 1, # bbox # scale # max_depth ) cudf.testing.assert_frame_equal( intersections, @@ -264,10 +268,20 @@ def test_polygon_join_small(dtype): min_size, ) poly_bboxes = cuspatial.polygon_bounding_boxes( - small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, + small_poly_offsets, + small_ring_offsets, + poly_points_x, + poly_points_y, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( - quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, + quadtree, + poly_bboxes, + x_min, + x_max, + y_min, + y_max, + scale, + max_depth, ) cudf.testing.assert_frame_equal( intersections, @@ -310,10 +324,20 @@ def test_polyline_join_small(dtype): min_size, ) poly_bboxes = cuspatial.polyline_bounding_boxes( - small_ring_offsets, poly_points_x, poly_points_y, expansion_radius, + small_ring_offsets, + poly_points_x, + poly_points_y, + expansion_radius, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( - quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, + quadtree, + poly_bboxes, + x_min, + x_max, + y_min, + y_max, + scale, + max_depth, ) cudf.testing.assert_frame_equal( intersections, @@ -401,10 +425,20 @@ def test_quadtree_point_in_polygon_small(dtype): min_size, ) poly_bboxes = cuspatial.polygon_bounding_boxes( - small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y, + small_poly_offsets, + small_ring_offsets, + poly_points_x, + poly_points_y, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( - quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, + quadtree, + poly_bboxes, + x_min, + x_max, + y_min, + y_max, + scale, + max_depth, ) polygons_and_points = cuspatial.quadtree_point_in_polygon( intersections, @@ -481,10 +515,20 @@ def run_test_quadtree_point_to_nearest_polyline_small( min_size, ) poly_bboxes = cuspatial.polyline_bounding_boxes( - small_ring_offsets, poly_points_x, poly_points_y, expansion_radius, + small_ring_offsets, + poly_points_x, + poly_points_y, + expansion_radius, ) intersections = cuspatial.join_quadtree_and_bounding_boxes( - quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth, + quadtree, + poly_bboxes, + x_min, + x_max, + y_min, + y_max, + scale, + max_depth, ) p2np_result = cuspatial.quadtree_point_to_nearest_polyline( intersections, diff --git a/python/cuspatial/cuspatial/tests/test_trajectory.py b/python/cuspatial/cuspatial/tests/test_trajectory.py index 9bec09661..f07717c87 100644 --- a/python/cuspatial/cuspatial/tests/test_trajectory.py +++ b/python/cuspatial/cuspatial/tests/test_trajectory.py @@ -74,7 +74,10 @@ def test_trajectory_bounding_boxes_ones(): def test_trajectory_bounding_boxes_zero_to_one(): result = cuspatial.trajectory_bounding_boxes( - 1, cudf.Series([0, 0]), cudf.Series([0, 0]), cudf.Series([0, 1]), + 1, + cudf.Series([0, 0]), + cudf.Series([0, 0]), + cudf.Series([0, 1]), ) cudf.testing.assert_frame_equal( result, @@ -86,7 +89,10 @@ def test_trajectory_bounding_boxes_zero_to_one(): def test_trajectory_bounding_boxes_zero_to_one_xy(): result = cuspatial.trajectory_bounding_boxes( - 1, cudf.Series([0, 0]), cudf.Series([0, 1]), cudf.Series([0, 1]), + 1, + cudf.Series([0, 0]), + cudf.Series([0, 1]), + cudf.Series([0, 1]), ) cudf.testing.assert_frame_equal( result, @@ -262,7 +268,10 @@ def test_derive_trajectories_many(): def test_trajectory_distances_and_speeds_zeros(): objects, traj_offsets = cuspatial.derive_trajectories( - [0], [0], [0], [0], # object_id # xs # ys # timestamp + [0], + [0], + [0], + [0], # object_id # xs # ys # timestamp ) result = cuspatial.trajectory_distances_and_speeds( len(traj_offsets), @@ -281,7 +290,10 @@ def test_trajectory_distances_and_speeds_zeros(): def test_trajectory_distances_and_speeds_ones(): objects, traj_offsets = cuspatial.derive_trajectories( - [1], [1], [1], [1], # object_id # xs # ys # timestamp + [1], + [1], + [1], + [1], # object_id # xs # ys # timestamp ) result = cuspatial.trajectory_distances_and_speeds( len(traj_offsets), diff --git a/python/cuspatial/cuspatial/utils/gis_utils.py b/python/cuspatial/cuspatial/utils/gis_utils.py index 517b909e2..65f8af0e3 100644 --- a/python/cuspatial/cuspatial/utils/gis_utils.py +++ b/python/cuspatial/cuspatial/utils/gis_utils.py @@ -7,8 +7,7 @@ @cuda.jit def binarize(in_col, out, width): - """Convert any positive integer to a binary array. - """ + """Convert any positive integer to a binary array.""" i = cuda.grid(1) if i < in_col.size: n = in_col[i]