Description
The following read_sql_query() works:
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://'+name+':'+pw+'@'+server+'/?charset=utf8')
sql = 'select * from MyDatabase.my_temp_table'
df = pd.read_sql_query(sql,engine)
The same statements now fail in read_sql():
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://'+name+':'+pw+'@'+server+'/?charset=utf8')
sql = 'select * from MyDatabase.my_temp_table'
df = pd.read_sql(sql,engine)
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1235 self.dialect.do_execute(
-> 1236 cursor, statement, parameters, context
1237 )
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
535 def do_execute(self, cursor, statement, parameters, context=None):
--> 536 cursor.execute(statement, parameters)
537
~/miniconda3/lib/python3.6/site-packages/pymysql/cursors.py in execute(self, query, args)
169
--> 170 result = self._query(query)
171 self._executed = query
~/miniconda3/lib/python3.6/site-packages/pymysql/cursors.py in _query(self, q)
327 self._clear_result()
--> 328 conn.query(q)
329 self._do_get_result()
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in query(self, sql, unbuffered)
515 self._execute_command(COMMAND.COM_QUERY, sql)
--> 516 self._affected_rows = self._read_query_result(unbuffered=unbuffered)
517 return self._affected_rows
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in _read_query_result(self, unbuffered)
726 result = MySQLResult(self)
--> 727 result.read()
728 self._result = result
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in read(self)
1065 try:
-> 1066 first_packet = self.connection._read_packet()
1067
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in _read_packet(self, packet_type)
682 packet = packet_type(buff, self.encoding)
--> 683 packet.check_error()
684 return packet
~/miniconda3/lib/python3.6/site-packages/pymysql/protocol.py in check_error(self)
219 if DEBUG: print("errno =", errno)
--> 220 err.raise_mysql_exception(self._data)
221
~/miniconda3/lib/python3.6/site-packages/pymysql/err.py in raise_mysql_exception(data)
108 errorclass = error_map.get(errno, InternalError)
--> 109 raise errorclass(errno, errval)
InternalError: (1046, 'No database selected')
The above exception was the direct cause of the following exception:
InternalError Traceback (most recent call last)
<ipython-input-5-ebe084ae005c> in <module>
----> 1 df = pd.read_sql(sql,engine)
~/miniconda3/lib/python3.6/site-packages/pandas/io/sql.py in read_sql(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize)
381
382 try:
--> 383 _is_table_name = pandas_sql.has_table(sql)
384 except (ImportError, AttributeError):
385 _is_table_name = False
~/miniconda3/lib/python3.6/site-packages/pandas/io/sql.py in has_table(self, name, schema)
1198 self.connectable.dialect.has_table,
1199 name,
-> 1200 schema or self.meta.schema,
1201 )
1202
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in run_callable(self, callable_, *args, **kwargs)
2123 """
2124 with self.contextual_connect() as conn:
-> 2125 return conn.run_callable(callable_, *args, **kwargs)
2126
2127 def execute(self, statement, *multiparams, **params):
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in run_callable(self, callable_, *args, **kwargs)
1594
1595 """
-> 1596 return callable_(self, *args, **kwargs)
1597
1598 def _run_visitor(self, visitorcallable, element, **kwargs):
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/dialects/mysql/base.py in has_table(self, connection, table_name, schema)
2254 rs = connection.execution_options(
2255 skip_user_error_events=True
-> 2256 ).execute(st)
2257 have = rs.fetchone() is not None
2258 rs.close()
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in execute(self, object_, *multiparams, **params)
972 """
973 if isinstance(object_, util.string_types[0]):
--> 974 return self._execute_text(object_, multiparams, params)
975 try:
976 meth = object_._execute_on_connection
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_text(self, statement, multiparams, params)
1145 parameters,
1146 statement,
-> 1147 parameters,
1148 )
1149 if self._has_events or self.engine._has_events:
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1238 except BaseException as e:
1239 self._handle_dbapi_exception(
-> 1240 e, statement, parameters, cursor, context
1241 )
1242
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
1456 util.raise_from_cause(newraise, exc_info)
1457 elif should_wrap:
-> 1458 util.raise_from_cause(sqlalchemy_exception, exc_info)
1459 else:
1460 util.reraise(*exc_info)
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/util/compat.py in raise_from_cause(exception, exc_info)
294 exc_type, exc_value, exc_tb = exc_info
295 cause = exc_value if exc_value is not exception else None
--> 296 reraise(type(exception), exception, tb=exc_tb, cause=cause)
297
298
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/util/compat.py in reraise(tp, value, tb, cause)
274 value.__cause__ = cause
275 if value.__traceback__ is not tb:
--> 276 raise value.with_traceback(tb)
277 raise value
278
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/base.py in _execute_context(self, dialect, constructor, statement, parameters, *args)
1234 if not evt_handled:
1235 self.dialect.do_execute(
-> 1236 cursor, statement, parameters, context
1237 )
1238 except BaseException as e:
~/miniconda3/lib/python3.6/site-packages/sqlalchemy/engine/default.py in do_execute(self, cursor, statement, parameters, context)
534
535 def do_execute(self, cursor, statement, parameters, context=None):
--> 536 cursor.execute(statement, parameters)
537
538 def do_execute_no_params(self, cursor, statement, context=None):
~/miniconda3/lib/python3.6/site-packages/pymysql/cursors.py in execute(self, query, args)
168 query = self.mogrify(query, args)
169
--> 170 result = self._query(query)
171 self._executed = query
172 return result
~/miniconda3/lib/python3.6/site-packages/pymysql/cursors.py in _query(self, q)
326 self._last_executed = q
327 self._clear_result()
--> 328 conn.query(q)
329 self._do_get_result()
330 return self.rowcount
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in query(self, sql, unbuffered)
514 sql = sql.encode(self.encoding, 'surrogateescape')
515 self._execute_command(COMMAND.COM_QUERY, sql)
--> 516 self._affected_rows = self._read_query_result(unbuffered=unbuffered)
517 return self._affected_rows
518
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in _read_query_result(self, unbuffered)
725 else:
726 result = MySQLResult(self)
--> 727 result.read()
728 self._result = result
729 if result.server_status is not None:
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in read(self)
1064 def read(self):
1065 try:
-> 1066 first_packet = self.connection._read_packet()
1067
1068 if first_packet.is_ok_packet():
~/miniconda3/lib/python3.6/site-packages/pymysql/connections.py in _read_packet(self, packet_type)
681
682 packet = packet_type(buff, self.encoding)
--> 683 packet.check_error()
684 return packet
685
~/miniconda3/lib/python3.6/site-packages/pymysql/protocol.py in check_error(self)
218 errno = self.read_uint16()
219 if DEBUG: print("errno =", errno)
--> 220 err.raise_mysql_exception(self._data)
221
222 def dump(self):
~/miniconda3/lib/python3.6/site-packages/pymysql/err.py in raise_mysql_exception(data)
107 errval = data[3:].decode('utf-8', 'replace')
108 errorclass = error_map.get(errno, InternalError)
--> 109 raise errorclass(errno, errval)
InternalError: (pymysql.err.InternalError) (1046, 'No database selected') [SQL: 'DESCRIBE `select * from MyDatabase.my_temp_table`'] (Background on this error at: http://sqlalche.me/e/2j85)
Problem description
Reverting to Pandas version 0.23.4 fixes the issue.
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-1021-aws
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.24.0
pytest: None
pip: 19.0.1
setuptools: 39.2.0
Cython: None
numpy: 1.16.0
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.2.17
pymysql: 0.9.3
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None