2424import pytest
2525
2626from bigframes import dtypes
27+ from bigframes .testing .utils import assert_frame_equal , assert_series_equal
2728
2829
2930@pytest .fixture (scope = "module" )
@@ -72,15 +73,11 @@ def temporal_dfs(session):
7273def _assert_series_equal (actual : pd .Series , expected : pd .Series ):
7374 """Helper function specifically for timedelta testsing. Don't use it outside of this module."""
7475 if actual .dtype == dtypes .FLOAT_DTYPE :
75- pandas .testing .assert_series_equal (
76- actual , expected .astype ("Float64" ), check_index_type = False
77- )
76+ assert_series_equal (actual , expected .astype ("Float64" ), check_index_type = False )
7877 elif actual .dtype == dtypes .INT_DTYPE :
79- pandas .testing .assert_series_equal (
80- actual , expected .astype ("Int64" ), check_index_type = False
81- )
78+ assert_series_equal (actual , expected .astype ("Int64" ), check_index_type = False )
8279 else :
83- pandas . testing . assert_series_equal (
80+ assert_series_equal (
8481 actual .astype ("timedelta64[ns]" ),
8582 expected .dt .floor ("us" ), # in BF the precision is microsecond
8683 check_index_type = False ,
@@ -181,9 +178,7 @@ def test_timestamp_add__ts_series_plus_td_series(temporal_dfs, column, pd_dtype)
181178 )
182179
183180 expected_result = pd_df [column ] + pd_df ["timedelta_col_1" ]
184- pandas .testing .assert_series_equal (
185- actual_result , expected_result , check_index_type = False
186- )
181+ assert_series_equal (actual_result , expected_result , check_index_type = False )
187182
188183
189184@pytest .mark .parametrize ("column" , ["datetime_col" , "timestamp_col" ])
@@ -212,9 +207,7 @@ def test_timestamp_add__ts_series_plus_td_literal(temporal_dfs, literal):
212207 )
213208
214209 expected_result = pd_df ["timestamp_col" ] + literal
215- pandas .testing .assert_series_equal (
216- actual_result , expected_result , check_index_type = False
217- )
210+ assert_series_equal (actual_result , expected_result , check_index_type = False )
218211
219212
220213@pytest .mark .parametrize (
@@ -232,9 +225,7 @@ def test_timestamp_add__td_series_plus_ts_series(temporal_dfs, column, pd_dtype)
232225 )
233226
234227 expected_result = pd_df ["timedelta_col_1" ] + pd_df [column ]
235- pandas .testing .assert_series_equal (
236- actual_result , expected_result , check_index_type = False
237- )
228+ assert_series_equal (actual_result , expected_result , check_index_type = False )
238229
239230
240231def test_timestamp_add__td_literal_plus_ts_series (temporal_dfs ):
@@ -244,9 +235,7 @@ def test_timestamp_add__td_literal_plus_ts_series(temporal_dfs):
244235 actual_result = (timedelta + bf_df ["datetime_col" ]).to_pandas ().astype ("<M8[ns]" )
245236
246237 expected_result = timedelta + pd_df ["datetime_col" ]
247- pandas .testing .assert_series_equal (
248- actual_result , expected_result , check_index_type = False
249- )
238+ assert_series_equal (actual_result , expected_result , check_index_type = False )
250239
251240
252241def test_timestamp_add__ts_literal_plus_td_series (temporal_dfs ):
@@ -258,9 +247,7 @@ def test_timestamp_add__ts_literal_plus_td_series(temporal_dfs):
258247 )
259248
260249 expected_result = timestamp + pd_df ["timedelta_col_1" ]
261- pandas .testing .assert_series_equal (
262- actual_result , expected_result , check_index_type = False
263- )
250+ assert_series_equal (actual_result , expected_result , check_index_type = False )
264251
265252
266253@pytest .mark .parametrize (
@@ -278,9 +265,7 @@ def test_timestamp_add_with_numpy_op(temporal_dfs, column, pd_dtype):
278265 )
279266
280267 expected_result = np .add (pd_df [column ], pd_df ["timedelta_col_1" ])
281- pandas .testing .assert_series_equal (
282- actual_result , expected_result , check_index_type = False
283- )
268+ assert_series_equal (actual_result , expected_result , check_index_type = False )
284269
285270
286271def test_timestamp_add_dataframes (temporal_dfs ):
@@ -295,9 +280,7 @@ def test_timestamp_add_dataframes(temporal_dfs):
295280 )
296281
297282 expected_result = pd_df [columns ] + timedelta
298- pandas .testing .assert_frame_equal (
299- actual_result , expected_result , check_index_type = False
300- )
283+ assert_frame_equal (actual_result , expected_result , check_index_type = False )
301284
302285
303286@pytest .mark .parametrize (
@@ -315,9 +298,7 @@ def test_timestamp_sub__ts_series_minus_td_series(temporal_dfs, column, pd_dtype
315298 )
316299
317300 expected_result = pd_df [column ] - pd_df ["timedelta_col_1" ]
318- pandas .testing .assert_series_equal (
319- actual_result , expected_result , check_index_type = False
320- )
301+ assert_series_equal (actual_result , expected_result , check_index_type = False )
321302
322303
323304@pytest .mark .parametrize (
@@ -334,9 +315,7 @@ def test_timestamp_sub__ts_series_minus_td_literal(temporal_dfs, column, pd_dtyp
334315 actual_result = (bf_df [column ] - literal ).to_pandas ().astype (pd_dtype )
335316
336317 expected_result = pd_df [column ] - literal
337- pandas .testing .assert_series_equal (
338- actual_result , expected_result , check_index_type = False
339- )
318+ assert_series_equal (actual_result , expected_result , check_index_type = False )
340319
341320
342321def test_timestamp_sub__ts_literal_minus_td_series (temporal_dfs ):
@@ -346,9 +325,7 @@ def test_timestamp_sub__ts_literal_minus_td_series(temporal_dfs):
346325 actual_result = (literal - bf_df ["timedelta_col_1" ]).to_pandas ().astype ("<M8[ns]" )
347326
348327 expected_result = literal - pd_df ["timedelta_col_1" ]
349- pandas .testing .assert_series_equal (
350- actual_result , expected_result , check_index_type = False
351- )
328+ assert_series_equal (actual_result , expected_result , check_index_type = False )
352329
353330
354331@pytest .mark .parametrize (
@@ -368,9 +345,7 @@ def test_timestamp_sub_with_numpy_op(temporal_dfs, column, pd_dtype):
368345 )
369346
370347 expected_result = np .subtract (pd_df [column ], pd_df ["timedelta_col_1" ])
371- pandas .testing .assert_series_equal (
372- actual_result , expected_result , check_index_type = False
373- )
348+ assert_series_equal (actual_result , expected_result , check_index_type = False )
374349
375350
376351def test_timestamp_sub_dataframes (temporal_dfs ):
@@ -385,9 +360,7 @@ def test_timestamp_sub_dataframes(temporal_dfs):
385360 )
386361
387362 expected_result = pd_df [columns ] - timedelta
388- pandas .testing .assert_frame_equal (
389- actual_result , expected_result , check_index_type = False
390- )
363+ assert_frame_equal (actual_result , expected_result , check_index_type = False )
391364
392365
393366@pytest .mark .parametrize (
@@ -406,9 +379,7 @@ def test_date_add__series_add_series(temporal_dfs, left_col, right_col):
406379 actual_result = (bf_df [left_col ] + bf_df [right_col ]).to_pandas ()
407380
408381 expected_result = (pd_df [left_col ] + pd_df [right_col ]).astype (dtypes .DATETIME_DTYPE )
409- pandas .testing .assert_series_equal (
410- actual_result , expected_result , check_index_type = False
411- )
382+ assert_series_equal (actual_result , expected_result , check_index_type = False )
412383
413384
414385# Pandas does not support date literal + timedelta series so we don't test it here.
@@ -419,9 +390,7 @@ def test_date_add__literal_add_series(temporal_dfs):
419390 actual_result = (literal + bf_df ["date_col" ]).to_pandas ()
420391
421392 expected_result = (literal + pd_df ["date_col" ]).astype (dtypes .DATETIME_DTYPE )
422- pandas .testing .assert_series_equal (
423- actual_result , expected_result , check_index_type = False
424- )
393+ assert_series_equal (actual_result , expected_result , check_index_type = False )
425394
426395
427396# Pandas does not support timedelta series + date literal so we don't test it here.
@@ -432,9 +401,7 @@ def test_date_add__series_add_literal(temporal_dfs):
432401 actual_result = (bf_df ["date_col" ] + literal ).to_pandas ()
433402
434403 expected_result = (pd_df ["date_col" ] + literal ).astype (dtypes .DATETIME_DTYPE )
435- pandas .testing .assert_series_equal (
436- actual_result , expected_result , check_index_type = False
437- )
404+ assert_series_equal (actual_result , expected_result , check_index_type = False )
438405
439406
440407def test_date_sub__series_sub_series (temporal_dfs ):
@@ -448,9 +415,7 @@ def test_date_sub__series_sub_series(temporal_dfs):
448415 expected_result = (pd_df ["date_col" ] - pd_df ["timedelta_col_1" ]).astype (
449416 dtypes .DATETIME_DTYPE
450417 )
451- pandas .testing .assert_series_equal (
452- actual_result , expected_result , check_index_type = False
453- )
418+ assert_series_equal (actual_result , expected_result , check_index_type = False )
454419
455420
456421def test_date_sub__series_sub_literal (temporal_dfs ):
@@ -460,9 +425,7 @@ def test_date_sub__series_sub_literal(temporal_dfs):
460425 actual_result = (bf_df ["date_col" ] - literal ).to_pandas ()
461426
462427 expected_result = (pd_df ["date_col" ] - literal ).astype (dtypes .DATETIME_DTYPE )
463- pandas .testing .assert_series_equal (
464- actual_result , expected_result , check_index_type = False
465- )
428+ assert_series_equal (actual_result , expected_result , check_index_type = False )
466429
467430
468431@pytest .mark .parametrize (
@@ -486,9 +449,7 @@ def test_timedelta_series_comparison(temporal_dfs, compare_func):
486449 expected_result = compare_func (
487450 pd_df ["timedelta_col_1" ], pd_df ["timedelta_col_2" ]
488451 ).astype ("boolean" )
489- pandas .testing .assert_series_equal (
490- actual_result , expected_result , check_index_type = False
491- )
452+ assert_series_equal (actual_result , expected_result , check_index_type = False )
492453
493454
494455@pytest .mark .parametrize (
@@ -509,9 +470,7 @@ def test_timedelta_series_and_literal_comparison(temporal_dfs, compare_func):
509470 actual_result = compare_func (literal , bf_df ["timedelta_col_2" ]).to_pandas ()
510471
511472 expected_result = compare_func (literal , pd_df ["timedelta_col_2" ]).astype ("boolean" )
512- pandas .testing .assert_series_equal (
513- actual_result , expected_result , check_index_type = False
514- )
473+ assert_series_equal (actual_result , expected_result , check_index_type = False )
515474
516475
517476def test_timedelta_filtering (session ):
@@ -532,9 +491,7 @@ def test_timedelta_filtering(session):
532491 )
533492
534493 expected_result = pd_series [(pd_series - timestamp ) > pd .Timedelta (1 , "h" )]
535- pandas .testing .assert_series_equal (
536- actual_result , expected_result , check_index_type = False
537- )
494+ assert_series_equal (actual_result , expected_result , check_index_type = False )
538495
539496
540497def test_timedelta_ordering (session ):
@@ -562,9 +519,7 @@ def test_timedelta_ordering(session):
562519 )
563520
564521 expected_result = (pd_df ["col_2" ] - pd_df ["col_1" ]).sort_values ()
565- pandas .testing .assert_series_equal (
566- actual_result , expected_result , check_index_type = False
567- )
522+ assert_series_equal (actual_result , expected_result , check_index_type = False )
568523
569524
570525def test_timedelta_cumsum (temporal_dfs ):
@@ -629,6 +584,6 @@ def test_timestamp_diff_after_type_casting(temporal_dfs):
629584 expected_result = pd_df ["timestamp_col" ] - pd_df ["positive_int_col" ].astype (
630585 "datetime64[us, UTC]"
631586 )
632- pandas . testing . assert_series_equal (
587+ assert_series_equal (
633588 actual_result , expected_result , check_index_type = False , check_dtype = False
634589 )
0 commit comments