Skip to content

Commit bbd102c

Browse files
committed
🔧 Switch to ruff
* Variables not shadowing Python builtins (A001) * Not used loop control variable renamed with a leading underscore (B007) * Raise with from inside except (B904) * Add explicit `strict=` parameter to `zip()` (B905) * Call datetime.now and datetime.strptime with timezone (DTZ005, DTZ007) * Assign a `def` instead of a `lambda` expression (E731) * Replace legacy `np.random.randn` with `np.random.Generator` (NPY002) * Use `.merge` method instead of `pd.merge` function (PD015) * `open()` is replaced by `Path.open()` (PTH123)
1 parent 3279a8f commit bbd102c

87 files changed

Lines changed: 15023 additions & 8019 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,17 @@ repos:
3131
rev: 4b2e70d08cb2ccd26d1fba73588de41c7a5d50b7 # v0.25
3232
hooks:
3333
- id: validate-pyproject
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
rev: 5e2fb545eba1ea9dc051f6f962d52fe8f76a9794 # v0.15.13
36+
hooks:
37+
- id: ruff-check
38+
args: [--fix, --exit-non-zero-on-fix]
39+
- id: ruff-format
3440
- repo: https://github.com/sphinx-contrib/sphinx-lint
3541
rev: c883505f64b59c3c5c9375191e4ad9f98e727ccd # v1.0.2
3642
hooks:
3743
- id: sphinx-lint
3844
types: [rst]
39-
- repo: https://github.com/pycqa/isort
40-
rev: dac090ce4d9ee313d086e2e89ab1acb8c2664fa1 # 9.0.0a3
41-
hooks:
42-
- id: isort
43-
additional_dependencies: ["toml"]
44-
entry: isort --profile=black
45-
name: isort (python)
46-
- repo: https://github.com/psf/black-pre-commit-mirror
47-
rev: fa505ab9c3e0fedafe1709fd7ac2b5f8996c670d # 26.3.1
48-
hooks:
49-
- id: black
50-
- repo: https://github.com/tonybaloney/perflint
51-
rev: 22f831509bc7765ce272ad6fcb99398d86a26a52 # 0.8.1
52-
hooks:
53-
- id: perflint
54-
exclude: ^docs/
5545
- repo: https://github.com/adamchainz/blacken-docs
5646
rev: fda77690955e9b63c6687d8806bafd56a526e45f # 1.20.0
5747
hooks:

data/.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
# SPDX-License-Identifier: BSD-3-Clause
44

5-
/fortune500.csv
6-
/Big.Buck.Bunny.mp4
75
/example.webm
6+
/ignore-iot_constraints.tdda
7+
/iot_example.json
88
/iris.csv
9+
/fortune500.csv
10+
/Big.Buck.Bunny.mp4

