1717import os
1818import re
1919from unittest import mock
20+ import warnings
2021
2122import google .api_core .exceptions
2223import google .cloud .bigquery
@@ -186,7 +187,7 @@ def get_table_mock(table_ref):
186187
187188
188189@pytest .mark .parametrize ("table" , CLUSTERED_OR_PARTITIONED_TABLES )
189- def test_no_default_index_error_raised_by_read_gbq (table ):
190+ def test_default_index_warning_raised_by_read_gbq (table ):
190191 """Because of the windowing operation to create a default index, row
191192 filters can't push down to the clustering column.
192193
@@ -202,12 +203,12 @@ def test_no_default_index_error_raised_by_read_gbq(table):
202203 session = resources .create_bigquery_session (bqclient = bqclient )
203204 table ._properties ["location" ] = session ._location
204205
205- with pytest .raises (bigframes .exceptions .NoDefaultIndexError ):
206+ with pytest .warns (bigframes .exceptions .DefaultIndexWarning ):
206207 session .read_gbq ("my-project.my_dataset.my_table" )
207208
208209
209210@pytest .mark .parametrize ("table" , CLUSTERED_OR_PARTITIONED_TABLES )
210- def test_no_default_index_error_not_raised_by_read_gbq_index_col_sequential_int64 (
211+ def test_default_index_warning_not_raised_by_read_gbq_index_col_sequential_int64 (
211212 table ,
212213):
213214 """Because of the windowing operation to create a default index, row
@@ -224,11 +225,13 @@ def test_no_default_index_error_not_raised_by_read_gbq_index_col_sequential_int6
224225 session = resources .create_bigquery_session (bqclient = bqclient )
225226 table ._properties ["location" ] = session ._location
226227
227- # No exception raised because we set the option allowing the default indexes.
228- df = session .read_gbq (
229- "my-project.my_dataset.my_table" ,
230- index_col = bigframes .enums .DefaultIndexKind .SEQUENTIAL_INT64 ,
231- )
228+ # No warnings raised because we set the option allowing the default indexes.
229+ with warnings .catch_warnings ():
230+ warnings .simplefilter ("error" , bigframes .exceptions .DefaultIndexWarning )
231+ df = session .read_gbq (
232+ "my-project.my_dataset.my_table" ,
233+ index_col = bigframes .enums .DefaultIndexKind .SEQUENTIAL_INT64 ,
234+ )
232235
233236 # We expect a window operation because we specificaly requested a sequential index.
234237 generated_sql = df .sql .casefold ()
@@ -246,7 +249,7 @@ def test_no_default_index_error_not_raised_by_read_gbq_index_col_sequential_int6
246249 ),
247250)
248251@pytest .mark .parametrize ("table" , CLUSTERED_OR_PARTITIONED_TABLES )
249- def test_no_default_index_error_not_raised_by_read_gbq_index_col_columns (
252+ def test_default_index_warning_not_raised_by_read_gbq_index_col_columns (
250253 total_count ,
251254 distinct_count ,
252255 table ,
@@ -270,18 +273,20 @@ def test_no_default_index_error_not_raised_by_read_gbq_index_col_columns(
270273 )
271274 table ._properties ["location" ] = session ._location
272275
273- # No exception raised because there are columns to use as the index.
274- df = session .read_gbq (
275- "my-project.my_dataset.my_table" , index_col = ("idx_1" , "idx_2" )
276- )
276+ # No warning raised because there are columns to use as the index.
277+ with warnings .catch_warnings ():
278+ warnings .simplefilter ("error" , bigframes .exceptions .DefaultIndexWarning )
279+ df = session .read_gbq (
280+ "my-project.my_dataset.my_table" , index_col = ("idx_1" , "idx_2" )
281+ )
277282
278283 # There should be no analytic operators to prevent row filtering pushdown.
279284 assert "OVER" not in df .sql
280285 assert tuple (df .index .names ) == ("idx_1" , "idx_2" )
281286
282287
283288@pytest .mark .parametrize ("table" , CLUSTERED_OR_PARTITIONED_TABLES )
284- def test_no_default_index_error_not_raised_by_read_gbq_primary_key (table ):
289+ def test_default_index_warning_not_raised_by_read_gbq_primary_key (table ):
285290 """If a primary key is set on the table, we use that as the index column
286291 by default, no error should be raised in this case.
287292
@@ -310,8 +315,10 @@ def test_no_default_index_error_not_raised_by_read_gbq_primary_key(table):
310315 )
311316 table ._properties ["location" ] = session ._location
312317
313- # No exception raised because there is a primary key to use as the index.
314- df = session .read_gbq ("my-project.my_dataset.my_table" )
318+ # No warning raised because there is a primary key to use as the index.
319+ with warnings .catch_warnings ():
320+ warnings .simplefilter ("error" , bigframes .exceptions .DefaultIndexWarning )
321+ df = session .read_gbq ("my-project.my_dataset.my_table" )
315322
316323 # There should be no analytic operators to prevent row filtering pushdown.
317324 assert "OVER" not in df .sql
0 commit comments