Skip to content

Commit bfebad6

Browse files
authored
fix: DocVec display (docarray#1522)
Signed-off-by: AnneY <evangeline-lun@foxmail.com>
1 parent 096f644 commit bfebad6

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

docarray/array/doc_vec/column_storage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,6 @@ def __iter__(self):
140140

141141
def __len__(self):
142142
return len(self.storage.columns)
143+
144+
def keys(self):
145+
return self.storage.columns.keys()

docarray/base_doc/doc.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,17 @@ def _get_field_type(cls, field: str) -> Type:
104104
return cls.__fields__[field].outer_type_
105105

106106
def __str__(self) -> str:
107+
content: Any = None
108+
if self.is_view():
109+
attr_str = ", ".join(
110+
f"{field}={self.__getattr__(field)}" for field in self.__dict__.keys()
111+
)
112+
content = f"{self.__class__.__name__}({attr_str})"
113+
else:
114+
content = self
115+
107116
with _console.capture() as capture:
108-
_console.print(self)
117+
_console.print(content)
109118

110119
return capture.get().strip()
111120

tests/units/document/test_view.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ class MyDoc(BaseDoc):
1313

1414
docs = [MyDoc(tensor=np.zeros((10, 10)), name='hello', id=i) for i in range(4)]
1515

16-
storage = DocVec[MyDoc](docs)._storage
16+
doc_vec = DocVec[MyDoc](docs)
17+
storage = doc_vec._storage
18+
19+
result = str(doc_vec[0])
20+
assert 'MyDoc' in result
21+
assert 'id' in result
22+
assert 'tensor' in result
23+
assert 'name' in result
1724

1825
doc = MyDoc.from_view(ColumnStorageView(0, storage))
1926
assert doc.is_view()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy