@@ -93,12 +93,7 @@ def _load_binary_stream(
9393
9494 from .... import Document
9595
96- if _show_progress :
97- from rich .progress import track as _track
98-
99- track = lambda x : _track (x , description = 'Deserializing' )
100- else :
101- track = lambda x : x
96+ from rich .progress import track
10297
10398 with file_ctx as f :
10499 version_numdocs_lendoc0 = f .read (9 )
@@ -107,7 +102,9 @@ def _load_binary_stream(
107102 # 8 bytes (uint64)
108103 num_docs = int .from_bytes (version_numdocs_lendoc0 [1 :9 ], 'big' , signed = False )
109104
110- for _ in track (range (num_docs )):
105+ for _ in track (
106+ range (num_docs ), description = 'Deserializing' , disable = not _show_progress
107+ ):
111108 # 4 bytes (uint32)
112109 len_current_doc_in_bytes = int .from_bytes (
113110 f .read (4 ), 'big' , signed = False
@@ -155,18 +152,14 @@ def _load_binary_all(
155152 version = int .from_bytes (d [0 :1 ], 'big' , signed = False )
156153 # 8 bytes (uint64)
157154 num_docs = int .from_bytes (d [1 :9 ], 'big' , signed = False )
158- if show_progress :
159- from rich .progress import track as _track
160155
161- track = lambda x : _track (x , description = 'Deserializing' )
162- else :
163- track = lambda x : x
156+ from rich .progress import track
164157
165158 # this 9 is version + num_docs bytes used
166159 start_pos = 9
167160 docs = []
168161
169- for _ in track (range (num_docs )):
162+ for _ in track (range (num_docs ), disable = not show_progress ):
170163 # 4 bytes (uint32)
171164 len_current_doc_in_bytes = int .from_bytes (
172165 d [start_pos : start_pos + 4 ], 'big' , signed = False
@@ -280,12 +273,6 @@ def to_bytes(
280273 f .write (pickle .dumps (self ))
281274 elif protocol in ('pickle' , 'protobuf' ):
282275 # Binary format for streaming case
283- if _show_progress :
284- from rich .progress import track as _track
285-
286- track = lambda x : _track (x , description = 'Serializing' )
287- else :
288- track = lambda x : x
289276
290277 # V1 DocArray streaming serialization format
291278 # | 1 byte | 8 bytes | 4 bytes | variable | 4 bytes | variable ...
@@ -296,7 +283,11 @@ def to_bytes(
296283 num_docs_as_bytes = len (self ).to_bytes (8 , 'big' , signed = False )
297284 f .write (version_byte + num_docs_as_bytes )
298285
299- for d in track (self ):
286+ from rich .progress import track
287+
288+ for d in track (
289+ self , description = 'Serializing' , disable = not _show_progress
290+ ):
300291 # 4 bytes (uint32)
301292 doc_as_bytes = d .to_bytes (protocol = protocol , compress = compress )
302293
0 commit comments