MCPcopy Index your code
hub / github.com/PyTables/PyTables / _check_shape

Method _check_shape

tables/array.py:743–761  ·  view source on GitHub ↗

Test that nparr shape is consistent with underlying object. If not, try creating a new nparr object, using broadcasting if necessary.

(
        self, nparr: np.ndarray, slice_shape: tuple[int, ...]
    )

Source from the content-addressed store, hash-verified

741 self._write_selection(selection, reorder, shape, nparr)
742
743 def _check_shape(
744 self, nparr: np.ndarray, slice_shape: tuple[int, ...]
745 ) -> np.ndarray:
746 """Test that nparr shape is consistent with underlying object.
747
748 If not, try creating a new nparr object, using broadcasting if
749 necessary.
750
751 """
752 if nparr.shape != (slice_shape + self.atom.dtype.shape):
753 # Create an array compliant with the specified shape
754 narr = np.empty(shape=slice_shape, dtype=self.atom.dtype)
755
756 # Assign the value to it. It will raise a ValueError exception
757 # if the objects cannot be broadcast to a single shape.
758 narr[...] = nparr
759 return narr
760 else:
761 return nparr
762
763 def _read_slice(
764 self,

Callers 3

_write_sliceMethod · 0.95
_write_coordsMethod · 0.95
_write_selectionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected