Skip to content

Commit

Permalink
SNOW-735220: update documentation of pd_writer (#1642)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-aling authored Jul 17, 2023
1 parent ac81f87 commit 783732d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/snowflake/connector/pandas_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,26 @@ def pd_writer(
) -> None:
"""This is a wrapper on top of write_pandas to make it compatible with to_sql method in pandas.
Notes:
Please note that when column names in the pandas DataFrame are consist of strictly lower case letters, column names need to
be enquoted, otherwise `ProgrammingError` will be raised.
This is because `snowflake-sqlalchemy` does not enquote lower case column names when creating the table, but `pd_writer` enquotes the columns by default.
the copy into command looks for enquoted column names.
Future improvements will be made in the snowflake-sqlalchemy library.
Example usage:
import pandas as pd
from snowflake.connector.pandas_tools import pd_writer
sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['NAME', 'NEWEST_VERSION'])
sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=pd_writer)
# when the column names are consist of only lower case letters, enquote the column names
sf_connector_version_df = pd.DataFrame([('snowflake-connector-python', '1.0')], columns=['"name"', '"newest_version"'])
sf_connector_version_df.to_sql('driver_versions', engine, index=False, method=pd_writer)
Args:
table: Pandas package's table object.
conn: SQLAlchemy engine object to talk to Snowflake.
Expand Down

0 comments on commit 783732d

Please sign in to comment.