openego/ego.io

type adaption in sqla/psycopg2 to match SQL types

Closed this issue · 1 comments

When adding a dataset to a table via sqla, e.g.

dataset = mapped_sqla_object(attr1=var_int, attr2=var_str)
session.add(dataset)

throws

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'numpy.int64'

Variable var_int is of type 'numpy.int64' so I seems psycopg2 doesn't know how to map the numpy to SQL-conform type (sqla column type is defined as 'sqla.Integer').

I found a solution using a psycopg2 extension using register_adapter().
To avoid having it in every single tool, @MGlauer proposes to make it a part of the planned ego.io-packages __init__.py, i.e. if you use import ego.io this adapter will be automatically registered.

(issue in dingo)

I already did it some time ago, see 8e7c64e.