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

Method append

tables/index.py:755–817  ·  view source on GitHub ↗

Append the array to the index objects.

(self, xarr: list[np.ndarray], update: bool = False)

Source from the content-addressed store, hash-verified

753 return idx
754
755 def append(self, xarr: list[np.ndarray], update: bool = False) -> None:
756 """Append the array to the index objects."""
757 if profile:
758 tref = clock()
759 if profile:
760 show_stats("Entering append", tref)
761 if not update and self.temp_required:
762 where = self.tmp
763 # The reduction will take place *after* the optimization process
764 reduction = 1
765 else:
766 where = self
767 reduction = self.reduction
768 sorted_ = where.sorted
769 indices = where.indices
770 ranges = where.ranges
771 mranges = where.mranges
772 bounds = where.bounds
773 mbounds = where.mbounds
774 abounds = where.abounds
775 zbounds = where.zbounds
776 sorted_lr = where.sortedLR
777 indices_lr = where.indicesLR
778 nrows = sorted_.nrows # before sorted.append()
779 larr, arr, idx = self.initial_append(xarr, nrows, reduction)
780 # Save the sorted array
781 sorted_.append(arr.reshape(1, arr.size))
782 cs = self.chunksize // reduction
783 ncs = self.nchunkslice
784 # Save ranges & bounds
785 ranges.append([[arr[0], larr]])
786 bounds.append([arr[cs::cs]])
787 abounds.append(arr[0::cs])
788 zbounds.append(arr[cs - 1 :: cs])
789 # Compute the medians
790 smedian = arr[cs // 2 :: cs]
791 mbounds.append(smedian)
792 mranges.append([smedian[ncs // 2]])
793 if profile:
794 show_stats("Before deleting arr & smedian", tref)
795 del arr, smedian # delete references
796 if profile:
797 show_stats("After deleting arr & smedian", tref)
798 # Now that arr is gone, we can upcast the indices and add the offset
799 if self.indsize == 4:
800 idx = self.final_idx32(idx, nrows * self.slicesize)
801 indices.append(idx.reshape(1, idx.size))
802 if profile:
803 show_stats("Before deleting idx", tref)
804 del idx
805 # Update counters after a successful append
806 self.nrows = nrows + 1
807 self.nelements = self.nrows * self.slicesize
808 self.nelementsSLR = 0 # reset the counter of the last row index to 0
809 self.nelementsILR = 0 # reset the counter of the last row index to 0
810 # The number of elements will be saved as an attribute.
811 # This is necessary in case the LR arrays can remember its values
812 # after a possible node preemtion/reload.

Callers 3

cleanup_tempMethod · 0.45
searchMethod · 0.45
__str__Method · 0.45

Calls 3

initial_appendMethod · 0.95
final_idx32Method · 0.95
show_statsFunction · 0.70

Tested by

no test coverage detected