MCPcopy Create free account
hub / github.com/PyTables/PyTables / cleanup_temp

Method cleanup_temp

tables/index.py:1324–1383  ·  view source on GitHub ↗

Copy the data and delete the temporaries for sorting purposes.

(self)

Source from the content-addressed store, hash-verified

1322 )
1323
1324 def cleanup_temp(self) -> None:
1325 """Copy the data and delete the temporaries for sorting purposes."""
1326 if self.verbose:
1327 print("Copying temporary data...")
1328 # tmp -> index
1329 reduction = self.reduction
1330 cs = self.chunksize // reduction
1331 ncs = self.nchunkslice
1332 tmp = self.tmp
1333 for i in range(self.nslices):
1334 # Copy sorted & indices slices
1335 sorted_ = tmp.sorted[i][::reduction].copy()
1336 self.sorted.append(sorted_.reshape(1, sorted_.size))
1337 # Compute ranges
1338 self.ranges.append([[sorted_[0], sorted_[-1]]])
1339 # Compute chunk bounds
1340 self.bounds.append([sorted_[cs::cs]])
1341 # Compute start, stop & median bounds and ranges
1342 self.abounds.append(sorted_[0::cs])
1343 self.zbounds.append(sorted_[cs - 1 :: cs])
1344 smedian = sorted_[cs // 2 :: cs]
1345 self.mbounds.append(smedian)
1346 self.mranges.append([smedian[ncs // 2]])
1347 del sorted_, smedian # delete references
1348 # Now that sorted is gone, we can copy the indices
1349 indices = tmp.indices[i]
1350 self.indices.append(indices.reshape(1, indices.size))
1351
1352 # Now it is the last row turn (if needed)
1353 if self.nelementsSLR > 0:
1354 # First, the sorted values
1355 sorted_lr = self.sortedLR
1356 indices_lr = self.indicesLR
1357 nelements_lr = self.nelementsILR
1358 sortedlr = tmp.sortedLR[:nelements_lr][::reduction].copy()
1359 nelements_slr = len(sortedlr)
1360 sorted_lr[:nelements_slr] = sortedlr
1361 # Now, the bounds
1362 self.bebounds = np.concatenate((sortedlr[::cs], [sortedlr[-1]]))
1363 offset2 = len(self.bebounds)
1364 sorted_lr[nelements_slr : nelements_slr + offset2] = self.bebounds
1365 # Finally, the indices
1366 indices_lr[:] = tmp.indicesLR[:]
1367 # Update the number of (reduced) sorted elements
1368 self.nelementsSLR = nelements_slr
1369 # The number of elements will be saved as an attribute
1370 self.sortedLR.attrs.nelements = self.nelementsSLR
1371 self.indicesLR.attrs.nelements = self.nelementsILR
1372
1373 if self.verbose:
1374 print("Deleting temporaries...")
1375 self.tmp = None
1376 self.tmpfile.close()
1377 Path(self.tmpfilename).unlink()
1378 self.tmpfilename = None
1379
1380 # The optimization process has finished, and the index is ok now
1381 self.dirty = False

Callers 1

optimizeMethod · 0.95

Calls 3

copyMethod · 0.45
appendMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected