Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated adding instance_format to variable query #83

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"])