Skip to content

Commit

Permalink
Merge branch 'main' into unpin-urllib3
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski authored May 30, 2024
2 parents 346f254 + 788a90e commit 3f9bd4c
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.4.4"
rev: "v0.4.5"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Support for "Feature" type `intersects` dictionaries [#696](https://github.com/stac-utils/pystac-client/pull/696)

## [v0.8.1] - 2024-05-23

### Fixed

- Use singular `include` and `exclude` Field extension key names [#690](https://github.com/stac-utils/pystac-client/pull/690)

## [v0.8.0] - 2024-05-17

### Fixed
Expand Down Expand Up @@ -366,7 +376,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

Initial release.

[Unreleased]: https://github.com/stac-utils/pystac-client/compare/v0.8.0...main
[Unreleased]: https://github.com/stac-utils/pystac-client/compare/v0.8.1...main
[v0.8.1]: https://github.com/stac-utils/pystac-client/compare/v0.8.0...v0.8.1
[v0.8.0]: https://github.com/stac-utils/pystac-client/compare/v0.7.7...v0.8.0
[v0.7.7]: https://github.com/stac-utils/pystac-client/compare/v0.7.6...v0.7.7
[v0.7.6]: https://github.com/stac-utils/pystac-client/compare/v0.7.5...v0.7.6
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ STAC Versions
+---------------+-----------+-----------------------------+
| pystac-client | STAC spec | STAC API Spec |
+===============+===========+=============================+
| 0.8.x | 1.0.x | 1.0.0-beta.1 - 1.0.0 |
+ --------------+-----------+-----------------------------+
| 0.7.x | 1.0.x | 1.0.0-beta.1 - 1.0.0 |
+---------------+-----------+-----------------------------+
| 0.6.x | 1.0.x | 1.0.0-beta.1 - 1.0.0-rc.2 |
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ stac-client = "pystac_client.cli:cli"
[project.optional-dependencies]
dev = [
"black~=24.0",
"codespell~=2.2.4",
"codespell~=2.3.0",
"coverage~=7.2",
"doc8~=1.1.1",
"importlib-metadata~=7.0",
Expand All @@ -53,7 +53,7 @@ dev = [
"pytest~=8.0",
"recommonmark~=0.7.1",
"requests-mock~=1.12",
"ruff==0.4.4",
"ruff==0.4.6",
"tomli~=2.0; python_version<'3.11'",
"types-python-dateutil>=2.8.19,<2.10.0",
"types-requests~=2.31.0",
Expand Down
20 changes: 11 additions & 9 deletions pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ class ItemSearch:
bbox: A list, tuple, or iterator representing a bounding box of 2D
or 3D coordinates. Results will be filtered
to only those intersecting the bounding box.
intersects: A string or dictionary representing a GeoJSON geometry, or
an object that implements a
``__geo_interface__`` property, as supported by several libraries
including Shapely, ArcPy, PySAL, and
geojson. Results filtered to only those intersecting the geometry.
intersects: A string or dictionary representing a GeoJSON geometry or feature,
or an object that implements a ``__geo_interface__`` property, as supported
by several libraries including Shapely, ArcPy, PySAL, and geojson. Results
filtered to only those intersecting the geometry.
datetime: Either a single datetime or datetime range used to filter results.
You may express a single datetime using a :class:`datetime.datetime`
instance, a `RFC 3339-compliant <https://tools.ietf.org/html/rfc3339>`__
Expand Down Expand Up @@ -633,20 +632,23 @@ def _fields_to_dict(fields: List[str]) -> Fields:
includes.append(field[1:])
else:
includes.append(field)
return {"includes": includes, "excludes": excludes}
return {"include": includes, "exclude": excludes}

@staticmethod
def _fields_dict_to_str(fields: Fields) -> str:
includes = [f"+{x}" for x in fields.get("includes", [])]
excludes = [f"-{x}" for x in fields.get("excludes", [])]
includes = [f"+{x}" for x in fields.get("include", [])]
excludes = [f"-{x}" for x in fields.get("exclude", [])]
return ",".join(chain(includes, excludes))

@staticmethod
def _format_intersects(value: Optional[IntersectsLike]) -> Optional[Intersects]:
if value is None:
return None
if isinstance(value, dict):
return deepcopy(value)
if value.get("type") == "Feature":
return deepcopy(value.get("geometry"))
else:
return deepcopy(value)
if isinstance(value, str):
return dict(json.loads(value))
if hasattr(value, "__geo_interface__"):
Expand Down
2 changes: 1 addition & 1 deletion pystac_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.8.1"
59 changes: 59 additions & 0 deletions tests/cassettes/test_item_search/test_fields.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 37 additions & 8 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,23 @@ def test_fields(self) -> None:

search = ItemSearch(url=SEARCH_URL, fields="id,collection,+foo,-bar")
assert search.get_parameters()["fields"] == {
"excludes": ["bar"],
"includes": ["id", "collection", "foo"],
"exclude": ["bar"],
"include": ["id", "collection", "foo"],
}

search = ItemSearch(url=SEARCH_URL, fields=["id", "collection", "+foo", "-bar"])
assert search.get_parameters()["fields"] == {
"excludes": ["bar"],
"includes": ["id", "collection", "foo"],
"exclude": ["bar"],
"include": ["id", "collection", "foo"],
}

search = ItemSearch(
url=SEARCH_URL,
fields={"excludes": ["bar"], "includes": ["id", "collection"]},
fields={"exclude": ["bar"], "include": ["id", "collection"]},
)
assert search.get_parameters()["fields"] == {
"excludes": ["bar"],
"includes": ["id", "collection"],
"exclude": ["bar"],
"include": ["id", "collection"],
}

search = ItemSearch(
Expand All @@ -500,7 +500,7 @@ def test_fields(self) -> None:
search = ItemSearch(
url=SEARCH_URL,
method="GET",
fields={"excludes": ["bar"], "includes": ["id", "collection"]},
fields={"exclude": ["bar"], "include": ["id", "collection"]},
)
assert search.get_parameters()["fields"] == "+id,+collection,-bar"

Expand Down Expand Up @@ -835,3 +835,32 @@ def test_naive_datetime() -> None:
method="POST",
)
assert search.get_parameters()["datetime"] == "2024-05-14T04:25:42Z"


@pytest.mark.vcr
def test_fields() -> None:
search = ItemSearch(
url="https://earth-search.aws.element84.com/v1/search",
collections=["sentinel-2-c1-l2a"],
intersects={"type": "Point", "coordinates": [-105.1019, 40.1672]},
max_items=1,
fields=["-geometry", "-assets", "-links"],
)
item = next(search.items_as_dicts())
assert "geometry" not in item
assert "assets" not in item
assert "links" not in item


def test_feature() -> None:
search = ItemSearch(
url="https://earth-search.aws.element84.com/v1/search",
intersects={
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-105.1019, 40.1672]},
},
)
assert search.get_parameters()["intersects"] == {
"type": "Point",
"coordinates": [-105.1019, 40.1672],
}

0 comments on commit 3f9bd4c

Please sign in to comment.