Skip to content

Commit

Permalink
Allow range reads on non-list dataset keys
Browse files Browse the repository at this point in the history
  • Loading branch information
danijar committed Oct 15, 2024
1 parent d74f31a commit b92a3e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion granular/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.20.0'
__version__ = '0.20.2'

from .bag import BagWriter
from .bag import BagReader
Expand Down
9 changes: 5 additions & 4 deletions granular/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ def __getitem__(self, index):
assert 0 <= index.start <= index.stop and index.step in (None, 1), index
refs = self._getrefs(index.start, index.stop)
for i, (key, dtype) in enumerate(self.spec.items()):
ref, msk = [x[i] for x in refs], mask.get(key, False)
# Cannot range read datapoints that contain sequence modalities,
# because they may not be consecutive and thus could be slow.
assert not dtype.endswith('[]'), (index, key, dtype)
ref, msk = [x[i] for x in refs], mask.get(key, False)
assert isinstance(msk, bool), (key, msk, type(msk))
if msk:
needed[key] = range(ref[0], ref[-1] + 1)
assert not (msk and dtype.endswith('[]')), (index, key, dtype)
if not msk:
continue
needed[key] = range(ref[0], ref[-1] + 1)
points = self._fetch(needed)
decoded = {
k: [self._decode(k, v, self.spec[k]) for v in vs]
Expand Down

0 comments on commit b92a3e4

Please sign in to comment.