nulinspiratie / SilQ

Software for quantum control of donor atoms in silicon
Other
6 stars 1 forks source link

Qcodes: DataArray __setitem__ with negative index fails #214

Closed maij closed 4 years ago

maij commented 4 years ago
from qcodes import DataArray

da = DataArray(preset_data=[1,2,3,4])

for i in range(-4, 0):
    print(da[i]) # __getitem__ with negative indexing works fine.

da[0] = 99
da[-4] = 1 # Fails with ValueError

Output:

1
2
3
4
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-79-164452cd2a10> in <module>
      7 
      8 da[0] = 99
----> 9 da[-4] = 1

~/Documents/github/Qcodes/qcodes/data/data_array.py in __setitem__(self, loop_indices, value)
    337                     ((stop - start - 1)//step) * step)
    338 
--> 339         min_li = self.flat_index(min_indices, self._min_indices)
    340         max_li = self.flat_index(max_indices, self._max_indices)
    341         self._update_modified_range(min_li, max_li)

~/Documents/github/Qcodes/qcodes/data/data_array.py in flat_index(self, indices, index_fill)
    583         if len(indices) < len(self.shape):
    584             indices = indices + index_fill[len(indices):]
--> 585         return np.ravel_multi_index(tuple(zip(indices)), self.shape)[0]
    586 
    587     def _update_modified_range(self, low, high):

<__array_function__ internals> in ravel_multi_index(*args, **kwargs)

ValueError: invalid entry in coordinates array