psrc / psrcelmerpy

Tools for accessing Elmer in Python
0 stars 0 forks source link

Check compatibility with latest version of sqlalchemy #13

Open stefancoe opened 6 months ago

stefancoe commented 6 months ago

Latest version is 2.0.

This code failed using the current version. I replaced it with this:

import pandas as pd
import geopandas as gpd
from shapely import wkt
from pymssql import connect
from sqlalchemy import create_engine, text
import urllib
import pyodbc
import toml

def load_elmer_table(table_name, sql=None):
    conn_string = "DRIVER={ODBC Driver 17 for SQL Server}; SERVER=AWS-PROD-SQL\Sockeye; DATABASE=Elmer; trusted_connection=yes"
    params = urllib.parse.quote_plus(conn_string)
    engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)

    if sql is None:
        sql = "SELECT * FROM " + table_name

    df = pd.DataFrame(engine.connect().execute(text(sql)))

    return df
christopeak commented 6 months ago

@stefancoe This seems to be working for me. I could not replicate the problem you were having, even in a new environment with the most recent sqlalchemy, so I will need you to confirm it works for you. I implemented the change you suggested in your load_elmer_table snippet above. Let me know?