mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-10-24 02:07:08 +02:00
Convert numpy integer and float scalars to Python numbers on insert, closes #876
This commit is contained in:
parent
6bc1d33d58
commit
3d90742d0d
2 changed files with 42 additions and 0 deletions
|
|
@ -5501,6 +5501,9 @@ class View(Queryable):
|
|||
def jsonify_if_needed(value: object) -> object:
|
||||
if isinstance(value, decimal.Decimal):
|
||||
return float(value)
|
||||
if np is not None and isinstance(value, (np.integer, np.floating)):
|
||||
# sqlite3 would otherwise store the raw buffer as a BLOB
|
||||
return cast(Any, value).item()
|
||||
if isinstance(value, (dict, list, tuple)):
|
||||
return json.dumps(value, default=repr, ensure_ascii=False)
|
||||
elif isinstance(value, (datetime.time, datetime.date, datetime.datetime)):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue