Skip to content

Fix: shift_slice to accept single slices as argument, and return tuples

Frederik Hennig requested to merge da15siwa/pystencils:fix_slicing into master

Two fixes to pystencils.slicing.shift_slice:

  • Previously, shift_slice assumed its argument slices to be iterable. Thus, it did not accept single slices as arguments. There are use cases, though, where it is necessary to shift a plain slice object, or even int or float objects which can also be seen as slices. An additional isinstance check takes care of this.
  • Previously, shift_slice returned lists of slices. By default, Python wraps multidimensional slices as tuples. Code for manipulating multidimensional slices thus expects them to be given as tuples. Also, although it is currently possible to access numpy arrays with lists of slices instead of tuples, this action produces a deprecation warning. Thus, shift_slice is changed to return tuples.

An additional test case evaluating array accesses with shifted slices is also added.

Merge request reports