Conversation
9eb4b38 to
12f962f
Compare
Codecov Report
@@ Coverage Diff @@
## main #79 +/- ##
==========================================
+ Coverage 82.85% 82.98% +0.13%
==========================================
Files 87 87
Lines 3815 3827 +12
==========================================
+ Hits 3161 3176 +15
+ Misses 654 651 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
d81bb73 to
5e09e7e
Compare
| def _del_docs_by_slice(self, _slice: slice): | ||
| del self._data[_slice] | ||
| self._rebuild_id2offset() | ||
| self._needs_id2offset_rebuild = True |
There was a problem hiding this comment.
change the _needs_id2offset_rebuild to a decorator?
There was a problem hiding this comment.
I changed it in the last commit, could you review ?
|
|
||
| def _init_storage( | ||
| self, _docs: Optional['DocumentArraySourceType'] = None, copy: bool = False | ||
| self, _docs: Optional["DocumentArraySourceType"] = None, copy: bool = False |
| def docs(): | ||
| return DocumentArray([Document(id=f"{i}") for i in range(1, 10)]) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "to_delete", | ||
| [ | ||
| 0, | ||
| 1, | ||
| 4, | ||
| -1, | ||
| list(range(1, 4)), | ||
| [2, 4, 7, 1, 1], | ||
| slice(0, 2), | ||
| slice(2, 4), | ||
| slice(4, -1), | ||
| [True, True, False], | ||
| ..., | ||
| ], | ||
| ) | ||
| def test_del_all(docs, to_delete): | ||
| doc_to_delete = docs[to_delete] | ||
| del docs[to_delete] | ||
| assert doc_to_delete not in docs | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ["deleted_ids", "expected_ids"], | ||
| [ | ||
| (["1", "2", "3", "4"], ["5", "6", "7", "8", "9"]), | ||
| (["2", "4", "7", "1"], ["3", "5", "6", "8", "9"]), | ||
| ], | ||
| ) |
There was a problem hiding this comment.
I already installed the pre-commit hook, this is already formatted by black
18af361 to
46a3633
Compare
46a3633 to
6621bc4
Compare
alaeddine-13
left a comment
There was a problem hiding this comment.
In general, I think that the operations that require rebuilding the id2offset are the delete and insert. Extend and append really don't require doing so. If we append/extend and the id2offset, is ready, then we update it efficiently without rebuilding, otherwise we don't update and wait for the next rebuilding
Co-authored-by: AlaeddineAbdessalem <[email protected]>
bd98fbe to
4426b61
Compare
Co-authored-by: AlaeddineAbdessalem <[email protected]>
4426b61 to
ddfa8a9
Compare
7620636 to
697cba0
Compare
| elif isinstance(_docs, DocumentArray): | ||
| self._data = _docs._data | ||
| self._id_to_index = _docs._id2offset |
There was a problem hiding this comment.
i think this part is wrong, not all DocumentArray has _id_to_index or _id2offset
There was a problem hiding this comment.
I agree, that was here before so I might be an other bug ? we should delete line 77 as the index _id_to_index will be automatically built on first call.
| if copy: | ||
| self._data = [Document(d, copy=True) for d in _docs] | ||
| self._rebuild_id2offset() | ||
| elif isinstance(_docs, DocumentArray): |
There was a problem hiding this comment.
| elif isinstance(_docs, DocumentArray): | |
| elif isinstance(_docs, DocumentArrayinMemory): |
hanxiao
left a comment
There was a problem hiding this comment.
wrong logic in copy constructor

Current version of docarray has a wrong behavior while deleting item via ids ==>
@JohannesMessner and I added some test to cover all of the del case from the documentation + a fix when deleting by ids