我在使用Snowflake的熊猫连接器时遇到了麻烦。
此代码的最后一行导致python内核立即死亡。关于如何诊断这种情况有什么建议吗?
import pyarrow
import snowflake.connector
import pandas as pd
ctx = snowflake.connector.connect(
user=********,
password=********,
account=********,
warehouse='compute_wh',
database='SNOWFLAKE_SAMPLE_DATA',
schema='WEATHER'
)
cs = ctx.cursor()
cs.execute('select * from weather_14_total limit 10')
cs.fetch_pandas_all()
请注意,如果将fetch_pandas_all()
替换为fetchone()
,一切正常。
谢谢。
答案 0 :(得分:0)
我们的团队上周也遇到了同样的问题。对于我们来说,解决方法最终是改为使用read_sql命令。
答案 1 :(得分:0)
这对我有用:
import pandas as pd
from snowflake.connector import connect
qry = "SELECT * FROM TABLE LIMIT 5"
con = connect(
account = 'ACCOUNT',
user = 'USER',
password = 'PASSWORD',
role= 'ROLE',
warehouse = 'WAREHOUSE',
database = 'DATABASE',
schema = 'SCHEMA'
)
df = pd.read_sql(qry, con)
但是,这是对类似问题的最高评价:
import pandas as pd
from sqlalchemy import create_engine
from snowflake.sqlalchemy import URL
url = URL(
account = 'xxxx',
user = 'xxxx',
password = 'xxxx',
database = 'xxx',
schema = 'xxxx',
warehouse = 'xxx',
role='xxxxx',
authenticator='https://xxxxx.okta.com',
)
engine = create_engine(URL)
connection = engine.connect()
query = '''
select * from MYDB.MYSCHEMA.MYTABLE
LIMIT 10;
'''
df = pd.read_sql(query, connection)