Skip to content

Commit 8f12756

Browse files
kurtmckeegadomski
andauthored
Use singular field key names: include and exclude (#690)
* 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>
1 parent 9eb5e0c commit 8f12756

File tree

4 files changed

+89
-11
lines changed

4 files changed

+89
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- 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)
13+
1014
## [v0.8.0] - 2024-05-17
1115

1216
### Fixed

pystac_client/item_search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,12 @@ def _fields_to_dict(fields: List[str]) -> Fields:
633633
includes.append(field[1:])
634634
else:
635635
includes.append(field)
636-
return {"includes": includes, "excludes": excludes}
636+
return {"include": includes, "exclude": excludes}
637637

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

644644
@staticmethod

tests/cassettes/test_item_search/test_fields.yaml

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

tests/test_item_search.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,23 @@ def test_fields(self) -> None:
468468

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

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

481481
search = ItemSearch(
482482
url=SEARCH_URL,
483-
fields={"excludes": ["bar"], "includes": ["id", "collection"]},
483+
fields={"exclude": ["bar"], "include": ["id", "collection"]},
484484
)
485485
assert search.get_parameters()["fields"] == {
486-
"excludes": ["bar"],
487-
"includes": ["id", "collection"],
486+
"exclude": ["bar"],
487+
"include": ["id", "collection"],
488488
}
489489

490490
search = ItemSearch(
@@ -500,7 +500,7 @@ def test_fields(self) -> None:
500500
search = ItemSearch(
501501
url=SEARCH_URL,
502502
method="GET",
503-
fields={"excludes": ["bar"], "includes": ["id", "collection"]},
503+
fields={"exclude": ["bar"], "include": ["id", "collection"]},
504504
)
505505
assert search.get_parameters()["fields"] == "+id,+collection,-bar"
506506

@@ -835,3 +835,18 @@ def test_naive_datetime() -> None:
835835
method="POST",
836836
)
837837
assert search.get_parameters()["datetime"] == "2024-05-14T04:25:42Z"
838+
839+
840+
@pytest.mark.vcr
841+
def test_fields() -> None:
842+
search = ItemSearch(
843+
url="https://earth-search.aws.element84.com/v1/search",
844+
collections=["sentinel-2-c1-l2a"],
845+
intersects={"type": "Point", "coordinates": [-105.1019, 40.1672]},
846+
max_items=1,
847+
fields=["-geometry", "-assets", "-links"],
848+
)
849+
item = next(search.items_as_dicts())
850+
assert "geometry" not in item
851+
assert "assets" not in item
852+
assert "links" not in item

0 commit comments

Comments
 (0)