Skip to content

Commit

Permalink
Merge pull request #1110 from xcube-dev/yogesh-1109-modify-include_at…
Browse files Browse the repository at this point in the history
…trs-type

Enhance include_attrs type
  • Loading branch information
b-yogesh authored Jan 21, 2025
2 parents 0a5466a + 7b9f6dd commit 9d4d5a0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
# Filesystem-specific storage options
# StorageOptions: ...
```
* The `get_data_ids()` method in `DataStore` has an enhanced `include_attrs` parameter.
Previously accepting only `Container[str]`, it now also supports a `bool` value.
Setting `include_attrs` to `True` retrieves all attributes of the data_ids.

* Updated dependency `urllib3` to be `>=2.0`.

### Fixes

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies:
- shapely >=1.6
- tabulate >=0.9
- tornado >=6.0
- urllib3 >=1.26
- urllib3 >=2.0
- xarray >=2024.7
- zarr >=2.11,<3 # until we can ensure zarr 3 compatibility; see Issue #1102
# Chartlets
Expand Down
6 changes: 4 additions & 2 deletions xcube/core/store/fs/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,13 @@ def get_data_types_for_data(self, data_id: str) -> tuple[str, ...]:
return tuple(data_type_aliases)

def get_data_ids(
self, data_type: DataTypeLike = None, include_attrs: Container[str] = None
self,
data_type: DataTypeLike = None,
include_attrs: Container[str] | bool = False,
) -> _DataIds:
data_type = DataType.normalize(data_type)
# TODO: do not ignore names in include_attrs
return_tuples = include_attrs is not None
return_tuples = include_attrs is not False
data_ids = self._generate_data_ids("", data_type, return_tuples, 1)
if self._includes or self._excludes:
yield from self._filter_data_ids(data_ids, return_tuples)
Expand Down
4 changes: 3 additions & 1 deletion xcube/core/store/ref/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def get_data_types_for_data(self, data_id: str) -> tuple[str, ...]:
return self.get_data_types()

def get_data_ids(
self, data_type: DataTypeLike = None, include_attrs: Container[str] = None
self,
data_type: DataTypeLike = None,
include_attrs: Container[str] | bool = False,
) -> Union[Iterator[str], Iterator[tuple[str, dict[str, Any]]]]:
return iter(self._refs.keys())

Expand Down
25 changes: 18 additions & 7 deletions xcube/core/store/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def get_data_types_for_data(self, data_id: str) -> tuple[str, ...]:

@abstractmethod
def get_data_ids(
self, data_type: DataTypeLike = None, include_attrs: Container[str] = None
self,
data_type: DataTypeLike = None,
include_attrs: Container[str] | bool = False,
) -> Union[Iterator[str], Iterator[tuple[str, dict[str, Any]]]]:
"""Get an iterator over the data resource identifiers for the
given type *data_type*. If *data_type* is omitted, all data
Expand All @@ -217,8 +219,12 @@ def get_data_ids(
Hence, the type of the returned iterator items depends on the
value of *include_attrs*:
- If *include_attrs* is None (the default), the method returns
- If *include_attrs* is False (the default), the method returns
an iterator of dataset identifiers *data_id* of type `str`.
- If *include_attrs* is True, the method returns an iterator of tuples
(*data_id*, *attrs*) of type `Tuple[str, Dict]`, where *attrs*
is a dictionary filled with all the attributes available respectively
for each *data_id*.
- If *include_attrs* is a sequence of attribute names, even an
empty one, the method returns an iterator of tuples
(*data_id*, *attrs*) of type `Tuple[str, Dict]`, where *attrs*
Expand Down Expand Up @@ -254,7 +260,9 @@ def get_data_ids(
"""

def list_data_ids(
self, data_type: DataTypeLike = None, include_attrs: Container[str] = None
self,
data_type: DataTypeLike = None,
include_attrs: Container[str] | bool = False,
) -> Union[list[str], list[tuple[str, dict[str, Any]]]]:
"""Convenience version of `get_data_ids()` that returns a list rather
than an iterator.
Expand All @@ -263,11 +271,14 @@ def list_data_ids(
data_type: If given, only data identifiers that are
available as this type are returned. If this is omitted,
all available data identifiers are returned.
include_attrs: A sequence of names of attributes to be
returned for each dataset identifier. If given, the
store will attempt to provide the set of requested
include_attrs: A boolean or sequence of names of attributes to be
returned for each dataset identifier. If a sequence of names of
attributes given, the store will attempt to provide the set of requested
dataset attributes in addition to the data ids. (added
in xcube 0.8.0)
in xcube 0.8.0).
If True, all the attributes for each dataset identifier will be
returned.
If False (default), only the data_ids are returned.
Returns:
A list comprising the identifiers and titles of data
Expand Down

0 comments on commit 9d4d5a0

Please sign in to comment.