Skip to content

Commit

Permalink
updated adding instance_format to variable query (#83)
Browse files Browse the repository at this point in the history
* consolidate query call, add changelog, correct test typo

* support multiple values

Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>

* Update tests/test_variable.py

Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>

* Update README.md

---------

Co-authored-by: Chuck Daniels <cjdaniels4@gmail.com>
Co-authored-by: Frank Greguska <89428916+frankinspace@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 5, 2024
1 parent e702451 commit 0770e4a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Support multi-point searches ([#72](https://github.com/nasa/python_cmr/issues/72))
- Support `processing_level_id` in `CollectionQuery` ([#76](https://github.com/nasa/python_cmr/issues/76))
- Support `platform` in `CollectionQuery` ([#77](https://github.com/nasa/python_cmr/issues/77))
- Support searching by instance format for `VariableQuery` ([#59]https://github.com/nasa/python_cmr/issues/59)

### Fixed
- Setup vcrpy for new `revision_date` unit tests ([#70](https://github.com/nasa/python_cmr/issues/70))
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ api.name('/AMR_Side_1/acc_lat')

# Search via concept_id
api.concept_id('V2112019824-POCLOUD')

# Search via instance format
query.instance_format(["zarr", "kerchunk"])
```

As an alternative to chaining methods together to set the parameters of your query, a method exists to allow you to pass
Expand Down
15 changes: 15 additions & 0 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,21 @@ def __init__(self, mode: str = CMR_OPS):
"dif", "dif10", "opendata", "umm_json", "umm_json_v[0-9]_[0-9]"
])

def instance_format(self, format: Union[str, Sequence[str]]) -> Self:
"""
Filter by instance format(s), matching any one of the specified formats.
Does nothing if `format` is an empty string or an empty sequence.
:param format: format(s) for variable instance (a single string, or sequence of
strings)
:returns: self
"""

if format:
# Assume we have non-empty string or sequence of strings (list, tuple, etc.)
self.params['instance_format'] = [format] if isinstance(format, str) else format

return self
@override
def _valid_state(self) -> bool:
return True
14 changes: 14 additions & 0 deletions tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,17 @@ def bearer_test_token(self):

self.assertIn("Authorization", query.headers)
self.assertEqual(query.headers["Authorization"], "Bearer 123TOKEN")

def test_instance_format(self):
query = VariableQuery()
query.instance_format("zarr")

self.assertIn("instance_format", query.params)
self.assertEqual(query.params["instance_format"], ["zarr"])

def test_instance_formats(self):
query = VariableQuery()
query.instance_format(["zarr", "kerchunk"])

self.assertIn("instance_format", query.params)
self.assertEqual(query.params["instance_format"], ["zarr", "kerchunk"])

0 comments on commit 0770e4a

Please sign in to comment.