Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-657] pre-commit add Python black hook; format Python with black #1593

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions .github/linters/ruff.toml

This file was deleted.

9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ repos:
hooks:
- id: identity
- id: check-hooks-apply
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
hooks:
- id: black-jupyter
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
Expand All @@ -18,11 +22,6 @@ repos:
description: Check spelling with codespell
args: [--ignore-words=.github/linters/codespell.txt]
exclude: ^docs/image|^spark/common/src/test/resources|^docs/usecases|^tools/maven/scalafmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.5
hooks:
- id: ruff
args: [--config=.github/linters/ruff.toml, --fix]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down
88 changes: 57 additions & 31 deletions docs/usecases/ApacheSedonaCore.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"from shapely.geometry import Polygon\n",
"\n",
"from sedona.spark import *\n",
"from sedona.core.geom.envelope import Envelope\n"
"from sedona.core.geom.envelope import Envelope"
]
},
{
Expand Down Expand Up @@ -182,12 +182,16 @@
}
],
"source": [
"config = SedonaContext.builder() .\\\n",
" config('spark.jars.packages',\n",
" 'org.apache.sedona:sedona-spark-3.4_2.12:1.6.0,'\n",
" 'org.datasyslab:geotools-wrapper:1.6.0-28.2,'\n",
" 'uk.co.gresearch.spark:spark-extension_2.12:2.11.0-3.4'). \\\n",
" getOrCreate()\n",
"config = (\n",
" SedonaContext.builder()\n",
" .config(\n",
" \"spark.jars.packages\",\n",
" \"org.apache.sedona:sedona-spark-3.4_2.12:1.6.0,\"\n",
" \"org.datasyslab:geotools-wrapper:1.6.0-28.2,\"\n",
" \"uk.co.gresearch.spark:spark-extension_2.12:2.11.0-3.4\",\n",
" )\n",
" .getOrCreate()\n",
")\n",
"\n",
"sedona = SedonaContext.create(config)"
]
Expand Down Expand Up @@ -560,7 +564,9 @@
"metadata": {},
"outputs": [],
"source": [
"point_rdd_to_geo = point_rdd.rawSpatialRDD.map(lambda x: [x.geom, *x.getUserData().split(\"\\t\")])"
"point_rdd_to_geo = point_rdd.rawSpatialRDD.map(\n",
" lambda x: [x.geom, *x.getUserData().split(\"\\t\")]\n",
")"
]
},
{
Expand All @@ -578,7 +584,9 @@
],
"source": [
"point_gdf = gpd.GeoDataFrame(\n",
" point_rdd_to_geo.collect(), columns=[\"geom\", \"attr1\", \"attr2\", \"attr3\"], geometry=\"geom\"\n",
" point_rdd_to_geo.collect(),\n",
" columns=[\"geom\", \"attr1\", \"attr2\", \"attr3\"],\n",
" geometry=\"geom\",\n",
")"
]
},
Expand Down Expand Up @@ -696,9 +704,9 @@
"metadata": {},
"outputs": [],
"source": [
"spatial_df = Adapter.\\\n",
" toDf(point_rdd, [\"attr1\", \"attr2\", \"attr3\"], sedona).\\\n",
" createOrReplaceTempView(\"spatial_df\")\n",
"spatial_df = Adapter.toDf(\n",
" point_rdd, [\"attr1\", \"attr2\", \"attr3\"], sedona\n",
").createOrReplaceTempView(\"spatial_df\")\n",
"\n",
"spatial_gdf = sedona.sql(\"Select attr1, attr2, attr3, geometry as geom from spatial_df\")"
]
Expand Down Expand Up @@ -995,10 +1003,16 @@
"metadata": {},
"outputs": [],
"source": [
"rectangle_rdd = RectangleRDD(sc, \"data/zcta510-small.csv\", FileDataSplitter.CSV, True, 11)\n",
"rectangle_rdd = RectangleRDD(\n",
" sc, \"data/zcta510-small.csv\", FileDataSplitter.CSV, True, 11\n",
")\n",
"point_rdd = PointRDD(sc, \"data/arealm-small.csv\", 1, FileDataSplitter.CSV, False, 11)\n",
"polygon_rdd = PolygonRDD(sc, \"data/primaryroads-polygon.csv\", FileDataSplitter.CSV, True, 11)\n",
"linestring_rdd = LineStringRDD(sc, \"data/primaryroads-linestring.csv\", FileDataSplitter.CSV, True)"
"polygon_rdd = PolygonRDD(\n",
" sc, \"data/primaryroads-polygon.csv\", FileDataSplitter.CSV, True, 11\n",
")\n",
"linestring_rdd = LineStringRDD(\n",
" sc, \"data/primaryroads-linestring.csv\", FileDataSplitter.CSV, True\n",
")"
]
},
{
Expand Down Expand Up @@ -1298,7 +1312,7 @@
"schema = StructType(\n",
" [\n",
" StructField(\"geom_left\", GeometryType(), False),\n",
" StructField(\"geom_right\", GeometryType(), False)\n",
" StructField(\"geom_right\", GeometryType(), False),\n",
" ]\n",
")"
]
Expand Down Expand Up @@ -1497,7 +1511,9 @@
"metadata": {},
"outputs": [],
"source": [
"spatial_join_result_non_flat = JoinQuery.SpatialJoinQuery(point_rdd, rectangle_rdd, False, True)"
"spatial_join_result_non_flat = JoinQuery.SpatialJoinQuery(\n",
" point_rdd, rectangle_rdd, False, True\n",
")"
]
},
{
Expand All @@ -1507,7 +1523,9 @@
"outputs": [],
"source": [
"# number of point for each polygon\n",
"number_of_points = spatial_join_result_non_flat.map(lambda x: [x[0].geom, x[1].__len__()])"
"number_of_points = spatial_join_result_non_flat.map(\n",
" lambda x: [x[0].geom, x[1].__len__()]\n",
")"
]
},
{
Expand All @@ -1516,10 +1534,12 @@
"metadata": {},
"outputs": [],
"source": [
"schema = StructType([\n",
" StructField(\"geometry\", GeometryType(), False),\n",
" StructField(\"number_of_points\", LongType(), False)\n",
"])"
"schema = StructType(\n",
" [\n",
" StructField(\"geometry\", GeometryType(), False),\n",
" StructField(\"number_of_points\", LongType(), False),\n",
" ]\n",
")"
]
},
{
Expand Down Expand Up @@ -1650,10 +1670,14 @@
],
"source": [
"polygon = Polygon(\n",
" [(-84.237756, 33.904859), (-84.237756, 34.090426),\n",
" (-83.833011, 34.090426), (-83.833011, 33.904859),\n",
" (-84.237756, 33.904859)\n",
" ])\n",
" [\n",
" (-84.237756, 33.904859),\n",
" (-84.237756, 34.090426),\n",
" (-83.833011, 34.090426),\n",
" (-83.833011, 33.904859),\n",
" (-84.237756, 33.904859),\n",
" ]\n",
")\n",
"polygons_nearby = KNNQuery.SpatialKnnQuery(polygon_rdd, polygon, 5, False)"
]
},
Expand Down Expand Up @@ -1737,7 +1761,9 @@
"source": [
"query_envelope = Envelope(-85.01, -60.01, 34.01, 50.01)\n",
"\n",
"result_range_query = RangeQuery.SpatialRangeQuery(linestring_rdd, query_envelope, False, False)"
"result_range_query = RangeQuery.SpatialRangeQuery(\n",
" linestring_rdd, query_envelope, False, False\n",
")"
]
},
{
Expand Down Expand Up @@ -1835,9 +1861,7 @@
],
"source": [
"sedona.createDataFrame(\n",
" result_range_query.map(lambda x: [x.geom]),\n",
" schema,\n",
" verifySchema=False\n",
" result_range_query.map(lambda x: [x.geom]), schema, verifySchema=False\n",
").show(5, True)"
]
},
Expand Down Expand Up @@ -2325,7 +2349,9 @@
"source": [
"query_envelope = Envelope(-85.01, -60.01, 34.01, 50.01)\n",
"\n",
"result_range_query = RangeQueryRaw.SpatialRangeQuery(linestring_rdd, query_envelope, False, False)"
"result_range_query = RangeQueryRaw.SpatialRangeQuery(\n",
" linestring_rdd, query_envelope, False, False\n",
")"
]
},
{
Expand Down
Loading
Loading