yhat / pandasql

sqldf for pandas
MIT License
1.31k stars 184 forks source link

Straightforward way to enable loading extensions? #81

Open tomviolin opened 4 years ago

tomviolin commented 4 years ago

I need to be able to load extensions into sqlite3 for use in queries with pandasql. In particular, I am using the excellent collection of mathematical functions available from this extension library:

https://github.com/seth/RSQLite.extfuns/blob/master/src/extension-functions.c

The only way I've been able to figure out so far to do this is by using a rather convoluted approach that I discovered by poking around in the PandaSQL class:

from pandasql import PandaSQL
pdsql = PandaSQL(persist=True)
sqlite3conn = next(pdsql.conn.gen).connection.connection
sqlite3conn.enable_load_extension(True)
sqlite3conn.load_extension('./libsqlitefunctions.so')

pdsql("select atan(1)*4;")

Is there a more straightforward way of accessing the sqlite3 connection?