From 792eaf55f76c2495c5f991bffa8b8cb76561ab65 Mon Sep 17 00:00:00 2001 From: richiverse Date: Mon, 6 May 2019 15:59:24 -0400 Subject: [PATCH] snowflake-sqlalchemy wont compile on earlier versions of setuptools and/or latest version of pip --- pandas_ext/snowflake.py | 22 +++++++++++++++++----- requirements/requirements.in | 1 + setup.py | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pandas_ext/snowflake.py b/pandas_ext/snowflake.py index 1f676fc..7016277 100644 --- a/pandas_ext/snowflake.py +++ b/pandas_ext/snowflake.py @@ -14,6 +14,7 @@ def connect(**kwargs): account = getenv('SNOWFLAKE_ACCOUNT') database = getenv('SNOWFLAKE_DATABASE') warehouse = getenv('SNOWFLAKE_WAREHOUSE') + role = getenv('SNOWFLAKE_ROLE') return create_engine( URL( account=account, @@ -21,16 +22,20 @@ def connect(**kwargs): password=password, database=database, warehouse=warehouse, + role=role, **kwargs ) ) -def from_snowflake(sql: str, con=None, **kwargs) -> pd.DataFrame: - """Retrieves a query from snowflake.""" +def read_snowflake(sql: str, con=None, **kwargs) -> pd.DataFrame: + """Retrieves a query from snowflake. + + >>> df = read_snowflake('select a from test.test') + """ if con is None: con = connect() - return pd.read_sql(sql, **kwargs) + return pd.read_sql(sql, con, **kwargs) def to_snowflake( @@ -42,7 +47,11 @@ def to_snowflake( if_exists='append', **kwargs ) -> pd.DataFrame: - """Sends the current dataframe to snowflake.""" + """Sends the current dataframe to snowflake. + + >>> df = pd.DataFrame(dict(a=[1,2,3],b=[4,5,6])) + >>> to_snowflake(df, 'test', 'test') + """ if con is None: con = connect() df.to_sql( @@ -56,4 +65,7 @@ def to_snowflake( if __name__ == '__main__': - connect() + df = pd.DataFrame(dict(a=[1,2,3],b=[4,5,6])) + to_snowflake(df, 'test', 'test',) + test_df = read_snowflake('select a from test.test') + print(test_df) diff --git a/requirements/requirements.in b/requirements/requirements.in index 0443100..38f531b 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -2,3 +2,4 @@ Jinja2>=2.10 pandas>=0.22 requests>=2.20.0 s3fs>=0.1.5 +setuptools>=41.0.1 diff --git a/setup.py b/setup.py index cdcdf5f..fff6240 100644 --- a/setup.py +++ b/setup.py @@ -63,7 +63,7 @@ def find_meta(meta): extras_require=dict( xls=["xlwt"], xlsx=["openpyxl", "xlsxwriter"], - snowflake=["snowflake-sqlalchemy"], + snowflake=["setuptools>=41.0.1", "snowflake-sqlalchemy"], parquet=["pyarrow"], ), long_description=README,