Skip to content

Adding empty quantity to time raises misleading error in 6.0rc1 #15601

Description

@maxnoe

Description

Testing the 6.0rc1, there was a change in behavior for adding empty quantities to time:
5.x:

 >>> Time.now() + [] * u.s
 <Time object: scale='utc' format='datetime' value=[]>

6.0 raises an error that is misleading, as the problem is the dimensionality of the quantity, not the missing function implementation:

 >>> Time.now() + [] * u.s
 Traceback (most recent call last):
   File "/home/maxnoe/.local/conda/envs/astropy5/lib/python3.11/site-packages/astropy/units/quantity_helper/converters.py", line 196, in converters_and_unit
     if can_have_arbitrary_unit(args[i]):
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/home/maxnoe/.local/conda/envs/astropy5/lib/python3.11/site-packages/astropy/units/quantity_helper/converters.py", line 138, in can_have_arbitrary_unit
     return np.all(np.logical_or(np.equal(value, 0.0), ~np.isfinite(value)))
                                                        ^^^^^^^^^^^^^^^^^^
 TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/home/maxnoe/.local/conda/envs/astropy5/lib/python3.11/site-packages/astropy/units/quantity.py", line 691, in __array_ufunc__
     raise e
   File "/home/maxnoe/.local/conda/envs/astropy5/lib/python3.11/site-packages/astropy/units/quantity.py", line 636, in __array_ufunc__
     converters, unit = converters_and_unit(function, method, *inputs)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/home/maxnoe/.local/conda/envs/astropy5/lib/python3.11/site-packages/astropy/units/quantity_helper/converters.py", line 207, in converters_and_unit
     raise TypeError(
 TypeError: Unsupported operand type(s) for ufunc add: 'Time,Quantity'

Expected behavior

Either stick with the 5.x behavior (empty time object) or raise a more helpful error message.

How to Reproduce

Time.now() + [] * u.s

Versions

astropy 6.0.0rc1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions