jeudi 3 mars 2016

connecting to SQLite with python 2.6, pandas and SqlAlhemy — mission impossibe?

I am trying to deploy geospatial joint script on the cluster of machines at my school. Unfortunately, they have python 2.6 (standard for Cloudera), and I have to re-write my code accordingly.

Reading pandas.from_sql() requires SQLAlchemy connection to be established. However, the way they propose it does not work in python 2.6:

engine = create_engine('sqlite:///%s' % path)

with engine.connect() as conn, conn.begin():
    chunks = pd.read_sql_table('tweets', conn, columns=columns, chunksize=50)

However, it seems that python 2.6 don't like 'with' statement, nor does it like 'with ... as ... , ... :'. So I had to modify the code slightly:

conn = engine.connect()
conn.begin()
chunks = pd.read_sql_table('tweets', conn, columns=columns, chunksize=50)
conn.close()

However, this throws me another error, pretty strange one:

 raise NotImplementedError("read_sql_table only supported for "
NotImplementedError: read_sql_table only supported for SQLAlchemy connectable.

How can I solve this one?

Aucun commentaire:

Enregistrer un commentaire