Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-853049 Add write_pandas test to a different schema #958

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/integ/test_pandas_to_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from pandas.testing import assert_frame_equal

from snowflake.connector.errors import ProgrammingError
from snowflake.snowpark import Row
from snowflake.snowpark._internal.utils import (
TempObjectType,
is_in_stored_procedure,
random_name_for_temp_object,
warning_dict,
)
Expand Down Expand Up @@ -403,3 +405,37 @@ def test_special_name_quoting(
) in df_data
finally:
session.sql(drop_sql).collect()


def test_write_to_different_schema(session):
pd_df = PandasDF(
[
(1, 4.5, "Nike"),
(2, 7.5, "Adidas"),
(3, 10.5, "Puma"),
],
columns=["id".upper(), "foot_size".upper(), "shoe_make".upper()],
)
original_schema_name = session.get_current_schema()
test_schema_name = Utils.random_temp_schema()

try:
Utils.create_schema(session, test_schema_name)
# For owner's rights stored proc test, current schema does not change after creating a new schema
if not is_in_stored_procedure():
session.sql(f"use schema {original_schema_name}").collect()
assert session.get_current_schema() == original_schema_name
table_name = random_name_for_temp_object(TempObjectType.TABLE)
session.write_pandas(
pd_df,
table_name,
quote_identifiers=False,
schema=test_schema_name,
auto_create_table=True,
)
Utils.check_answer(
session.table(f"{test_schema_name}.{table_name}").sort("id"),
[Row(1, 4.5, "Nike"), Row(2, 7.5, "Adidas"), Row(3, 10.5, "Puma")],
)
finally:
Utils.drop_schema(session, test_schema_name)
Loading