OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError using pandas read_sql_query() with dtype=UNIQUEIDENTIFIER

  • Thread starter Thread starter philipnye
  • Start date Start date
P

philipnye

Guest
I'm trying to use Pandas' read_sql_query(), specifying a dtype of UNIQUEIDENTIFIER for one of the columns:

Code:
import os
import urllib

import pandas as pd
from sqlalchemy import create_engine, engine, exc
from sqlalchemy.dialects.mssql import UNIQUEIDENTIFIER

driver='pyodbc'
driver_version='ODBC Driver 17 for SQL Server'
dialect='mssql'
server=os.environ['odbc_server']
database=os.environ['odbc_database']
authentication='ActiveDirectoryInteractive'
username=os.environ['odbc_username']

connection_string = (
    f'{dialect}+{driver}:///?odbc_connect=' +
    urllib.parse.quote_plus(
        f'DRIVER={driver_version};SERVER={server};DATABASE={database};' +
        f'UID={username};AUTHENTICATION={authentication};'
    )
)

connection = create_engine(connection_string)

df_ifg_appt = pd.read_sql_query(
    '''
    select
        p.id,
        p.name,
        p.start_date,
        p.end_date
    from core.person p
    ''',
    con=connection,
    dtype={
        'id': UNIQUEIDENTIFIER,
    }
)

This is giving an error: TypeError: dtype '<class 'sqlalchemy.dialects.mssql.base.UNIQUEIDENTIFIER'>' not understood.

What am I doing wrong?
<p>I'm trying to use Pandas' <code>read_sql_query()</code>, specifying a <code>dtype</code> of <code>UNIQUEIDENTIFIER</code> for one of the columns:</p>
<pre class="lang-py prettyprint-override"><code>import os
import urllib

import pandas as pd
from sqlalchemy import create_engine, engine, exc
from sqlalchemy.dialects.mssql import UNIQUEIDENTIFIER

driver='pyodbc'
driver_version='ODBC Driver 17 for SQL Server'
dialect='mssql'
server=os.environ['odbc_server']
database=os.environ['odbc_database']
authentication='ActiveDirectoryInteractive'
username=os.environ['odbc_username']

connection_string = (
f'{dialect}+{driver}:///?odbc_connect=' +
urllib.parse.quote_plus(
f'DRIVER={driver_version};SERVER={server};DATABASE={database};' +
f'UID={username};AUTHENTICATION={authentication};'
)
)

connection = create_engine(connection_string)

df_ifg_appt = pd.read_sql_query(
'''
select
p.id,
p.name,
p.start_date,
p.end_date
from core.person p
''',
con=connection,
dtype={
'id': UNIQUEIDENTIFIER,
}
)
</code></pre>
<p>This is giving an error: <code>TypeError: dtype '<class 'sqlalchemy.dialects.mssql.base.UNIQUEIDENTIFIER'>' not understood</code>.</p>
<p>What am I doing wrong?</p>
 

Latest posts

Top