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, ...]
)
| 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, |
no outgoing calls
no test coverage detected