fix: better error message when docvec is unusable by JohannesMessner · Pull Request #1675 · docarray/docarray · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions docarray/array/any_array.py
10 changes: 9 additions & 1 deletion docarray/array/doc_vec/doc_vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(
f'docs = DocVec[MyDoc](docs) instead of DocVec(docs)'
)
self.tensor_type = tensor_type
self._is_unusable = False

tensor_columns: Dict[str, Optional[AbstractTensor]] = dict()
doc_columns: Dict[str, Optional['DocVec']] = dict()
Expand Down Expand Up @@ -769,7 +770,14 @@ def to_doc_list(self: T) -> DocList[T_doc]:

del self._storage

return DocList.__class_getitem__(self.doc_type).construct(docs)
doc_type = self.doc_type

# Setting _is_unusable will raise an Exception if someone interacts with this instance from hereon out.
# I don't like relying on this state, but we can't override the getattr/setattr directly:
# https://stackoverflow.com/questions/10376604/overriding-special-methods-on-an-instance
self._is_unusable = True

return DocList.__class_getitem__(doc_type).construct(docs)

def traverse_flat(
self,
Expand Down
Empty file added docarray/exceptions/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions docarray/exceptions/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class UnusableObjectError(NotImplementedError):
...
16 changes: 16 additions & 0 deletions tests/units/array/stack/test_array_stacked.py