django-daiquiri / daiquiri

A framework for the publication of scientific databases
https://escience.aip.de/daiquiri
Apache License 2.0
26 stars 8 forks source link

BUG: upload fails with "char" types #156

Open agy-why opened 1 year ago

agy-why commented 1 year ago

When a field is of type char the upload process breaks here: https://github.com/django-daiquiri/daiquiri/blob/master/daiquiri/core/adapter/database/base.py#L338

This is due to the fact that parse_single_table from astropy reads char fields as built-in string and not as numpy._str, which leads to no dtype attribute.

agy-why commented 1 year ago
def _escape_cell(self, cell, mask_cell=None):
        if mask_cell:
            return 'NULL'
        else:
            if type(cell) == str:
                # chars need to be decoded
                value = cell.decode()
            elif cell.dtype.char == 'S':
                # chars need to be decoded
                value = cell.decode()
            elif cell.dtype.char == '?':
                # booleans need to be converted to 0 or 1, or quoting will fail
                value = 1 if cell else 0
            else:
                value = cell

            return self.escape_string(value)