Add `in` Operator for `DataClass`
jianyangli opened this issue · 0 comments
jianyangli commented
This is a request for
- a new feature
- an enhancement to existing sbpy functionality
- somethings else: [explain here]
The requested changes will be implemented by
- me
- the sbpy developers
High-level concept
sbpy.DataClass
allows aliases for column names for flexibility. A in
operator would be useful to extend the flexibility for the operations on fields.
Explain the relevance to sbpy
New feature to allow for better operability of sbpy.DataClass
.
Proposal details
Implement DataClass.__contains__
method to allow for in
operator. Make use of DataClass._translate_columns
method.
Example (pseudo-)code
from astropy.time import Time
from sbpy.data import Ephem
ceres = Ephem.from_horizons('ceres', epochs=Time('2022-01-01'))
print(ceres['rh']) # print [2.7183022] AU
print(ceres['r']) # print [2.7183022] AU
print('r' in eph.field_names) # print True
print('rh' in eph.field_names) # print False
# new feature will allow for both lines below to print `True`
print('r' in eph)
print('rh' in eph) # print False, but I hope this will print True