-
Notifications
You must be signed in to change notification settings - Fork 253
Description
When constructing an entity instance, a numpy integer type (eg np.int64) cannot be used in an integer field (an error is thrown on this line ). This is unintuitive to me, and also "unpythonic" in the sense that an object which provides an int-like interface should be treated as an int rather than being excluded through explicit type checking.
I tested the analogous behavior in SQLAlchemy and there, numpy int64s do work in integer fields.
I don't know what the best way to implement this is - one simple way might be to just compare whether val == int(val). Alternately, we could use the same approach that is taken with strings a few lines up - just attempt to cast it to an int.
Steps to reproduce:
from pony import orm
import numpy as np
db = orm.Database()
class Person(db.Entity):
name = orm.Required(str)
age = orm.Required(int)
db.bind(provider='sqlite', filename=':memory:')
db.generate_mapping(create_tables=True)
#works fine
p1 = Person(name='John', age=20)
# throws TypeError
p2 = Person(name='Mary', age=np.int64(20))
Happy to post the full traceback or the analogous SQLAlchemy code if that would be helpful.