docs/clean-prep/dask-pipeline.ipynb

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@
3434
"metadata": {},
3535
"outputs": [],
3636
"source": [
37+
"import datetime\n",
3738
"import logging\n",
38-
"import sys\n",
3939
"\n",
40-
"from datetime import datetime\n",
41-
"from math import radians\n",
4240
"from operator import itemgetter\n",
4341
"from time import sleep\n",
4442
"\n",
43+
"import httpx\n",
4544
"import numpy as np\n",
46-
"import requests\n",
4745
"\n",
4846
"from dask import delayed\n",
4947
"from sklearn.metrics import DistanceMetric"
@@ -62,8 +60,7 @@
6260
"metadata": {},
6361
"outputs": [],
6462
"source": [
65-
"logger = logging.getLogger()\n",
66-
"logger.setLevel(logging.INFO)"
63+
"logger = logging.getLogger()"
6764
]
6865
},
6966
{
@@ -81,13 +78,14 @@
8178
"source": [
8279
"from geopy.geocoders import Nominatim\n",
8380
"\n",
81+
"\n",
8482
"def get_lat_long(address):\n",
8583
" loc = Nominatim(user_agent=\"Geopy Library\")\n",
86-
" getLoc = loc.geocode(address)\n",
84+
" get_loc = loc.geocode(address)\n",
8785
" return {\n",
88-
" \"name\": getLoc.address,\n",
89-
" \"lat\": getLoc.latitude,\n",
90-
" \"long\": getLoc.longitude\n",
86+
" \"name\": get_loc.address,\n",
87+
" \"lat\": get_loc.latitude,\n",
88+
" \"long\": get_loc.longitude,\n",
9189
" }"
9290
]
9391
},
@@ -191,7 +189,7 @@
191189
"outputs": [],
192190
"source": [
193191
"def get_spaceship_location():\n",
194-
" resp = requests.get(\"http://api.open-notify.org/iss-now.json\")\n",
192+
" resp = httpx.get(\"http://api.open-notify.org/iss-now.json\")\n",
195193
" location = resp.json()[\"iss_position\"]\n",
196194
" return {\n",
197195
" \"lat\": float(location.get(\"latitude\")),\n",
@@ -209,9 +207,9 @@
209207
" dist = DistanceMetric.get_metric(\"haversine\")\n",
210208
" lon1, lat1, lon2, lat2 = map(np.radians, [lon1, lat1, lon2, lat2])\n",
211209
"\n",
212-
" X = [[lat1, lon1], [lat2, lon2]]\n",
210+
" ll = [[lat1, lon1], [lat2, lon2]]\n",
213211
" kms = 6367\n",
214-
" return (kms * dist.pairwise(X)).max()"
212+
" return (kms * dist.pairwise(ll)).max()"
215213
]
216214
},
217215
{
@@ -222,9 +220,12 @@
222220
"source": [
223221
"def iss_dist_from_loc(issloc, loc):\n",
224222
" distance = great_circle_dist(\n",
225-
" issloc.get(\"long\"), issloc.get(\"lat\"), loc.get(\"long\"), loc.get(\"lat\")\n",
223+
" issloc.get(\"long\"),\n",
224+
" issloc.get(\"lat\"),\n",
225+
" loc.get(\"long\"),\n",
226+
" loc.get(\"lat\"),\n",
226227
" )\n",
227-
" logging.info(f\"ISS is {int(distance)}km from {loc.get(\"name\")}\")\n",
228+
" logger.info(f\"ISS is {int(distance)}km from {loc.get('name')}\")\n",
228229
" return distance"
229230
]
230231
},
@@ -235,27 +236,27 @@
235236
"outputs": [],
236237
"source": [
237238
"def iss_pass_near_loc(loc):\n",
238-
" resp = requests.get(\n",
239+
" resp = httpx.get(\n",
239240
" \"http://api.open-notify.org/iss-pass.json\",\n",
240241
" params={\"lat\": loc.get(\"lat\"), \"lon\": loc.get(\"long\")},\n",
241242
" )\n",
242243
" data = resp.json().get(\"response\")[0]\n",
243-
" td = datetime.fromtimestamp(data.get(\"risetime\")) - datetime.now()\n",
244+
" td = datetime.datetime.fromtimestamp(\n",
245+
" data.get(\"risetime\"),\n",
246+
" tz=datetime.timezone.utc,\n",
247+
" ) - datetime.datetime.now(tz=datetime.timezone.utc)\n",
244248
" m, s = divmod(int(td.total_seconds()), 60)\n",
245249
" h, m = divmod(m, 60)\n",
246-
" logging.info(\n",
247-
" \"ISS will pass near %s in %02d:%02d:%02d\", loc.get(\"name\"), h, m, s\n",
250+
" logger.info(\n",
251+
" \"ISS will pass near %s in %02d:%02d:%02d\",\n",
252+
" loc.get(\"name\"),\n",
253+
" h,\n",
254+
" m,\n",
255+
" s,\n",
248256
" )\n",
249257
" return td.total_seconds()"
250258
]
251259
},
252-
{
253-
"cell_type": "markdown",
254-
"metadata": {},
255-
"source": [
256-
"The predictions for the `iss-pass` API are unfortunately no longer available, see[Open Notify API Server](http://api.open-notify.org)."
257-
]
258-
},
259260
{
260261
"cell_type": "code",
261262
"execution_count": 11,
@@ -427,9 +428,9 @@
427428
],
428429
"metadata": {
429430
"kernelspec": {
430-
"display_name": "Python 3.11 Kernel",
431+
"display_name": "Python 3.13 Kernel",
431432
"language": "python",
432-
"name": "python311"
433+
"name": "python313"
433434
},
434435
"language_info": {
435436
"codemirror_mode": {
@@ -441,7 +442,7 @@
441442
"name": "python",
442443
"nbconvert_exporter": "python",
443444
"pygments_lexer": "ipython3",
444-
"version": "3.11.4"
445+
"version": "3.13.0"
445446
},
446447
"latex_envs": {
447448
"LaTeX_envs_menu_present": true,

0 commit comments

Comments
 (0)