scipy: BUG: `bool(rotation)` leads to error

Describe your issue.

Maybe it’s undefined behavior, but calling bool on an instance of scipy.spatial.transform.Rotation yields an unclear error.

Perhaps any identity rotations could be Falsy, and anything else be truthy? (That’s also why I tried bool on it)

Reproducing Code Example

from scipy.spatial.transform import Rotation
bool(Rotation.from_euler("x", 0))

Error message

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_rotation.pyx", line 563, in scipy.spatial.transform._rotation.Rotation.__len__
TypeError: Single rotation has no len().

SciPy/NumPy/Python version information

1.8.1 1.22.2 sys.version_info(major=3, minor=9, micro=9, releaselevel=‘final’, serial=0)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (14 by maintainers)

Most upvoted comments

Nice digging on the reasons of the len TypeError. While it settles len, and might warrant these extra tests to cement them (preferably with links to these issues), it still leaves bool up to discussion. Even though for good reasons it turns out you can’t check the length of a single rotation, it doesn’t seem like there’s reason to bar its truth value as a generic Python object to be consistently assessed.

  def __bool__(self):
    # Link to this issue
    return True

? 🙂