File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -439,12 +439,21 @@ def upsert_dataframe(self,
439
439
if not isinstance (df , pd .DataFrame ):
440
440
raise ValueError (f"Only pandas dataframes are supported. Found: { type (df )} " )
441
441
442
- async_results = [
443
- self .upsert (vectors = chunk , namespace = namespace , async_req = True )
444
- for chunk in tqdm (self ._iter_dataframe (df , batch_size = batch_size ),
445
- total = len (df ) // batch_size , disable = not show_progress )
446
- ]
447
- res = [async_result .result () for async_result in async_results ]
442
+ pbar = tqdm (total = len (df ), disable = not show_progress , desc = "sending upsert requests" )
443
+ results = []
444
+ for chunk in self ._iter_dataframe (df , batch_size = batch_size ):
445
+ res = self .upsert (vectors = chunk , namespace = namespace , async_req = use_async_requests )
446
+ pbar .update (len (chunk ))
447
+ results .append (res )
448
+
449
+ if use_async_requests :
450
+ results = [async_result .result () for async_result in tqdm (results , desc = "collecting async responses" )]
451
+
452
+ upserted_count = 0
453
+ for res in results :
454
+ upserted_count += res .upserted_count
455
+
456
+ return UpsertResponse (upserted_count = upserted_count )
448
457
449
458
@staticmethod
450
459
def _iter_dataframe (df , batch_size ):
Original file line number Diff line number Diff line change @@ -214,12 +214,16 @@ def upsert_dataframe(self,
214
214
if not isinstance (df , pd .DataFrame ):
215
215
raise ValueError (f"Only pandas dataframes are supported. Found: { type (df )} " )
216
216
217
+ upserted_count = 0
217
218
pbar = tqdm (total = len (df ), disable = not show_progress )
218
219
for i in range (0 , len (df ), batch_size ):
219
220
batch = df .iloc [i :i + batch_size ].to_dict (orient = "records" )
220
- self .upsert (batch , namespace = namespace )
221
+ res = self .upsert (batch , namespace = namespace )
222
+ upserted_count += res .upserted_count
221
223
pbar .update (len (batch ))
222
224
225
+ return UpsertResponse (upserted_count = upserted_count )
226
+
223
227
@validate_and_convert_errors
224
228
def delete (self ,
225
229
ids : Optional [List [str ]] = None ,
You can’t perform that action at this time.
0 commit comments