Skip to content

Conversation

@Giulero
Copy link
Collaborator

@Giulero Giulero commented Dec 21, 2025

This PR fixes the failing action https://github.com/gbionics/adam/actions/runs/20404127584 which fails the test idyntree_conversion with

/opt/hostedtoolcache/Python/3.11.14/x64/lib/python3.11/site-packages/adam/model/conversions/idyntree.py:23: in _to_sequence
    val = [float(v) for v in cs.DM(val).full()]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

.0 = <iterator object at 0x7f11ce7734c0>

>   val = [float(v) for v in cs.DM(val).full()]
           ^^^^^^^^
E   TypeError: only 0-dimensional arrays can be converted to Python scalars

I guess after the release https://numpy.org/news/#numpy-240-released

Indeed there was a deprecation warning before the release:

tests/test_idyntree_conversion.py: 6750 warnings
adam/src/adam/model/conversions/idyntree.py:23: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    val = [float(v) for v in cs.DM(val).full()]

tests/test_idyntree_conversion.py: 249 warnings
adam/src/adam/model/conversions/idyntree.py:42: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
    return float(val)

📚 Documentation preview 📚: https://adam-docs--147.org.readthedocs.build/en/147/

@Giulero Giulero changed the title Flatten casadi array after Numpy 2.4 release Fix casadi casadi conversion to array after Numpy 2.4 release Dec 21, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a compatibility issue with NumPy 2.4 that caused test failures in the idyntree_conversion module. The problem arose from deprecated NumPy behavior that converted multi-dimensional arrays to scalars, which now raises a TypeError.

Key changes:

  • Updated _to_sequence to properly flatten CasADi arrays using nested list comprehension
  • Modified _to_scalar to extract scalar values from 2D arrays before conversion to float

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Giulero Giulero mentioned this pull request Dec 21, 2025
@Giulero
Copy link
Collaborator Author

Giulero commented Dec 21, 2025

Thanks @traversaro ! Merging.

@Giulero Giulero merged commit e6ee6d8 into main Dec 21, 2025
12 checks passed
@Giulero Giulero deleted the fix-conversion branch December 21, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants