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

Method __iter__

tables/expression.py:708–760  ·  view source on GitHub ↗

Iterate over the rows of the outcome of the expression. This iterator always returns rows as NumPy objects, so a possible out container specified in :meth:`Expr.set_output` method is ignored here.

(self)

Source from the content-addressed store, hash-verified

706 return out
707
708 def __iter__(self) -> Iterator[Row]:
709 """Iterate over the rows of the outcome of the expression.
710
711 This iterator always returns rows as NumPy objects, so a possible out
712 container specified in :meth:`Expr.set_output` method is ignored here.
713
714 """
715 values, shape, maindim = self.values, self.shape, self.maindim
716
717 # Get different info we need for the main computation loop
718 i_nrows, slice_pos, start, stop, step, nrowsinbuf = self._get_info(
719 shape, maindim, itermode=True
720 )
721
722 if i_nrows == 0:
723 # No elements to compute
724 return
725
726 # Create a key that selects every element in inputs
727 # (including the main dimension)
728 i_slices = [slice(None)] * (maindim + 1)
729
730 # This is a hack to prevent doing unnecessary flavor conversions
731 # while reading buffers
732 for val in values:
733 if hasattr(val, "maindim"):
734 val._v_convert = False
735
736 # Start the computation itself
737 for start2 in range(start, stop, step * nrowsinbuf):
738 stop2 = start2 + step * nrowsinbuf
739 if stop2 > stop:
740 stop2 = stop
741 # Set the proper slice in the main dimension
742 i_slices[maindim] = slice(start2, stop2, step)
743 # Get the values for computing the buffer
744 vals = []
745 for i, val in enumerate(values):
746 if i in slice_pos:
747 vals.append(val.__getitem__(tuple(i_slices)))
748 else:
749 # A read of values is not apparently needed, as PyTables
750 # leaves seems to work just fine inside Numexpr
751 vals.append(val)
752 # Do the actual computation
753 rout = self._compiled_expr(*vals)
754 # Return one row per call
755 yield from rout
756
757 # Activate the conversion again (default)
758 for val in values:
759 if hasattr(val, "maindim"):
760 val._v_convert = True
761
762
763if __name__ == "__main__":

Callers

nothing calls this directly

Calls 3

_get_infoMethod · 0.95
appendMethod · 0.45
__getitem__Method · 0.45

Tested by

no test coverage detected