Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Commit 6dcd7f1

Browse files
authored
refactor(array): unify summary fn on diff backends (#230)
1 parent fda457b commit 6dcd7f1

7 files changed

Lines changed: 13 additions & 50 deletions

File tree

‎docarray/array/mixins/plot.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def summary(self):
3939
all_attrs = self._get_attributes('non_empty_fields')
4040
attr_counter = Counter(all_attrs)
4141

42-
table = Table(box=box.SIMPLE)
42+
table = Table(box=box.SIMPLE, highlight=True)
4343
table.show_header = False
4444
table.add_row('Length', str(len(self)))
4545
is_homo = len(attr_counter) == 1
@@ -77,7 +77,7 @@ def summary(self):
7777
all_attrs_names = tuple(sorted(all_attrs_names))
7878
if all_attrs_names:
7979

80-
attr_table = Table(box=box.SIMPLE)
80+
attr_table = Table(box=box.SIMPLE, highlight=True)
8181
attr_table.add_column('Attribute')
8282
attr_table.add_column('Data type')
8383
attr_table.add_column('#Unique values')
@@ -102,12 +102,18 @@ def summary(self):
102102

103103
storage_infos = self._get_storage_infos()
104104
if storage_infos:
105-
storage_table = Table(box=box.SIMPLE)
105+
storage_table = Table(box=box.SIMPLE, highlight=True)
106106
storage_table.show_header = False
107107
for k, v in storage_infos.items():
108108
storage_table.add_row(k, v)
109109

110-
tables.append(Panel(storage_table, title='Storage Summary', expand=False))
110+
tables.append(
111+
Panel(
112+
storage_table,
113+
title=f'[bold]{self.__class__.__name__}[/bold] Config',
114+
expand=False,
115+
)
116+
)
111117

112118
console.print(*tables)
113119

‎docarray/array/storage/annlite/backend.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,3 @@ def __setstate__(self, state):
9595
from annlite import AnnLite
9696

9797
self._annlite = AnnLite(n_dim, lock=False, **config)
98-
99-
def _get_storage_infos(self) -> Dict:
100-
return {
101-
'Backend': 'AnnLite',
102-
'Distance Metric': self._annlite.metric.name,
103-
'Data Path': self._config.data_path,
104-
'Serialization Protocol': self._config.serialize_config.get('protocol'),
105-
}

‎docarray/array/storage/base/backend.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import ABC
2+
from dataclasses import is_dataclass, asdict
23
from typing import Dict, Optional, TYPE_CHECKING
34

45
if TYPE_CHECKING:
@@ -16,7 +17,8 @@ def _init_storage(
1617
self._load_offset2ids()
1718

1819
def _get_storage_infos(self) -> Optional[Dict]:
19-
...
20+
if hasattr(self, '_config') and is_dataclass(self._config):
21+
return {k: str(v) for k, v in asdict(self._config).items()}
2022

2123
def _map_id(self, _id: str) -> str:
2224
return _id

‎docarray/array/storage/elastic/backend.py‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,6 @@ def _refresh(self, index_name):
122122
def _doc_id_exists(self, doc_id):
123123
return self._client.exists(index=self._config.index_name, id=doc_id)
124124

125-
def _get_storage_infos(self) -> Dict:
126-
return {
127-
'Backend': 'ElasticSearch',
128-
'Hosts': str(self._config.hosts),
129-
'ES config': str(self._config.es_config),
130-
'Distance': str(self._config.distance),
131-
'Vector dimension': str(self._config.n_dim),
132-
}
133-
134125
def _update_offset2ids_meta(self):
135126
"""Update the offset2ids in elastic"""
136127
if self._client.indices.exists(index=self._index_name_offset2id):

‎docarray/array/storage/qdrant/backend.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,6 @@ def _update_offset2ids_meta(self):
165165
),
166166
)
167167

168-
def _get_storage_infos(self) -> Dict:
169-
return {
170-
'Backend': 'Qdrant',
171-
'Host': self._config.host,
172-
'Port': str(self._config.port),
173-
'Collection Name': self.collection_name,
174-
'Distance': self._config.distance,
175-
'Serialization Protocol': self._config.serialize_config.get('protocol'),
176-
}
177-
178168
def _map_embedding(self, embedding: 'ArrayType') -> List[float]:
179169
if embedding is None:
180170
embedding = np.random.rand(self.n_dim)

‎docarray/array/storage/sqlite/backend.py‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,3 @@ def __setstate__(self, state):
134134
check_same_thread=False,
135135
**_conn_kwargs,
136136
)
137-
138-
def _get_storage_infos(self) -> Dict:
139-
return {
140-
'Backend': 'SQLite',
141-
'Connection': self._config.connection,
142-
'Table Name': self._table_name,
143-
'Serialization Protocol': self._config.serialize_config.get('protocol'),
144-
}

‎docarray/array/storage/weaviate/backend.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,6 @@ def _map_embedding(self, embedding: 'ArrayType'):
304304
embedding = None
305305
return embedding
306306

307-
def _get_storage_infos(self) -> Dict:
308-
return {
309-
'Backend': 'Weaviate',
310-
'Host': self._config.host,
311-
'Port': str(self._config.port),
312-
'Protocol': self._config.protocol,
313-
'Schema Name': self._config.name,
314-
'Serialization Protocol': self._config.serialize_config.get('protocol'),
315-
}
316-
317307
def __getstate__(self):
318308
d = dict(self.__dict__)
319309
del d['_client']

0 commit comments

Comments
 (0)