Skip to content

Commit

Permalink
feat(python): return point count from search_to
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Sep 22, 2024
1 parent b8699d1 commit 9c5bd1c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## [0.1.2] - 2024-09-22

### Changed

- Return the item count from `search_to`

## [0.1.1] - 2024-09-21

### Added
Expand Down Expand Up @@ -39,7 +45,8 @@ Non-functional release to fix releasing from Github actions.

Initial release.

[Unreleased]: https://github.com/stac-utils/stac-rs/compare/python-v0.1.1...main
[Unreleased]: https://github.com/stac-utils/stac-rs/compare/python-v0.1.2...main
[0.1.2]: https://github.com/stac-utils/stac-rs/compare/python-v0.1.1...python-v0.1.2
[0.1.1]: https://github.com/stac-utils/stac-rs/compare/python-v0.1.0...python-v0.1.1
[0.1.0]: https://github.com/stac-utils/stac-rs/compare/python-v0.0.3...python-v0.1.0
[0.0.3]: https://github.com/stac-utils/stac-rs/compare/python-v0.0.2...python-v0.0.3
Expand Down
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Python bindings for stac-rs"
license = "MIT OR Apache-2.0"
repository = "https://github.com/stac-utils/stac-rs"
homepage = "https://github.com/stac-utils/stac-rs"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
publish = false

Expand Down
2 changes: 1 addition & 1 deletion python/python/stacrs/stacrs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def search_to(
query: Optional[dict[str, Any]] = None,
format: Optional[str] = None,
options: Optional[list[Tuple[str, str]]] = None,
) -> None: ...
) -> int: ...
def validate_href(href: str) -> None: ...
def validate(value: dict[str, Any]) -> None: ...
def write(
Expand Down
5 changes: 3 additions & 2 deletions python/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn search_to(
query: Option<Py<PyDict>>,
format: Option<String>,
options: Option<Vec<(String, String)>>,
) -> PyResult<()> {
) -> PyResult<usize> {
let items = search_items(
href,
intersects,
Expand All @@ -180,6 +180,7 @@ pub fn search_to(
.or_else(|| Format::infer_from_href(&outfile))
.unwrap_or_default();
let item_collection = ItemCollection::from(items);
let count = item_collection.items.len();
Builder::new_current_thread()
.build()?
.block_on(format.put_opts(
Expand All @@ -188,7 +189,7 @@ pub fn search_to(
options.unwrap_or_default(),
))
.map_err(Error::from)?;
Ok(())
Ok(count)
}

fn search_items(
Expand Down
3 changes: 2 additions & 1 deletion python/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ def test_search_to(tmp_path: Path) -> None:


def test_search_to_geoparquet(tmp_path: Path) -> None:
stacrs.search_to(
count = stacrs.search_to(
str(tmp_path / "out.parquet"),
"https://landsatlook.usgs.gov/stac-server",
collections="landsat-c2l2-sr",
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
sortby="-properties.datetime",
max_items=1,
)
assert count == 1
table = pyarrow.parquet.read_table(tmp_path / "out.parquet")
items = list(stac_geoparquet.arrow.stac_table_to_items(table))
assert len(items) == 1

0 comments on commit 9c5bd1c

Please sign in to comment.