Python Forum
Key error when using adodbapi, azure and pandas - Printable Version

+- Python Forum (
+-- Forum: Python Coding (
+--- Forum: Data Science (
+--- Thread: Key error when using adodbapi, azure and pandas (/thread-16138.html)

Key error when using adodbapi, azure and pandas - mazamus - Feb-15-2019


I'm using Anaconda environment (Spyder) for my Python development and until recently have been using adodbapi to connect to an Azure SQL server (namely because that one does not need an ODBC driver installed). With the established connection, I have been able to read stuff directly to a Pandas dataframe with pd.read_sql(), awesome.

I just updated everything in my Anaconda environment so I don't exactly know what caused the issue, but now using the exact same code as before leads to a key error (the last rows of the generated output below):

Traceback (most recent call last): File "<ipython-input-20-df4577e99893>", line 1, in <module> data = pd.read_sql(dataSQL, connection) File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\", line 380, in read_sql chunksize=chunksize) File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\", line 1482, in read_query parse_dates=parse_dates) File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\io\", line 141, in _wrap_result coerce_float=coerce_float) File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\", line 1512, in from_records coerce_float=coerce_float) File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\internals\", line 408, in to_arrays elif isinstance(data[0], ABCSeries): File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\dtypes\", line 9, in _check return getattr(inst, attr, '_typ') in comp File "C:\Users\mahal\AppData\Local\Continuum\anaconda3\lib\site-packages\adodbapi\", line 466, in __getattr__ return self._getValue(self.rows.columnNames[name.lower()]) KeyError: '_typ'
The code is simply:

import pandas as pd
import adodbapi

connection = adodbapi.connect("PROVIDER=SQLOLEDB; Data Source={0}; \
                              Database={1}; trusted_connection=no; \
                              Uid={2}; PWD={3};".format(server, database, username, password))

df = pd.read_sql(dataSQL, connection)
with string values assigned to the variables, and a legit SQL query as string in dataSQL. I have little to no understanding what is happening under the hood in these libraries, so any help is appreciated. What could be causing that key error? I am yet to try this with another connection type (have to wait for the IT to install the ODBC driver), but this connection method is widely used in my various code snippets and I would like to get it working again.

RE: Key error when using adodbapi, azure and pandas - pr0faka - May-09-2019

Did you find a solution?
I have the same issue with adodbapi after updating pandas

RE: Key error when using adodbapi, azure and pandas - TomKom - Sep-11-2019

Hi, I found a solution. It's described there: adodbapi-patch suggestion at github

Since adodbapi doesn't change much, this simple "patch" will last long.