Set a row, a range of rows or a slice in the array. It takes different actions depending on the type of the key parameter: if it is an integer, the corresponding array row is set to value (the value is broadcast when needed). If key is a slice, the row slice determi
(self, key: SelectionType, value: Any)
| 679 | return internal_to_flavor(arr, self.flavor) |
| 680 | |
| 681 | def __setitem__(self, key: SelectionType, value: Any) -> None: |
| 682 | """Set a row, a range of rows or a slice in the array. |
| 683 | |
| 684 | It takes different actions depending on the type of the key parameter: |
| 685 | if it is an integer, the corresponding array row is set to value (the |
| 686 | value is broadcast when needed). If key is a slice, the row slice |
| 687 | determined by it is set to value (as usual, if the slice to be updated |
| 688 | exceeds the actual shape of the array, only the values in the existing |
| 689 | range are updated). |
| 690 | |
| 691 | If value is a multidimensional object, then its shape must be |
| 692 | compatible with the shape determined by key, otherwise, a ValueError |
| 693 | will be raised. |
| 694 | |
| 695 | Furthermore, NumPy-style fancy indexing, where a list of indices in a |
| 696 | certain axis is specified, is also supported. Note that only one list |
| 697 | per selection is supported right now. Finally, NumPy-style point and |
| 698 | boolean selections are supported as well. |
| 699 | |
| 700 | Examples |
| 701 | -------- |
| 702 | :: |
| 703 | |
| 704 | a1[0] = 333 # assign an integer to an Integer Array row |
| 705 | a2[0] = 'b' # assign a string to a string Array row |
| 706 | a3[1:4] = 5 # broadcast 5 to slice 1:4 |
| 707 | a4[1:4:2] = 'xXx' # broadcast 'xXx' to slice 1:4:2 |
| 708 | |
| 709 | # General slice update (a5.shape = (4,3,2,8,5,10). |
| 710 | a5[1, ..., ::2, 1:4, 4:] = numpy.arange(1728, shape=(4,3,2,4,3,6)) |
| 711 | a6[1, [1,5,10], ..., -1] = arr # fancy selection |
| 712 | a7[np.where(a6[:] > 4)] = 4 # point selection + broadcast |
| 713 | a8[arr > 4] = arr2 # boolean selection |
| 714 | |
| 715 | """ |
| 716 | self._g_check_open() |
| 717 | |
| 718 | # Create an array compliant with the specified slice |
| 719 | nparr = convert_to_np_atom2(value, self.atom) |
| 720 | if nparr.size == 0: |
| 721 | return |
| 722 | |
| 723 | # truncate data if least_significant_digit filter is set |
| 724 | # TODO: add the least_significant_digit attribute to the array on disk |
| 725 | if ( |
| 726 | self.filters.least_significant_digit is not None |
| 727 | and not np.issubdtype(nparr.dtype, np.signedinteger) |
| 728 | ): |
| 729 | nparr = quantize(nparr, self.filters.least_significant_digit) |
| 730 | |
| 731 | try: |
| 732 | startl, stopl, stepl, shape = self._interpret_indexing(key) |
| 733 | self._write_slice(startl, stopl, stepl, shape, nparr) |
| 734 | except TypeError: |
| 735 | # Then, try with a point-wise selection |
| 736 | try: |
| 737 | coords = self._point_selection(key) |
| 738 | self._write_coords(coords, nparr) |
nothing calls this directly
no test coverage detected