From 7297d66db794352beb453b910fcd62ff28229427 Mon Sep 17 00:00:00 2001 From: Sophie Tan Date: Wed, 7 Jun 2023 14:28:31 -0400 Subject: [PATCH 1/3] Add file format to temp stage --- src/snowflake/connector/pandas_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snowflake/connector/pandas_tools.py b/src/snowflake/connector/pandas_tools.py index 047822365..3b0c4ebb7 100644 --- a/src/snowflake/connector/pandas_tools.py +++ b/src/snowflake/connector/pandas_tools.py @@ -192,7 +192,7 @@ def write_pandas( name=random_string(), quote_identifiers=quote_identifiers, ) - create_stage_sql = f"CREATE TEMP STAGE /* Python:snowflake.connector.pandas_tools.write_pandas() */ {stage_location}" + create_stage_sql = f"CREATE TEMP STAGE /* Python:snowflake.connector.pandas_tools.write_pandas() */ {stage_location} FILE_FORMAT=(TYPE=PARQUET COMPRESSION={compression_map[compression]}{' BINARY_AS_TEXT=FALSE' if auto_create_table or overwrite else ''})" logger.debug(f"creating stage with '{create_stage_sql}'") cursor.execute(create_stage_sql, _is_internal=True).fetchall() From d422557f76d68ce06bda55f052aaacc3f49fb9b4 Mon Sep 17 00:00:00 2001 From: Sophie Tan Date: Fri, 9 Jun 2023 19:46:10 -0400 Subject: [PATCH 2/3] Add test --- test/integ/pandas/test_pandas_tools.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/integ/pandas/test_pandas_tools.py b/test/integ/pandas/test_pandas_tools.py index af95fa0ea..ef88a4832 100644 --- a/test/integ/pandas/test_pandas_tools.py +++ b/test/integ/pandas/test_pandas_tools.py @@ -48,6 +48,15 @@ ) +def test_fix_snow_746341(conn_cnx: Callable[..., Generator[SnowflakeConnection, None, None]]): + cat = '"cat"' + df = pandas.DataFrame([[1], [2]], columns=[f"col_'{cat}'"]) + table_name = random_string(5, "snow746341_") + with conn_cnx() as conn: + write_pandas(conn, df, table_name, auto_create_table=True, table_type="temporary") + assert conn.cursor().execute(f'select * from "{table_name}"').fetchall() == [(1,),(2,)] + + @pytest.mark.parametrize("quote_identifiers", [True, False]) @pytest.mark.parametrize("auto_create_table", [True, False]) @pytest.mark.parametrize("index", [False]) From 5e7cf60f889ce880712421727328163af787d25a Mon Sep 17 00:00:00 2001 From: Sophie Tan Date: Mon, 12 Jun 2023 13:43:29 -0400 Subject: [PATCH 3/3] Fix lint --- test/integ/pandas/test_pandas_tools.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/integ/pandas/test_pandas_tools.py b/test/integ/pandas/test_pandas_tools.py index ef88a4832..b801eba91 100644 --- a/test/integ/pandas/test_pandas_tools.py +++ b/test/integ/pandas/test_pandas_tools.py @@ -48,13 +48,20 @@ ) -def test_fix_snow_746341(conn_cnx: Callable[..., Generator[SnowflakeConnection, None, None]]): +def test_fix_snow_746341( + conn_cnx: Callable[..., Generator[SnowflakeConnection, None, None]] +): cat = '"cat"' df = pandas.DataFrame([[1], [2]], columns=[f"col_'{cat}'"]) table_name = random_string(5, "snow746341_") with conn_cnx() as conn: - write_pandas(conn, df, table_name, auto_create_table=True, table_type="temporary") - assert conn.cursor().execute(f'select * from "{table_name}"').fetchall() == [(1,),(2,)] + write_pandas( + conn, df, table_name, auto_create_table=True, table_type="temporary" + ) + assert conn.cursor().execute(f'select * from "{table_name}"').fetchall() == [ + (1,), + (2,), + ] @pytest.mark.parametrize("quote_identifiers", [True, False])