Skip to content

Commit

Permalink
Use singular field key names: include and exclude (#690)
Browse files Browse the repository at this point in the history
* Use singular field key names: `include` and `exclude`

Fixes #689

* Update the CHANGELOG

* tests: add vcr test for fields

---------

Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>
  • Loading branch information
kurtmckee and gadomski committed May 23, 2024
1 parent 9eb5e0c commit 8f12756
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Use singular `include` and `exclude` Field extension key names to align with the extension documentation. [#690](https://github.com/stac-utils/pystac-client/issues/690)

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

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,12 @@ 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
Expand Down
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.

31 changes: 23 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,18 @@ 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

0 comments on commit 8f12756

Please sign in to comment.