Skip to content

Commit 2f34ef7

Browse files
committed
--wip-- [skip ci]
1 parent 81825ab commit 2f34ef7

File tree

8 files changed

+358
-388
lines changed

8 files changed

+358
-388
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/example.ipynb

Lines changed: 311 additions & 376 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ dependencies = []
2525

2626
[project.optional-dependencies]
2727
arrow = ["arro3-core>=0.4.5"]
28+
docs = [
29+
"jinja2>=3.1.4",
30+
]
2831

2932
[project.scripts]
3033
stacrs = "stacrs:main"

src/duckdb.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::Result;
22
use pyo3::{
33
exceptions::PyException,
44
prelude::*,
5-
types::{PyDict, PyList},
5+
types::{PyCapsule, PyDict, PyList},
66
IntoPyObjectExt,
77
};
88
use pyo3_arrow::PyTable;
@@ -134,3 +134,9 @@ impl DuckdbClient {
134134
Ok(collections)
135135
}
136136
}
137+
138+
// TODO this probably should live in a different mod
139+
#[pyfunction]
140+
pub fn from_arrow(table: &Bound<PyCapsule>) -> () {
141+
todo!()
142+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fn stacrs(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
2424
m.add_function(wrap_pyfunction!(migrate::migrate, m)?)?;
2525
m.add_function(wrap_pyfunction!(migrate::migrate_href, m)?)?;
2626
m.add_function(wrap_pyfunction!(read::read, m)?)?;
27+
m.add_function(wrap_pyfunction!(duckdb::from_arrow, m)?)?;
2728
m.add_function(wrap_pyfunction!(search::search, m)?)?;
2829
m.add_function(wrap_pyfunction!(search::search_to, m)?)?;
2930
m.add_function(wrap_pyfunction!(version::version, m)?)?;

stacrs.pyi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ async def read(
212212
>>> item = await stacrs.read("item.json")
213213
"""
214214

215+
async def from_arrow(
216+
table: arro3.core.Table,
217+
) -> dict[str, Any]:
218+
"""
219+
Converts an [arrow3.core.table][] to a STAC item collection.
220+
221+
Requires **stacrs** to be installed with the `arrow` extra.
222+
223+
Args:
224+
table: The table
225+
226+
Returns:
227+
dict[str, Any]: The STAC item collection
228+
"""
229+
215230
async def search(
216231
href: str,
217232
*,

tests/test_duckdb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import stacrs
23
from geopandas import GeoDataFrame
34
from stacrs import DuckdbClient
45

@@ -45,3 +46,6 @@ def test_search_to_arrow(client: DuckdbClient) -> None:
4546
table = client.search_to_arrow("data/100-sentinel-2-items.parquet")
4647
data_frame = GeoDataFrame.from_arrow(table)
4748
assert len(data_frame) == 100
49+
table = data_frame.to_arrow()
50+
item_collection = stacrs.from_arrow(table)
51+
assert len(item_collection["features"]) == 100

uv.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)