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

Calling len() on the scipy.spatial.transform.rotation.Rotation object with one rotation should return 1 #13452

Closed
MatusGasparik opened this issue Jan 29, 2021 · 3 comments · Fixed by #16722
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial
Milestone

Comments

@MatusGasparik
Copy link

MatusGasparik commented Jan 29, 2021

When calling the len() function on the scipy.spatial.transform.rotation.Rotation object with exactly one rotation, it currently raises a TypeError instead of returning 1.

(Link to source code)

Reproducing code example:

from scipy.spatial.transform import Rotation as R

r = R.from_quat([1, 0, 0, 0])
print(len(r))    # raises TypeError

Error message:

TypeError                                 Traceback (most recent call last)
<ipython-input-227-c5f861eb1f8a> in <module>
      4 try:
----> 5     print(len(r))
      6 except Exception as e:

rotation.pyx in scipy.spatial.transform.rotation.Rotation.__len__()

TypeError: Single rotation has no len().

Calling len() on an object with 2 rotations returns 2 as expected:

r = R.from_quat([[1, 0, 0, 0],
                 [1, 0, 0, 0]])
print(len(r))    # returns 2

Moreover, when creating a rotation object using the from_euler() class method, it correctly returns 1 for one rotation around a single coordinate axis, but raises the above error again for a rotation around more than one coordinate axes:

r = R.from_euler('x', [0.1])
print(len(r))    # returns 1

r = R.from_euler('xz', [0.1, 0.1])
print(len(r))    # raises TypeError

Scipy/Numpy/Python version information:

import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
1.6.0 1.19.5 sys.version_info(major=3, minor=9, micro=1, releaselevel='final', serial=0)
@AtsushiSakai
Copy link
Member

I think the answer to this issue is in #12398

@rgommers
Copy link
Member

This still works this way and seems inconsistent. I don't immediately see how gh-12398 answers whether this is intended or not - looks like a bug to me.

@rgommers rgommers added the defect A clear bug or issue that prevents SciPy from being installed or used as expected label Feb 22, 2022
@WarrenWeckesser
Copy link
Member

Based on the comments in #16663 (#16663 (comment) in particular) I think this is intended behavior. r = Rotation([1, 0, 0, 0]) is like a scalar rotation, so the object has no length, and len(r) should raise a TypeError. r2 = Rotation([[1, 0, 0, 0], [0, 1, 0, 0]]) is like a sequence of two rotations, and len(r2) is 2.

If my interpretation is correct, we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.spatial
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants