Ir al contenido principal

sqlalchemy ProgrammingError can't adapt type numpy.float64 - Python troubleshooting

Are you getting a

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


It's because psycopg (psycopg2) - which is used inherently by SQL Alchemy but if you're just dealing directly with alchemy you might not know this - has no idea how to make the numpy.core.numerictypes.float64 (complete type path: another thing they don't tell you) a string for SQL querying.

Simple solution, add:

# solution by Jorge Orpinel found at rehalcon.blogspotcom
import numpy
from psycopg2.extensions import register_adapter, AsIs
def addapt_numpy_float64(numpy_float64):
return AsIs(numpy_float64)
register_adapter(numpy.float64, addapt_numpy_float64)

somewhere in the program.

For a more complete reference of the problem see


  1. Could this solution be simplified by not defining the addapt_numpy_float64 function and just using AsIs instead?

    register_adapter(numpy.float64, AsIs)

  2. This was super helpful. I had exactly this problem (with numpy.float32 type). I have a Flask app that connects to a postgres db. I put this in my app's, and now everything works perfectly! Thank you!

  3. @Genevine I'm glad this post from 6 years ago helped you! Good luck out there (:


Publicar un comentario

Entradas populares de este blog

I don't git it.

A lot of people praise git. I liked it at first, now I don't geet it.

Some weird stuff I've found in git, in no particular order:

You can pretend to be anyone. Just change your [user] name and email in .git/config and commit away. As long as when you push you use valid credentials, the commits will be recorded as from someone else. (At least this is possible on GitHub, I know git doesn't implement any specific user access control.)
* I guess you could try to enforce signing commits but as anything besides the basics, that gets pretty complicated on git.Steep learning curve that keeps getting steeper. Ok: git init, git add, git rm -r, git commit -am, git remote add, git fetch, git merge -ff, git push and pull -u of course, git checkout -b, git reset --mixed, git revert HEAD ... Those are just some of the basics... Ever tried to incorporate git subtree pull -P prefix --squash > into your workflow? I have, it's not fun (keep reading).Its super complicated to collaborate…

How to Book Airbnb in Cuba

Currently (January 2016), you can only book a casa particular through Airbnb from the USA (not even from Cuba itself). Payment has to be made with a US-based method as well. The process however, is not as simple as with any other places they offer listings in. In fact you're not really supposed to book there unless you're a "licensed US traveler", but you still can ;)

Here are some important tips after having to figure all this myself -- which would've been hard without writing/speaking Spanish, I recon. The truth is either in Spanish or English, the info. about this topic is extremely lacking out there... UNTIL NOW

In Cuba you can't just put your house up for Airbnb! Only government permitted bed-n-breakfast (arrendador divisa, see right figure) didn't help create a new market it Cuba like in other parts of the world, it just helps people in the US (for now) find these places without having to pay an expensive guide on-the-ground to plan the entire tri…