Skip to content

Commit

Permalink
feat(examples): add zones geojson example (#8040)
Browse files Browse the repository at this point in the history
Adds a `zones` geospatial data example

Closes #7958.
  • Loading branch information
cpcloud authored Jan 22, 2024
1 parent 899dce1 commit 2d562b7
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
36 changes: 36 additions & 0 deletions ibis/backends/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,39 @@ def test_load_examples(con, example, columns):
t = getattr(ibis.examples, example).fetch(backend=con)
assert t.columns == columns
assert t.count().execute() > 0


@pytest.mark.skipif(
(LINUX or MACOS) and SANDBOXED,
reason="nix on linux cannot download duckdb extensions or data due to sandboxing",
)
@pytest.mark.notimpl(
[
# everything except duckdb
"bigquery",
"clickhouse",
"dask",
"datafusion",
"druid",
"exasol",
"flink",
"impala",
"mssql",
"mysql",
"oracle",
"pandas",
"polars",
"postgres",
"pyspark",
"snowflake",
"sqlite",
"trino",
]
)
def test_load_geo_example(con):
pytest.importorskip("geopandas")
pytest.importorskip("shapely")
pytest.importorskip("geoalchemy2")

t = ibis.examples.zones.fetch(backend=con)
assert t.geom.type().is_geospatial()
27 changes: 27 additions & 0 deletions ibis/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,33 @@ def __dir__() -> list[str]:
return sorted(_get_metadata().keys())


class Zones(Concrete):
name: str
help: Optional[str]

def fetch(
self,
*,
table_name: str | None = None,
backend: BaseBackend | None = None,
) -> ir.Table:
if backend is None:
backend = ibis.get_backend()

name = self.name

if table_name is None:
table_name = name

board = _get_board()

(path,) = board.pin_download(name)
return backend.read_geo(path)


zones = Zones("zones", help="Taxi zones in New York City (EPSG:2263)")


def __getattr__(name: str) -> Example:
try:
meta = _get_metadata()
Expand Down
13 changes: 13 additions & 0 deletions ibis/examples/gen_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from collections import Counter
from pathlib import Path
from typing import TYPE_CHECKING, Any
from urllib.request import urlretrieve

import pins
import requests
Expand Down Expand Up @@ -107,6 +108,16 @@ def add_movielens_example(
con.read_csv(csv_path).to_parquet(parquet_path, codec="zstd")


def add_zones_geojson(data_path: Path) -> None:
file_name = "zones.geojson"
url = "https://raw.githubusercontent.com/ibis-project/testing-data/master/geojson/zones.geojson"

file_path = Path(file_name)

if not file_path.exists():
urlretrieve(url, data_path / file_path)


def add_imdb_example(data_path: Path) -> None:
def convert_to_parquet(
base: Path,
Expand Down Expand Up @@ -229,6 +240,8 @@ def main(parser):

add_wowah_example(data_path, client=storage.Client(), metadata=metadata)

add_zones_geojson(data_path)

# generate data from R
subprocess.check_call(["Rscript", str(EXAMPLES_DIRECTORY / "gen_examples.R")])

Expand Down

0 comments on commit 2d562b7

Please sign in to comment.