Skip to content

Warn when using ufuncs on a Column with units set? #20474

Description

@adrn

This is very related to #15300: it is confusing for users that Column has a unit attribute that is ignored in operations.

A few examples:

Treats values as radians even though the units are degrees:

>>> import astropy.table as at
>>> import numpy as np
>>> col1 = at.Column([1., 2., 3], unit="deg")
>>> np.sin(col1).value
array([0.84147098, 0.90929743, 0.14112001])
>>> np.sin(np.deg2rad(col1.value))
array([0.01745241, 0.0348995 , 0.05233596])

Ignores units in operations, but still returns a column with the unit of the first operand:

>>> col2 = at.Column([1., 2., 3], unit="rad")
>>> col1 + col2
<Column dtype='float64' unit='deg' length=3>
2.0
4.0
6.0

(and etc. for other operations, like multiplication)

However, if you do an operation between a Column with a unit and a Quantity, the units are used and we get a Quantity out:

>>> import astropy.units as u
>>> col1 * 5 * u.m
<Quantity [ 5., 10., 15.] deg m>

I think I'm in favor of adding a warning and suggestion to use QTable instead. I think we could just add this check to BaseColumn.__array_wrap__?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions