NASA-Planetary-Science / sbpy

A Python package for small bodies research
https://sbpy.org/
Other
66 stars 34 forks source link

`DataClass.__setitem__` doesn't check column names #363

Closed jianyangli closed 1 year ago

jianyangli commented 2 years ago

High-level problem description Looks like the current implementation of DataClass.__setitem__ simply refers to self.table.__setitem__ without checking the column names. This would potentially cause alternative volume names as defined in Conf.fieldnames_info to be confused with each other.

What did you do?

import astropy.units as u
from sbpy.data import DataClass

d = DataClass.from_dict({'rh': [1, 2, 3] * u.au, 'delta': [1, 2, 3] * u.au})
assert d.field_names == ['rh', 'delta']
print(d['r'])  # print out <Quantity [1., 2., 3.] AU>
d['r'] = [4, 5, 6] * u.au
print(d['r'])  # print out <Quantity [4., 5., 6.] AU>
print(d['rh'])  # print out <Quantity [1., 2., 3.] AU>

I suspect this should be fixed, so that the column names will be translated first before being passed to self.table.__setitem__.

Provide information on your environment: operating system and version: [Linux (which distribution?), MacOS, Win] sbpy version: 0.3.1 astropy version: numpy version:

jianyangli commented 2 years ago

Again, @mkelley , I didn't follow the development of DataClass from the beginning, so I'm not sure if this should be fixed or it is an allowed behavior. Please advise. If a bug, I can work to fix it. Thanks.

mkelley commented 2 years ago

Good find, that is a problem!

jianyangli commented 2 years ago

OK, it should be an easy fix, and I'll do it.