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

Toniof 46 return strings #47

Merged
merged 5 commits into from
Apr 9, 2021
Merged
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
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Changes in 0.8.0 (in development)

* Store methods *get_type_specifier* and *get_type_specifiers_for_data* now return
values in correct format (strings instead of type specifiers)
* Provided xcube data store framework interface compatibility with
breaking changes in xcube 0.8.0 (see https://github.com/dcs4cop/xcube/issues/420).

## Changes in 0.7.0

- Replace Travis CI with AppVeyor for CI (closes #25)
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -8,4 +8,4 @@ dependencies:
- numpy >=1.17
- python-dateutil >=2.8.1
- xarray >=0.14.1
- xcube >=0.7.0
- xcube >=0.8.0
12 changes: 7 additions & 5 deletions test/test_store.py
Original file line number Diff line number Diff line change
@@ -80,13 +80,13 @@ def test_invalid_data_id(self):
def test_list_and_describe_data_ids(self):
store = CDSDataStore(endpoint_url=_CDS_API_URL,
cds_api_key=_CDS_API_KEY)
data_ids = store.get_data_ids()
data_ids = store.get_data_ids(include_attrs=['title'])
self.assertIsInstance(data_ids, Iterator)
for data_id in data_ids:
self.assertIsInstance(data_id, tuple)
self.assertTrue(1 <= len(data_id) <= 2)
for element in data_id:
self.assertIsInstance(element, str)
self.assertIsInstance(data_id[0], str)
self.assertIsInstance(data_id[1], dict)
descriptor = store.describe_data(data_id[0])
self.assertIsInstance(descriptor, DataDescriptor)

@@ -134,8 +134,10 @@ def test_get_data_store_params_schema(self):
}, CDSDataStore.get_data_store_params_schema().to_dict())

def test_get_type_specifiers(self):
self.assertTupleEqual((TYPE_SPECIFIER_CUBE, ),
CDSDataStore.get_type_specifiers())
type_specifiers = CDSDataStore.get_type_specifiers()
self.assertEqual(1, len(type_specifiers))
self.assertIsInstance(type_specifiers[0], str)
self.assertTupleEqual(('dataset[cube]',), type_specifiers)

def test_has_data_false(self):
self.assertFalse(CDSDataStore().has_data('nonexistent data ID'))
39 changes: 22 additions & 17 deletions xcube_cds/store.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
import tempfile
from abc import ABC
from abc import abstractmethod
from typing import Any
from typing import Any, Container
from typing import Dict
from typing import Iterator
from typing import List
@@ -316,8 +316,7 @@ def __init__(self,
normalize_names: Optional[bool] = False,
client_class=cdsapi.Client,
endpoint_url=None,
cds_api_key=None
):
cds_api_key=None):
"""Instantiate a CDS data opener.

:param normalize_names: if True, all variable names in the returned
@@ -330,7 +329,7 @@ def __init__(self,
:param endpoint_url: CDS API URL. Will be passed to the CDS API client.
If omitted, the client will read the value from an environment
variable or configuration file.
:param cds_api_url: CDS API key. Will be passed to the CDS API client.
:param cds_api_key: CDS API key. Will be passed to the CDS API client.
If omitted, the client will read the value from an environment
variable or configuration file.
"""
@@ -752,24 +751,30 @@ def get_data_store_params_schema(cls) -> JsonObjectSchema:

@classmethod
def get_type_specifiers(cls) -> Tuple[str, ...]:
return TYPE_SPECIFIER_CUBE,
return str(TYPE_SPECIFIER_CUBE),

def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
self._validate_data_id(data_id)
return TYPE_SPECIFIER_CUBE,
return str(TYPE_SPECIFIER_CUBE),

def get_data_ids(self, type_specifier: Optional[str] = None,
include_titles: bool = True) \
-> Iterator[Tuple[str, Optional[str]]]:
if not self._is_type_specifier_satisfied(type_specifier):
# If the type specifier isn't compatible, return an empty iterator.
return iter(())
return iter(
(data_id,
self._handler_registry[data_id].
get_human_readable_data_id(data_id) if include_titles else None)
for data_id in self._handler_registry
)
include_attrs: Container[str] = None) -> \
Union[Iterator[str], Iterator[Tuple[str, Dict[str, Any]]]]:

if self._is_type_specifier_satisfied(type_specifier):
# Only if the type specifier isn't compatible
return_tuples = include_attrs is not None
# TODO: respect names other than "title" in include_attrs
include_titles = return_tuples and 'title' in include_attrs

for data_id, handler in self._handler_registry.items():
if return_tuples:
if include_titles:
yield data_id, {'title': handler.get_human_readable_data_id(data_id)}
else:
yield data_id, {}
else:
yield data_id

def has_data(self, data_id: str, type_specifier: Optional[str] = None) \
-> bool:
2 changes: 1 addition & 1 deletion xcube_cds/version.py
Original file line number Diff line number Diff line change
@@ -20,4 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

version = '0.7.0'
version = '0.8.0.dev0'