Skip to content

Test failure in test_umath.py::TestUmath::test_fix with NumPy 2.4 #266

@apdavison

Description

@apdavison
quantities/tests/test_umath.py F
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> traceback >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

self = array(3.14) * degF, obj = array(3.), context = (<ufunc 'trunc'>, (array(3.14) * degF,), 0)

    def __array_prepare__(self, obj, context=None):
        if self.__array_priority__ >= Quantity.__array_priority__:
            res = obj if isinstance(obj, type(self)) else obj.view(type(self))
        else:
            # don't want a UnitQuantity
            res = obj.view(Quantity)
        if context is None:
            return res

        uf, objs, huh = context
        if uf.__name__.startswith('is'):
            return obj

        try:
>           res._dimensionality = p_dict[uf](*objs)
                                  ^^^^^^^^^^
E           KeyError: <ufunc 'trunc'>

quantities/quantity.py:311: KeyError

During handling of the above exception, another exception occurred:

self = <quantities.tests.test_umath.TestUmath testMethod=test_fix>

    def test_fix(self):
>       self.assertQuantityEqual(np.fix(3.14 * pq.degF), 3.0 * pq.degF)
                                 ^^^^^^^^^^^^^^^^^^^^^^

quantities/tests/test_umath.py:163:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../env-202601/lib/python3.14/site-packages/numpy/lib/_ufunclike_impl.py:59: in fix
    return nx.trunc(x, out=out)
           ^^^^^^^^^^^^^^^^^^^^
quantities/quantity.py:331: in __array_wrap__
    return self.__array_prepare__(obj, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = array(3.14) * degF, obj = array(3.), context = (<ufunc 'trunc'>, (array(3.14) * degF,), 0)

    def __array_prepare__(self, obj, context=None):
        if self.__array_priority__ >= Quantity.__array_priority__:
            res = obj if isinstance(obj, type(self)) else obj.view(type(self))
        else:
            # don't want a UnitQuantity
            res = obj.view(Quantity)
        if context is None:
            return res

        uf, objs, huh = context
        if uf.__name__.startswith('is'):
            return obj

        try:
            res._dimensionality = p_dict[uf](*objs)
        except KeyError:
>           raise ValueError(
                """ufunc %r not supported by quantities
                please file a bug report at https://github.com/python-quantities
                """ % uf
                )
E           ValueError: ufunc <ufunc 'trunc'> not supported by quantities
E                           please file a bug report at https://github.com/python-quantities

quantities/quantity.py:313: ValueError

This seems to be because the implementation of np.fix was changed in NumPy 2.4 to use trunc (v2.3.5 v2.4.0)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions