Skip to content

Commit

Permalink
docs(geospatial): update blog to use as_scalar and fix dependencies (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncclementi authored Mar 5, 2024
1 parent 98c52aa commit a845030
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions conda/environment-arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dependencies:
- toolz >=0.11
- trino-python-client >=0.321
# geospatial
- leafmap >=0.29.6
- leafmap >=0.29.6,<0.31
# test dependencies
- filelock >=3.7.0,<4
- hypothesis >=6.58.0,<7
Expand Down Expand Up @@ -91,4 +91,4 @@ dependencies:
- just
- pip
- pip:
- lonboard>=0.3.0
- lonboard==0.4.0
6 changes: 4 additions & 2 deletions conda/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies:
- toolz >=0.11
- trino-python-client >=0.321
# geospatial
- leafmap >=0.29.6
- leafmap >=0.29.6,<0.31
# streaming
- kafka-python
# test dependencies
Expand Down Expand Up @@ -93,4 +93,6 @@ dependencies:
- taplo
- tqdm >=4.66.1
- just
# dependencies for lonboard
- pip
- pip:
- lonboard==0.4.0
16 changes: 7 additions & 9 deletions docs/posts/ibis-duckdb-geospatial/index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,9 @@ broad_station
Then convert it to a scalar subquery:

```{python}
broad_station_subquery = broad_station.select("geom").to_array()
broad_station_subquery = broad_station.select("geom").as_scalar()
```

::: {.callout-note}
The `.to_array()` API will change in version `9.0` to a more convenient alternative: `broad_station.as_scalar()`.
:::

### `geo_equals` (`ST_Equals`)

Expand All @@ -113,7 +110,7 @@ We can also write this query without using `broad_station` as a variable, and wi
API, also known as [the underscore API](../../how-to/analytics/chain_expressions.qmd).

```{python}
subway_stations.filter(_.geom.geo_equals(_.filter(_.NAME == "Broad St")[["geom"]].to_array()))
subway_stations.filter(_.geom.geo_equals(_.filter(_.NAME == "Broad St")[["geom"]].as_scalar()))
```

### `intersect` (ST_Intersect)
Expand Down Expand Up @@ -148,8 +145,9 @@ sts_near_broad
```

::: {.callout-note}
In the previous query, `streets` and `broad_station` are different tables. We use [`to_array()`](../../reference/expression-tables.qmd#ibis.expr.types.relations.Table.to_array) to generate a
scalar subquery from a table with a single column (whose shape is scalar).
In the previous query, `streets` and `broad_station` are different tables. We use
[`as_scalar()`](../../reference/expression-tables.qmd#ibis.expr.types.relations.Table.as_scalar)
to generate a scalar subquery from a table with a single column (whose shape is scalar).
:::

To visualize the findings, we will convert the tables to GeoPandas DataFrames.
Expand Down Expand Up @@ -211,7 +209,7 @@ To find if there were any homicides in that area, we can find where the polygon
200 meters buffer to our "Broad St" station point intersects with the geometry column in our homicides table.

```{python}
h_near_broad = homicides.filter(_.geom.intersects(broad_station.select(_.geom.buffer(200)).to_array()))
h_near_broad = homicides.filter(_.geom.intersects(broad_station.select(_.geom.buffer(200)).as_scalar()))
h_near_broad
```

Expand All @@ -220,7 +218,7 @@ data we can't tell the street near which it happened. However, we can check if t
distance of a street.

```{python}
h_street = streets.filter(_.geom.d_within(h_near_broad.select(_.geom).to_array(), 2))
h_street = streets.filter(_.geom.d_within(h_near_broad.select(_.geom).as_scalar(), 2))
h_street
```

Expand Down
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ quartodoc = { version = ">=0.6.1,<1", python = ">=3.10,<3.13" }
requests = { version = ">=2,<3", python = ">=3.10,<3.13" }
scikit-learn = { version = ">=1.3,<2", python = ">=3.10,<3.13" }
seaborn = { version = ">=0.12.2,<1", python = ">=3.10,<3.13" }
leafmap = { version = ">=0.29.6,<1", python = ">=3.10,<3.13" }
lonboard = { version = ">=0.5.0,<1", python = ">=3.10,<3.13" }
leafmap = { version = ">=0.29.6,<0.31", python = ">=3.10,<3.13" }
lonboard = { version = "==0.4.0", python = ">=3.10,<3.13" }

[tool.poetry.extras]
# generate the `all` extra using nix run '.#gen-all-extras'
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ aiohttp==3.9.3 ; python_version >= "3.9" and python_version < "4.0"
aiosignal==1.3.1 ; python_version >= "3.9" and python_version < "4.0"
altair==5.2.0 ; python_version >= "3.10" and python_version < "3.13"
annotated-types==0.6.0 ; python_version >= "3.10" and python_version < "3.13"
anywidget==0.9.2 ; python_version >= "3.10" and python_version < "3.13"
anywidget==0.7.1 ; python_version >= "3.10" and python_version < "3.13"
appdirs==1.4.4 ; python_version >= "3.9" and python_version < "4.0"
appnope==0.1.4 ; python_version >= "3.10" and python_version < "3.13" and platform_system == "Darwin"
asn1crypto==1.5.1 ; python_version >= "3.9" and python_version < "4.0"
Expand Down Expand Up @@ -111,9 +111,9 @@ jupyter-core==5.7.1 ; python_version >= "3.10" and python_version < "3.13"
jupyterlab-widgets==3.0.10 ; python_version >= "3.10" and python_version < "3.13"
keyring==24.3.1 ; python_version >= "3.9" and python_version < "4.0"
kiwisolver==1.4.5 ; python_version >= "3.10" and python_version < "3.13"
leafmap==0.31.3 ; python_version >= "3.10" and python_version < "3.13"
leafmap==0.30.1 ; python_version >= "3.10" and python_version < "3.13"
locket==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
lonboard==0.6.0 ; python_version >= "3.10" and python_version < "3.13"
lonboard==0.4.0 ; python_version >= "3.10" and python_version < "3.13"
lz4==4.3.3 ; python_version >= "3.9" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.9" and python_version < "4.0"
markupsafe==2.1.5 ; python_version >= "3.9" and python_version < "4.0"
Expand Down

0 comments on commit a845030

Please sign in to comment.