Support for numpy types, closes #11 (#12)

This commit is contained in:
Simon Willison 2019-02-23 20:02:19 -08:00 committed by GitHub
commit e615d22c55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 0 deletions

View file

@ -5,6 +5,11 @@ import itertools
import json
import pathlib
try:
import numpy as np
except ImportError:
np = None
Column = namedtuple(
"Column", ("cid", "name", "type", "notnull", "default_value", "is_pk")
)
@ -70,6 +75,23 @@ class Database:
datetime.time: "TEXT",
None.__class__: "TEXT",
}
# If numpy is available, add more types
if np:
col_type_mapping.update(
{
np.int8: "INTEGER",
np.int16: "INTEGER",
np.int32: "INTEGER",
np.int64: "INTEGER",
np.uint8: "INTEGER",
np.uint16: "INTEGER",
np.uint32: "INTEGER",
np.uint64: "INTEGER",
np.float16: "FLOAT",
np.float32: "FLOAT",
np.float64: "FLOAT",
}
)
columns_sql = ",\n".join(
" [{col_name}] {col_type}{primary_key}{references}".format(
col_name=col_name,