Skip to content

Commit

Permalink
pre-commit add Python black hook; format Python with black
Browse files Browse the repository at this point in the history
  • Loading branch information
jbampton committed Sep 19, 2024
1 parent d04a8e0 commit 5f766cd
Show file tree
Hide file tree
Showing 148 changed files with 8,857 additions and 4,162 deletions.
4 changes: 2 additions & 2 deletions .github/linters/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ target-version = "py38"
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = ["E721", "E722", "E731", "F401", "F402", "F403", "F405", "F811", "F821", "F822", "F841", "F901"]
select = ["E3", "E4", "E5", "E7", "E9", "F"]
ignore = ["E501", "E721", "E722", "E731", "F401", "F402", "F403", "F405", "F811", "F821", "F822", "F841", "F901"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
Expand Down
4 changes: 4 additions & 0 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
- repo: https://github.com/codespell-project/codespell
rev: v2.3.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

0 comments on commit 5f766cd

Please sign in to comment.