Skip to content
This repository was archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Add black pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Apr 14, 2023
1 parent 87fb358 commit 85c84ad
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 181 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ repos:
rev: 0.6.0
hooks:
- id: nbstripout
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black-jupyter
34 changes: 25 additions & 9 deletions examples/Reading-Parquet-Files-using-DuckDB.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"source": [
"import ibis\n",
"\n",
"t = ibis.read_parquet(f\"s3://gbif-open-data-us-east-1/occurrence/2023-04-01/occurrence.parquet/000000\")\n",
"t = ibis.read_parquet(\n",
" f\"s3://gbif-open-data-us-east-1/occurrence/2023-04-01/occurrence.parquet/000000\"\n",
")\n",
"t"
]
},
Expand All @@ -66,11 +68,23 @@
},
"outputs": [],
"source": [
"cols = ['gbifid', 'datasetkey', 'occurrenceid', 'kingdom',\n",
" 'phylum', 'class', 'order', 'family', 'genus',\n",
" 'species', 'day', 'month', 'year']\n",
"cols = [\n",
" \"gbifid\",\n",
" \"datasetkey\",\n",
" \"occurrenceid\",\n",
" \"kingdom\",\n",
" \"phylum\",\n",
" \"class\",\n",
" \"order\",\n",
" \"family\",\n",
" \"genus\",\n",
" \"species\",\n",
" \"day\",\n",
" \"month\",\n",
" \"year\",\n",
"]\n",
"\n",
"t.select(cols).filter(t['family'].isin(['Corvidae'])).limit(5).execute()"
"t.select(cols).filter(t[\"family\"].isin([\"Corvidae\"])).limit(5).execute()"
]
},
{
Expand Down Expand Up @@ -111,7 +125,9 @@
},
"outputs": [],
"source": [
"t = ibis.read_parquet(f\"s3://gbif-open-data-us-east-1/occurrence/2023-04-01/occurrence.parquet/*\")"
"t = ibis.read_parquet(\n",
" f\"s3://gbif-open-data-us-east-1/occurrence/2023-04-01/occurrence.parquet/*\"\n",
")"
]
},
{
Expand All @@ -132,11 +148,11 @@
"outputs": [],
"source": [
"df = (\n",
" t.select(['gbifid', 'family', 'species'])\n",
" .filter(t['family'].isin(['Corvidae']))\n",
" t.select([\"gbifid\", \"family\", \"species\"])\n",
" .filter(t[\"family\"].isin([\"Corvidae\"]))\n",
" # Here we limit by 10,000 to fetch a quick batch of results\n",
" .limit(10000)\n",
" .group_by('species')\n",
" .group_by(\"species\")\n",
" .count()\n",
" .execute()\n",
")\n",
Expand Down
25 changes: 9 additions & 16 deletions examples/Substrait.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
"class DatabaseServer:\n",
" DB_NAME = \"palmer_penguins.ddb\"\n",
" DB_URL = \"https://storage.googleapis.com/ibis-tutorial-data/palmer_penguins.ddb\"\n",
" \n",
"\n",
" def __init__(self):\n",
" if not os.path.exists(self.DB_NAME):\n",
" urlretrieve(self.DB_URL, self.DB_NAME)\n",
" self.db = duckdb.connect(self.DB_NAME)\n",
" self.db.install_extension(\"substrait\")\n",
" self.db.load_extension(\"substrait\")\n",
" \n",
"\n",
" def execute(self, substrait):\n",
" result = self.db.from_substrait(substrait)\n",
" return result.fetchall()\n",
" \n",
"\n",
"\n",
"db_server = DatabaseServer()"
]
Expand All @@ -84,7 +84,7 @@
"from ibis.expr.datatypes.core import Float64, Int64, String\n",
"\n",
"table = ibis.table(\n",
" name=\"penguins\", \n",
" name=\"penguins\",\n",
" schema=[\n",
" (\"species\", String()),\n",
" (\"island\", String()),\n",
Expand All @@ -93,8 +93,8 @@
" (\"flipper_length_mm\", Int64()),\n",
" (\"body_mass_g\", Int64()),\n",
" (\"sex\", String()),\n",
" (\"year\", Int64)\n",
" ]\n",
" (\"year\", Int64),\n",
" ],\n",
")\n",
"\n",
"print(table)"
Expand Down Expand Up @@ -122,12 +122,7 @@
"\n",
"compiler = SubstraitCompiler()\n",
"\n",
"query = (\n",
" table\n",
" .select(_.species)\n",
" .group_by(_.species)\n",
" .agg(count=_.species.count())\n",
")\n",
"query = table.select(_.species).group_by(_.species).agg(count=_.species.count())\n",
"\n",
"substrait_plan = compiler.compile(query)\n",
"\n",
Expand Down Expand Up @@ -172,8 +167,7 @@
"outputs": [],
"source": [
"query = (\n",
" table\n",
" .select(_.island, _.species)\n",
" table.select(_.island, _.species)\n",
" .group_by([_.island, _.species])\n",
" .agg(num=_.species.count())\n",
" .order_by([ibis.asc(_.island), ibis.asc(_.species)])\n",
Expand All @@ -198,8 +192,7 @@
"outputs": [],
"source": [
"query = (\n",
" table\n",
" .select(_.island, _.species, _.body_mass_g)\n",
" table.select(_.island, _.species, _.body_mass_g)\n",
" .group_by([_.island, _.species])\n",
" .agg(num=_.species.count(), avg_weight=_.body_mass_g.mean())\n",
" .order_by([ibis.asc(_.island), ibis.asc(_.species)])\n",
Expand Down
27 changes: 10 additions & 17 deletions examples/clickhouse-hackernews.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"import ibis\n",
"from ibis import _\n",
"\n",
"ibis.options.interactive = True "
"ibis.options.interactive = True"
]
},
{
Expand All @@ -46,10 +46,7 @@
"outputs": [],
"source": [
"con = ibis.clickhouse.connect(\n",
" host=\"play.clickhouse.com\", \n",
" port=9440, \n",
" user=\"play\", \n",
" secure=True\n",
" host=\"play.clickhouse.com\", port=9440, user=\"play\", secure=True\n",
")"
]
},
Expand Down Expand Up @@ -131,9 +128,9 @@
"source": [
"top_posts_by_score = (\n",
" t.filter(_.title != \"\")\n",
" .select(\"title\", \"score\")\n",
" .order_by(ibis.desc(\"score\"))\n",
" .limit(5)\n",
" .select(\"title\", \"score\")\n",
" .order_by(ibis.desc(\"score\"))\n",
" .limit(5)\n",
")\n",
"\n",
"top_posts_by_score"
Expand Down Expand Up @@ -163,11 +160,7 @@
"outputs": [],
"source": [
"top_commenters = (\n",
" t.filter(_.by != \"\")\n",
" .group_by(\"by\")\n",
" .count()\n",
" .order_by(ibis.desc(\"count\"))\n",
" .limit(5)\n",
" t.filter(_.by != \"\").group_by(\"by\").count().order_by(ibis.desc(\"count\")).limit(5)\n",
")\n",
"\n",
"top_commenters"
Expand Down Expand Up @@ -214,10 +207,10 @@
"source": [
"top_commenters_by_score = (\n",
" t.filter(_.by != \"\")\n",
" .group_by(\"by\")\n",
" .agg(total_score=_.score.sum())\n",
" .order_by(ibis.desc(\"total_score\"))\n",
" .limit(5)\n",
" .group_by(\"by\")\n",
" .agg(total_score=_.score.sum())\n",
" .order_by(ibis.desc(\"total_score\"))\n",
" .limit(5)\n",
")\n",
"\n",
"top_commenters_by_score"
Expand Down
21 changes: 11 additions & 10 deletions tutorial/01-Introduction-to-Ibis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"outputs": [],
"source": [
"from tutorial_utils import setup\n",
"\n",
"setup()"
]
},
Expand Down Expand Up @@ -108,7 +109,7 @@
"metadata": {},
"outputs": [],
"source": [
"connection = ibis.sqlite.connect('geography.db')"
"connection = ibis.sqlite.connect(\"geography.db\")"
]
},
{
Expand Down Expand Up @@ -150,7 +151,7 @@
"metadata": {},
"outputs": [],
"source": [
"countries = connection.table('countries')"
"countries = connection.table(\"countries\")"
]
},
{
Expand Down Expand Up @@ -184,7 +185,7 @@
"metadata": {},
"outputs": [],
"source": [
"countries['name', 'continent', 'population']"
"countries[\"name\", \"continent\", \"population\"]"
]
},
{
Expand Down Expand Up @@ -219,7 +220,7 @@
"metadata": {},
"outputs": [],
"source": [
"countries['name', 'continent', 'population'].limit(3)"
"countries[\"name\", \"continent\", \"population\"].limit(3)"
]
},
{
Expand All @@ -239,7 +240,7 @@
"metadata": {},
"outputs": [],
"source": [
"countries[['continent']].distinct()"
"countries[[\"continent\"]].distinct()"
]
},
{
Expand All @@ -256,7 +257,7 @@
"metadata": {},
"outputs": [],
"source": [
"countries['continent'] == 'AS'"
"countries[\"continent\"] == \"AS\""
]
},
{
Expand All @@ -274,8 +275,8 @@
"metadata": {},
"outputs": [],
"source": [
"asian_countries = countries['name', 'continent', 'population'].filter(\n",
" countries['continent'] == 'AS'\n",
"asian_countries = countries[\"name\", \"continent\", \"population\"].filter(\n",
" countries[\"continent\"] == \"AS\"\n",
")\n",
"asian_countries"
]
Expand Down Expand Up @@ -310,7 +311,7 @@
"metadata": {},
"outputs": [],
"source": [
"asian_countries.order_by('population').limit(10)"
"asian_countries.order_by(\"population\").limit(10)"
]
},
{
Expand All @@ -329,7 +330,7 @@
"metadata": {},
"outputs": [],
"source": [
"asian_countries.order_by(ibis.desc('population')).limit(10)"
"asian_countries.order_by(ibis.desc(\"population\")).limit(10)"
]
},
{
Expand Down
Loading

0 comments on commit 85c84ad

Please sign in to comment.