Skip to content

Commit 594c0de

Browse files
committed
fix: be less dumb
1 parent 339f0d6 commit 594c0de

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/search.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub fn search<'py>(
4646
{
4747
pyo3_async_runtimes::tokio::future_into_py(py, async move {
4848
let value = search_duckdb(href, search, max_items)?;
49-
Ok(value)
49+
Ok(Json(value.items))
5050
})
5151
} else {
5252
pyo3_async_runtimes::tokio::future_into_py(py, async move {
5353
let value = search_api(href, search, max_items).await?;
54-
Ok(value)
54+
Ok(Json(value.items))
5555
})
5656
}
5757
}
@@ -105,16 +105,25 @@ pub fn search_to<'py>(
105105
{
106106
pyo3_async_runtimes::tokio::future_into_py(py, async move {
107107
let value = search_duckdb(href, search, max_items)?;
108-
Ok(value)
108+
let count = value.items.len();
109+
let _ = format
110+
.put_opts(
111+
outfile,
112+
serde_json::to_value(value).map_err(Error::from)?,
113+
options.unwrap_or_default(),
114+
)
115+
.await
116+
.map_err(Error::from)?;
117+
Ok(count)
109118
})
110119
} else {
111120
pyo3_async_runtimes::tokio::future_into_py(py, async move {
112121
let value = search_api(href, search, max_items).await?;
113-
let count = value.0.items.len();
122+
let count = value.items.len();
114123
let _ = format
115124
.put_opts(
116125
outfile,
117-
serde_json::to_value(value.0).map_err(Error::from)?,
126+
serde_json::to_value(value).map_err(Error::from)?,
118127
options.unwrap_or_default(),
119128
)
120129
.await
@@ -128,16 +137,16 @@ fn search_duckdb(
128137
href: String,
129138
search: Search,
130139
max_items: Option<usize>,
131-
) -> Result<Json<stac_api::ItemCollection>> {
140+
) -> Result<stac_api::ItemCollection> {
132141
let value = stac_duckdb::search(&href, search, max_items)?;
133-
Ok(Json(value))
142+
Ok(value)
134143
}
135144

136145
async fn search_api(
137146
href: String,
138147
search: Search,
139148
max_items: Option<usize>,
140-
) -> Result<Json<stac_api::ItemCollection>> {
149+
) -> Result<stac_api::ItemCollection> {
141150
let value = stac_api::client::search(&href, search, max_items).await?;
142-
Ok(Json(value))
151+
Ok(value)
143152
}

stacrs.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ async def search_to(
272272
to None.
273273
274274
Returns:
275-
list[dict[str, Any]]: A list of the returned STAC items.
275+
int: The number of items written
276276
277277
Examples:
278-
>>> items = await stacrs.search_to("out.parquet",
278+
>>> count = await stacrs.search_to("out.parquet",
279279
... "https://landsatlook.usgs.gov/stac-server",
280280
... collections=["landsat-c2l2-sr"],
281281
... intersects={"type": "Point", "coordinates": [-105.119, 40.173]},

tests/test_search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88

99
async def test_search() -> None:
10-
item_collection = await stacrs.search(
10+
items = await stacrs.search(
1111
"https://landsatlook.usgs.gov/stac-server",
1212
collections="landsat-c2l2-sr",
1313
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
1414
sortby="-properties.datetime",
1515
max_items=1,
1616
)
17-
assert len(item_collection["features"]) == 1
17+
assert len(items) == 1
1818

1919

2020
async def test_search_to(tmp_path: Path) -> None:
@@ -47,5 +47,5 @@ async def test_search_to_geoparquet(tmp_path: Path) -> None:
4747

4848

4949
async def test_search_geoparquet(data: Path) -> None:
50-
item_collection = await stacrs.search(str(data / "extended-item.parquet"))
51-
assert len(item_collection["features"]) == 1
50+
items = await stacrs.search(str(data / "extended-item.parquet"))
51+
assert len(items) == 1

0 commit comments

Comments
 (0)