Snowflake Python Pandas Connector - Unknown error using fetch_pandas_all

痴心易碎 提交于 2020-07-10 07:30:20

问题


I am trying to connect to snowflake using the python pandas connector.

I use the anaconda distribution on Windows, but uninstalled the existing connector and pyarrow and reinstalled using instructions on this page: https://docs.snowflake.com/en/user-guide/python-connector-pandas.html

I have the following versions

pandas 1.0.4 py37h47e9c7a_0

pip 20.1.1 py37_1

pyarrow 0.17.1 pypi_0 pypi

python 3.7.7 h81c818b_4

snowflake-connector-python 2.2.7 pypi_0 pypi

When running step 2 of this document: https://docs.snowflake.com/en/user-guide/python-connector-install.html, I get: 4.21.2

On attempting to use fetch_pandas_all() I get an error: NotSupportedError: Unknown error

The code I am using is as follows:

import snowflake.connector
import pandas as pd

SNOWFLAKE_DATA_SOURCE = '<DB>.<Schema>.<VIEW>'

query = '''
select * 
from table(%s)
LIMIT 10;
'''
def create_snowflake_connection():
    conn = snowflake.connector.connect(
            user='MYUSERNAME',
            account='MYACCOUNT',
            authenticator = 'externalbrowser',
            warehouse='<WH>',
            database='<DB>',
            role='<ROLE>',
            schema='<SCHEMA>'
    )
    
    return conn

con = create_snowflake_connection()

cur = con.cursor()
temp = cur.execute(query, (SNOWFLAKE_DATA_SOURCE)).fetch_pandas_all()
cur.close()

I am wondering what else I need to install/upgrade/check in order to get fetch_pandas_all() to work?


回答1:


What happens when you run this code?

from snowflake import connector
import time

import logging
for logger_name in ['snowflake.connector', 'botocore', 'boto3']:
    logger = logging.getLogger(logger_name)
    logger.setLevel(logging.DEBUG)
    ch = logging.FileHandler('test.log')
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(logging.Formatter('%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s'))
    logger.addHandler(ch)

from snowflake.connector.cursor import CAN_USE_ARROW_RESULT

import  pyarrow
import pandas as pd

print('CAN_USE_ARROW_RESULT', CAN_USE_ARROW_RESULT)

This will output whether CAN_USE_ARROW_RESULT is true and if it's not true, then pandas won't work. When you did the pip install, which of these did you run?

pip install snowflake-connector-python pip install snowflake-connector-python[pandas]

Also, what OS are you running on?



来源:https://stackoverflow.com/questions/62439547/snowflake-python-pandas-connector-unknown-error-using-fetch-pandas-all

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!