Skip to content
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
14 changes: 8 additions & 6 deletions docarray/array/storage/base/getsetdel.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,13 @@ def _update_subindices_set(self, set_index, docs):
_check_valid_values_nested_set(self[set_index], docs)
if set_index in subindices:
subindex_da = subindices[set_index]
with subindex_da:
subindex_da.clear()
subindex_da.extend(docs)
subindex_da.clear()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand the problem, maybe a more clear description of the problem would clarify the scope

Copy link
Copy Markdown
Member

@JohannesMessner JohannesMessner Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is the usage of the context manager for subindices. It is used "all the time", even if the main (parent) da does not use it, so subindex offset2ids are always synced, and there is no control over it.

This change undoes this, and instead ties the syncing of the subindices to the syncing of the parent, by making .sync() operate on all the subindices. I like it.

subindex_da.extend(docs)
else: # root level set, update subindices iteratively
for subindex_selector, subindex_da in subindices.items():
old_ids = DocumentArray(self[set_index])[subindex_selector, 'id']
with subindex_da:
del subindex_da[old_ids]
subindex_da.extend(DocumentArray(docs)[subindex_selector])
del subindex_da[old_ids]
subindex_da.extend(DocumentArray(docs)[subindex_selector])

def _set_docs(self, ids, docs: Iterable['Document']):
docs = list(docs)
Expand Down Expand Up @@ -328,3 +326,7 @@ def _save_offset2ids(self):
def sync(self):
if hasattr(self, '_offset2ids'):
self._save_offset2ids()

if getattr(self, '_subindices', None):
for selector, da in self._subindices.items():
da.sync()