1717@pytest .mark .parametrize ("index" , [True , False ])
1818@pytest .mark .parametrize ("index_labels" , [None , ["my_index" ]])
1919# one extra query to convert index to native pandas when creating the snowpark pandas dataframe
20- @sql_count_checker (query_count = 3 )
20+ @sql_count_checker (query_count = 2 )
2121def test_to_snowflake_index (test_table_name , index , index_labels ):
2222 df = pd .DataFrame (
2323 {"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]}, index = pd .Index ([2 , 3 , 4 ], name = "index" )
@@ -38,7 +38,7 @@ def test_to_snowflake_index(test_table_name, index, index_labels):
3838 verify_columns (test_table_name , expected_columns )
3939
4040
41- @sql_count_checker (query_count = 2 )
41+ @sql_count_checker (query_count = 1 )
4242def test_to_snowflake_multiindex (test_table_name ):
4343 index = native_pd .MultiIndex .from_arrays (
4444 [[1 , 1 , 2 , 2 ], ["red" , "blue" , "red" , "blue" ]], names = ("number" , "color" )
@@ -94,7 +94,7 @@ def test_to_snowflake_if_exists(session, test_table_name):
9494 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
9595
9696 # Verify new table is created
97- with SqlCounter (query_count = 3 ):
97+ with SqlCounter (query_count = 2 ):
9898 df .to_snowflake (test_table_name , if_exists = "fail" , index = False )
9999 verify_columns (test_table_name , ["a" , "b" ])
100100
@@ -110,19 +110,19 @@ def test_to_snowflake_if_exists(session, test_table_name):
110110
111111 # Verify existing table is replaced with new data
112112 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "c" : [4 , 5 , 6 ]})
113- with SqlCounter (query_count = 3 ):
113+ with SqlCounter (query_count = 2 ):
114114 df .to_snowflake (test_table_name , if_exists = "replace" , index = False )
115115 verify_columns (test_table_name , ["a" , "c" ])
116116 verify_num_rows (session , test_table_name , 3 )
117117
118118 # Verify data is appended to existing table
119- with SqlCounter (query_count = 4 ):
119+ with SqlCounter (query_count = 3 ):
120120 df .to_snowflake (test_table_name , if_exists = "append" , index = False )
121121 verify_columns (test_table_name , ["a" , "c" ])
122122 verify_num_rows (session , test_table_name , 6 )
123123
124124 # Verify pd.to_snowflake operates the same
125- with SqlCounter (query_count = 4 ):
125+ with SqlCounter (query_count = 3 ):
126126 pd .to_snowflake (df , test_table_name , if_exists = "append" , index = False )
127127 verify_columns (test_table_name , ["a" , "c" ])
128128 verify_num_rows (session , test_table_name , 9 )
@@ -134,7 +134,7 @@ def test_to_snowflake_if_exists(session, test_table_name):
134134
135135
136136@pytest .mark .parametrize ("index_label" , VALID_PANDAS_LABELS )
137- @sql_count_checker (query_count = 2 )
137+ @sql_count_checker (query_count = 1 )
138138def test_to_snowflake_index_labels (index_label , test_table_name ):
139139 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
140140 df .to_snowflake (
@@ -144,7 +144,7 @@ def test_to_snowflake_index_labels(index_label, test_table_name):
144144
145145
146146@pytest .mark .parametrize ("col_name" , VALID_PANDAS_LABELS )
147- @sql_count_checker (query_count = 2 )
147+ @sql_count_checker (query_count = 1 )
148148def test_to_snowflake_column_names_from_panadas (col_name , test_table_name ):
149149 df = pd .DataFrame ({col_name : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
150150 df .to_snowflake (test_table_name , if_exists = "replace" , index = False )
@@ -156,7 +156,7 @@ def test_to_snowflake_column_names_from_panadas(col_name, test_table_name):
156156def test_column_names_with_read_snowflake_and_to_snowflake (
157157 col_name , if_exists , session
158158):
159- with SqlCounter (query_count = 7 if if_exists == "append" else 6 ):
159+ with SqlCounter (query_count = 6 if if_exists == "append" else 5 ):
160160 # Create a table
161161 session .sql (f"create or replace table t1 ({ col_name } int)" ).collect ()
162162 session .sql ("insert into t1 values (1), (2), (3)" ).collect ()
@@ -173,7 +173,7 @@ def test_column_names_with_read_snowflake_and_to_snowflake(
173173 assert len (data ) == (6 if if_exists == "append" else 3 )
174174
175175
176- @sql_count_checker (query_count = 2 )
176+ @sql_count_checker (query_count = 1 )
177177def test_to_snowflake_column_with_quotes (session , test_table_name ):
178178 df = pd .DataFrame ({'a"b' : [1 , 2 , 3 ], 'a""b' : [4 , 5 , 6 ]})
179179 df .to_snowflake (test_table_name , if_exists = "replace" , index = False )
@@ -183,28 +183,28 @@ def test_to_snowflake_column_with_quotes(session, test_table_name):
183183# one extra query to convert index to native pandas when creating the snowpark pandas dataframe
184184def test_to_snowflake_index_label_none (test_table_name ):
185185 # no index
186- with SqlCounter (query_count = 2 ):
186+ with SqlCounter (query_count = 1 ):
187187 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]})
188188 df .to_snowflake (test_table_name , if_exists = "replace" )
189189 verify_columns (test_table_name , ["index" , "a" , "b" ])
190190
191191 # named index
192- with SqlCounter (query_count = 3 ):
192+ with SqlCounter (query_count = 2 ):
193193 df = pd .DataFrame (
194194 {"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]}, index = pd .Index ([2 , 3 , 4 ], name = "index" )
195195 )
196196 df .to_snowflake (test_table_name , if_exists = "replace" , index_label = [None ])
197197 verify_columns (test_table_name , ["index" , "a" , "b" ])
198198
199199 # nameless index
200- with SqlCounter (query_count = 3 ):
200+ with SqlCounter (query_count = 2 ):
201201 df = pd .DataFrame ({"a" : [1 , 2 , 3 ], "b" : [4 , 5 , 6 ]}, index = pd .Index ([2 , 3 , 4 ]))
202202 df .to_snowflake (test_table_name , if_exists = "replace" , index_label = [None ])
203203 verify_columns (test_table_name , ["index" , "a" , "b" ])
204204
205205
206206# one extra query to convert index to native pandas when creating the snowpark pandas dataframe
207- @sql_count_checker (query_count = 6 )
207+ @sql_count_checker (query_count = 4 )
208208def test_to_snowflake_index_label_none_data_column_conflict (test_table_name ):
209209 df = pd .DataFrame ({"index" : [1 , 2 , 3 ], "a" : [4 , 5 , 6 ]})
210210 df .to_snowflake (test_table_name , if_exists = "replace" )
@@ -260,7 +260,7 @@ def verify_num_rows(session, table_name: str, expected: int) -> None:
260260 assert actual == expected
261261
262262
263- @sql_count_checker (query_count = 2 )
263+ @sql_count_checker (query_count = 1 )
264264def test_timedelta_to_snowflake_with_read_snowflake (test_table_name , caplog ):
265265 with caplog .at_level (logging .WARNING ):
266266 df = pd .DataFrame (
0 commit comments