Fix columns with falsy cells wrongly parsed as dates (#276)

Eg. before this commit, this table would result in Date columns:

| A     | B |
| ----- | -- |
| FALSE | 0 |

For now, even FALSE is parsed as Numeric (not sure why we don't have
a BooleanConverter).
This commit is contained in:
Yohan Boniface 2022-09-09 21:13:34 +02:00 committed by GitHub
parent c9a81ea7ea
commit 8bc5c7d595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

Binary file not shown.

View File

@ -189,5 +189,22 @@ class TestImportXLS(unittest.TestCase):
],
}])
def test_falsy_cells(self):
# Falsy cells should be parsed as Numeric, not Date.
parsed_file = import_xls.parse_file(*_get_fixture('test_falsy_cells.xlsx'))
tables = parsed_file[1]
self.assertEqual(tables, [{
'table_name': 'Sheet1',
'column_metadata': [
{'id': u'A', 'type': 'Numeric'},
{'id': u'B', 'type': 'Numeric'},
],
'table_data': [
[0, 0],
[0, 0],
],
}])
if __name__ == '__main__':
unittest.main()

View File

@ -83,7 +83,7 @@ class SimpleDateTimeConverter(BaseConverter):
def convert(cls, value):
if type(value) is datetime.datetime:
return value
elif not value:
elif value is None:
return None
raise ValueError()