sot / astromon

Astrometric accuracy (celestial location) monitor
0 stars 0 forks source link

Make code for writing tables require all the expected columns #23

Closed taldcroft closed 2 years ago

taldcroft commented 2 years ago

If I'm understanding correctly this code worries me:

        dtype = DTYPES[table_name]
        names = [n for n in dtype.names if n in data.dtype.names]
        if len(names) == 0:
            raise Exception('Input data has no columns in common with table in DB')
        b = np.zeros(len(data), dtype=dtype)
        b[names] = data[names].as_array().astype(dtype[names])
        data = b

It basically says that the calling function can supply a data table that does not have the expected columns and the missing columns will silently be filled with zeros. I think that finding the expected columns should be required. The following code does this (I think):

dtype = DTYPES[table_name]
data = data[dtype.names].as_array().astype(dtype)
javierggt commented 2 years ago

I added code to check this (in my local copy) and this brings up another issue.

The fields in the dtypes were set more or less following the previous astromon, but at some point we decided we do not care about being compatible. The following fields are currently not being set, so I should set them to default values, set them to proper values or remove the column altogether:

taldcroft commented 2 years ago

My inclination is cutting the column names that are not defined. Keep it simple and don't put in scaffolding that we don't obviously need.