Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of a slice tuple for numpy 1.23 #2726

Merged
merged 1 commit into from
Jun 3, 2022

Conversation

adeak
Copy link
Member

@adeak adeak commented Jun 1, 2022

NumPy 1.23 is almost out.

This is in NumPy 1.22:

>>> import numpy as np
>>> np.arange(3)[[slice(None)]]
<stdin>:1: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
array([0, 1, 2])

And as promised, this raises in NumPy 1.23.0rc2:

>>> import numpy as np
>>> np.arange(3)[[slice(None)]]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

The poblem is that multidimensional indices like arr[i, j, k] are syntactical sugar for tuples: arr[(i, j, k)]. Using a list instead as in arr[[i, j, k]] should trigger advanced (fancy) indexing. There used to be some leeway that interpreted the latter as the former when a 1d fancy index with the wrong length equal to the number of dimensions was found, and this magic is what was deprecated in favour of writing more exact code.

We had two test failures (with one source) due to this, which has a simple fix.

@adeak adeak added the bug Uh-oh! Something isn't working as expected. label Jun 1, 2022
Copy link
Member

@akaszynski akaszynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@codecov
Copy link

codecov bot commented Jun 1, 2022

Codecov Report

Merging #2726 (6d9260f) into main (6eb0b23) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #2726   +/-   ##
=======================================
  Coverage   93.77%   93.77%           
=======================================
  Files          76       76           
  Lines       16168    16169    +1     
=======================================
+ Hits        15161    15162    +1     
  Misses       1007     1007           

@akaszynski akaszynski merged commit aa73d6b into pyvista:main Jun 3, 2022
@adeak adeak mentioned this pull request Jun 29, 2022
4 tasks
akaszynski added a commit that referenced this pull request Jun 30, 2022
* Fix imports of vtkExtractEdges and vtkCellTreeLocator (#2585)

These classes have been moved and imports failed. This checks for VTK versions/builds and imports them accordingly.

* Implement fixes for VTK 9.2.0rc (#2863)

* add fixes for py310

* add windows and mac to testing

* improve coverage

* Update pyvista/core/filters/data_set.py

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>

* add crushed can example

Co-authored-by: Andras Deak <adeak@users.noreply.github.com>

* bump to v0.34.2

* don't use cache

* Fix use of a slice tuple for numpy 1.23 (#2726)

* remove more cache

Co-authored-by: Håkon Strandenes <h.strandenes@km-turbulenz.no>
Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Uh-oh! Something isn't working as expected.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants