I want to hide this warning UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
and I’ve tried
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)
import pandas
but the warning still shows.
My python script read data from databases. I’m using pandas.read_sql
for SQL queries and psycopg2
for db connections.
Also I’d like to know which line triggers the warning.
3
Answers
It seems I cannot disable the pandas warning, so I used SQLAlchemy (as the warning message wants me to do so) to wrap the psycopg2 connection.
I followed the instruction here: SQLAlchemy for psycopg2 documentation
A simple example:
The warning doesn't get triggered anymore.
The warnings that you’re filtering right now are warnings of type
FutureWarning
. The warning that you’re getting is of typeUserWarning
, so you should change the warning category toUserWarning
. I hope this answers your question regarding why pandas is giving that warning.Using the following worked well for me:
I am using pandas with pyodbc and was previously getting the same warning.