8000 Is change in behavior of quantity.value for scalars deliberate? · Issue #9697 · astropy/astropy · GitHub
[go: up one dir, main page]

Skip to content
Is change in behavior of quantity.value for scalars deliberate? #9697
@timj

Description

@timj

Description

There is a change in behavior between Astropy 3.2 and Astropy 4.0 that is breaking some of our code. I'm flagging this in case it wasn't deliberate:

Astropy 3:

>>> import astropy.units as u
>>> import numpy
>>> a = 5 * u.s
>>> type(a.value)
<class 'float'>

Astropy 4

>>> import astropy.units as u
>>> import numpy
>>> a = 5 * u.s
>>> type(a.value)
<class 'numpy.float64'>

So for scalar quantities the type has changed from standard float to numpy float.

It's entirely possible that this is deliberate so that array values and scalar values have the same type. I was asked to file this on Slack just in case it was a side effect of something.

The impact for us is that something which serialized to YAML without any issue now breaks because YAML does not understand what to do with a numpy object. We can of course fix our code to trap this case.

cc/ @mhvk

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0