Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
snowflake-sqlalchemy wont compile on earlier versions of setuptools a…
Browse files Browse the repository at this point in the history
…nd/or latest version of pip
  • Loading branch information
richiverse committed May 6, 2019
1 parent 10ed5d8 commit 792eaf5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions pandas_ext/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@ 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,
user=user,
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(
Expand All @@ -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(
Expand All @@ -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)
1 change: 1 addition & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Jinja2>=2.10
pandas>=0.22
requests>=2.20.0
s3fs>=0.1.5
setuptools>=41.0.1
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 792eaf5

Please sign in to comment.