Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): add zones geojson example #8040

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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()

Check warning on line 140 in ibis/examples/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/examples/__init__.py#L140

Added line #L140 was not covered by tests

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
Loading