CompositeUnit from SBDB
- Dominant language
- Python
- Stars
- 791
- Forks
- 451
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 4
Description
I wanted to query some information for many asteroids and make a DataFrame, but found it very annoying as astroquery uses CompositeUnit:
```python
from astroquery.jplsbdb import SBDB
import pandas as pd
import astroquery
import astropy
print(astroquery.__version__)
# 0.4.1.dev5959
print(pd.__version__)
# 1.0.2
print(astropy.__version__)
# 4.0
sbdbs = {}
astnums = [1, 2, 3, 944]
for num in astnums:
sb = SBDB.query(num, phys=True)
phys = sb['phys_par']
obj = sb['object']
sbdbs[num] = dict(
num=obj['des'],
fullname=obj['fullname'],
diam=phys['diameter'],
diam_sig=phys['diameter_sig'],
)
df = pd.DataFrame.from_dict(sbdbs).T
diams = df['diam']
df
```
The ``df`` looks like this:

It's fine until here, but I cannot extract the diameters as **useful** numpy ndarray. I tried ``diams.values``, but it contained all objects such as ``Unit("939.4 km")``, so I cannot use ``diams.values`` for plotting, etc. If I try plotting by ``plt.plot(df['diam'], df['diam_sig'])``, an error comes: ``TypeError: float() argument must be a string or a number, not 'CompositeUnit'
``.
Of course I can do something like ``diam=phys['diameter'].to('km')`` in the for loop, but I cannot use this workaround directly (i.e., without ``if`` or ``try``/``except``) for ``diameter_sig``, because Hidalgo has it ``None``. Also I don't want to specify ``.to()`` for all physical parameters I want...
Did I do something wrong/inefficient? Is there any easy way to convert all CompositeUnit to plain float? Or can I do a batch query? Or more straightforwardly, can I just **not** use astropy units (such as options like ``return_unit=False``)?
EDIT: I cannot use .value to CompositeUnit.
Contributor guide
Research direction
Start by reviewing the SBDB.query entry point and the shown pandas DataFrame conversion, then inspect how physical parameters and missing diameter_sig values are represented. Clarify whether the intended result is unit conversion, plain numeric output, batch querying, or an option to disable units, and define tests covering mixed units and None values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100