Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit 7cf8a3e

Browse files
fix more tests
1 parent 483b301 commit 7cf8a3e

20 files changed

Lines changed: 124 additions & 85 deletions

File tree

bigframes/core/compile/ibis_compiler/scalar_op_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ def to_timedelta_op_impl(x: ibis_types.Value, op: ops.ToTimedeltaOp):
10301030

10311031
@scalar_op_compiler.register_unary_op(ops.timedelta_floor_op)
10321032
def timedelta_floor_op_impl(x: ibis_types.NumericValue):
1033-
return ibis_api.case().when(x > 0, x.floor()).else_(x.ceil()).end()
1033+
return ibis_api.case().when(x > ibis.literal(0), x.floor()).else_(x.ceil()).end()
10341034

10351035

10361036
@scalar_op_compiler.register_unary_op(ops.RemoteFunctionOp, pass_op=True)

bigframes/core/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def get_standardized_ids(
113113
"""
114114
col_ids = [
115115
UNNAMED_COLUMN_ID
116-
if col_label is None
116+
if pd.isna(col_label) # type: ignore
117117
else label_to_identifier(col_label, strict=strict)
118118
for col_label in col_labels
119119
]

bigframes/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,7 @@ def to_excel(
43984398
**kwargs,
43994399
) -> None:
44004400
return self.to_pandas(allow_large_results=allow_large_results).to_excel(
4401-
excel_writer, sheet_name, **kwargs
4401+
excel_writer, sheet_name=sheet_name, **kwargs
44024402
)
44034403

44044404
def to_latex(

bigframes/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ def to_excel(
22922292
self, excel_writer, sheet_name="Sheet1", *, allow_large_results=None, **kwargs
22932293
) -> None:
22942294
return self.to_pandas(allow_large_results=allow_large_results).to_excel(
2295-
excel_writer, sheet_name, **kwargs
2295+
excel_writer, sheet_name=sheet_name, **kwargs
22962296
)
22972297

22982298
def to_json(

bigframes/testing/utils.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def assert_series_equivalent(pd_series: pd.Series, bf_series: bpd.Series, **kwar
9191

9292

9393
def _normalize_all_nulls(col: pd.Series) -> pd.Series:
94-
# This over-normalizes probably, make more conservative later
95-
if col.hasnans and (pd_types.is_float_dtype(col.dtype)):
94+
if pd_types.is_float_dtype(col.dtype):
9695
col = col.astype("float64").astype("Float64")
9796
return col
9897

@@ -172,8 +171,8 @@ def assert_series_equal(
172171
right.index = right.index.astype("Int64")
173172

174173
if nulls_are_nan:
175-
left = _normalize_all_nulls(left)
176-
right = _normalize_all_nulls(right)
174+
left = _normalize_all_nulls(left.infer_objects())
175+
right = _normalize_all_nulls(right.infer_objects())
177176
left.index = _normalize_index_nulls(left.index)
178177
right.index = _normalize_index_nulls(right.index)
179178
left.name = pd.NA if pd.isna(left.name) else left.name # type: ignore

tests/system/small/bigquery/test_datetime.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import pytest
2020

2121
from bigframes import bigquery
22+
import bigframes.testing
2223

2324
_TIMESTAMP_DTYPE = pd.ArrowDtype(pa.timestamp("us", tz="UTC"))
2425

@@ -40,7 +41,7 @@ def test_unix_seconds(scalars_dfs):
4041
.apply(lambda ts: _to_unix_epoch(ts, "s"))
4142
.astype("Int64")
4243
)
43-
pd.testing.assert_series_equal(actual_res, expected_res)
44+
bigframes.testing.assert_series_equal(actual_res, expected_res)
4445

4546

4647
def test_unix_seconds_after_type_casting(int_series):
@@ -53,7 +54,9 @@ def test_unix_seconds_after_type_casting(int_series):
5354
.apply(lambda ts: _to_unix_epoch(ts, "s"))
5455
.astype("Int64")
5556
)
56-
pd.testing.assert_series_equal(actual_res, expected_res, check_index_type=False)
57+
bigframes.testing.assert_series_equal(
58+
actual_res, expected_res, check_index_type=False
59+
)
5760

5861

5962
def test_unix_seconds_incorrect_input_type_raise_error(scalars_dfs):
@@ -73,7 +76,7 @@ def test_unix_millis(scalars_dfs):
7376
.apply(lambda ts: _to_unix_epoch(ts, "ms"))
7477
.astype("Int64")
7578
)
76-
pd.testing.assert_series_equal(actual_res, expected_res)
79+
bigframes.testing.assert_series_equal(actual_res, expected_res)
7780

7881

7982
def test_unix_millis_after_type_casting(int_series):
@@ -86,7 +89,9 @@ def test_unix_millis_after_type_casting(int_series):
8689
.apply(lambda ts: _to_unix_epoch(ts, "ms"))
8790
.astype("Int64")
8891
)
89-
pd.testing.assert_series_equal(actual_res, expected_res, check_index_type=False)
92+
bigframes.testing.assert_series_equal(
93+
actual_res, expected_res, check_index_type=False
94+
)
9095

9196

9297
def test_unix_millis_incorrect_input_type_raise_error(scalars_dfs):
@@ -106,7 +111,7 @@ def test_unix_micros(scalars_dfs):
106111
.apply(lambda ts: _to_unix_epoch(ts, "us"))
107112
.astype("Int64")
108113
)
109-
pd.testing.assert_series_equal(actual_res, expected_res)
114+
bigframes.testing.assert_series_equal(actual_res, expected_res)
110115

111116

112117
def test_unix_micros_after_type_casting(int_series):
@@ -119,7 +124,9 @@ def test_unix_micros_after_type_casting(int_series):
119124
.apply(lambda ts: _to_unix_epoch(ts, "us"))
120125
.astype("Int64")
121126
)
122-
pd.testing.assert_series_equal(actual_res, expected_res, check_index_type=False)
127+
bigframes.testing.assert_series_equal(
128+
actual_res, expected_res, check_index_type=False
129+
)
123130

124131

125132
def test_unix_micros_incorrect_input_type_raise_error(scalars_dfs):

tests/system/small/bigquery/test_geo.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import bigframes.bigquery as bbq
3333
import bigframes.geopandas
3434
import bigframes.session
35+
import bigframes.testing
3536

3637

3738
def test_geo_st_area(session: bigframes.session.Session):
@@ -56,7 +57,7 @@ def test_geo_st_area(session: bigframes.session.Session):
5657
geobf_s_result = bbq.st_area(geobf_s).to_pandas().round(-3)
5758
assert geobf_s_result.iloc[0] >= 1000
5859

59-
pd.testing.assert_series_equal(
60+
bigframes.testing.assert_series_equal(
6061
geobf_s_result,
6162
geopd_s_result,
6263
check_dtype=False,
@@ -109,7 +110,7 @@ def test_st_length_various_geometries(session):
109110

110111
# Test default use_spheroid
111112
result_default = st_length(geoseries).to_pandas()
112-
pd.testing.assert_series_equal(
113+
bigframes.testing.assert_series_equal(
113114
result_default,
114115
expected_lengths,
115116
rtol=1e-3,
@@ -118,7 +119,7 @@ def test_st_length_various_geometries(session):
118119

119120
# Test explicit use_spheroid=False
120121
result_explicit_false = st_length(geoseries, use_spheroid=False).to_pandas()
121-
pd.testing.assert_series_equal(
122+
bigframes.testing.assert_series_equal(
122123
result_explicit_false,
123124
expected_lengths,
124125
rtol=1e-3,
@@ -152,7 +153,7 @@ def test_geo_st_difference_with_geometry_objects(session: bigframes.session.Sess
152153
index=[0, 1, 2],
153154
dtype=geopandas.array.GeometryDtype(),
154155
)
155-
pandas.testing.assert_series_equal(
156+
bigframes.testing.assert_series_equal(
156157
geobf_s_result,
157158
expected,
158159
check_index_type=False,
@@ -191,7 +192,7 @@ def test_geo_st_difference_with_single_geometry_object(
191192
index=[0, 1, 2],
192193
dtype=geopandas.array.GeometryDtype(),
193194
)
194-
pandas.testing.assert_series_equal(
195+
bigframes.testing.assert_series_equal(
195196
geobf_s_result,
196197
expected,
197198
check_index_type=False,
@@ -217,7 +218,7 @@ def test_geo_st_difference_with_similar_geometry_objects(
217218
index=[0, 1, 2],
218219
dtype=geopandas.array.GeometryDtype(),
219220
)
220-
pandas.testing.assert_series_equal(
221+
bigframes.testing.assert_series_equal(
221222
geobf_s_result,
222223
expected,
223224
check_index_type=False,
@@ -273,7 +274,7 @@ def test_geo_st_distance_with_geometry_objects(session: bigframes.session.Sessio
273274
index=[0, 1, 2, 3],
274275
dtype="Float64",
275276
)
276-
pandas.testing.assert_series_equal(
277+
bigframes.testing.assert_series_equal(
277278
geobf_s_result,
278279
expected,
279280
check_index_type=False,
@@ -320,7 +321,7 @@ def test_geo_st_distance_with_single_geometry_object(
320321
],
321322
dtype="Float64",
322323
)
323-
pandas.testing.assert_series_equal(
324+
bigframes.testing.assert_series_equal(
324325
geobf_s_result,
325326
expected,
326327
check_index_type=False,
@@ -355,7 +356,7 @@ def test_geo_st_intersection_with_geometry_objects(session: bigframes.session.Se
355356
index=[0, 1, 2],
356357
dtype=geopandas.array.GeometryDtype(),
357358
)
358-
pandas.testing.assert_series_equal(
359+
bigframes.testing.assert_series_equal(
359360
geobf_s_result,
360361
expected,
361362
check_index_type=False,
@@ -394,7 +395,7 @@ def test_geo_st_intersection_with_single_geometry_object(
394395
index=[0, 1, 2],
395396
dtype=geopandas.array.GeometryDtype(),
396397
)
397-
pandas.testing.assert_series_equal(
398+
bigframes.testing.assert_series_equal(
398399
geobf_s_result,
399400
expected,
400401
check_index_type=False,
@@ -424,7 +425,7 @@ def test_geo_st_intersection_with_similar_geometry_objects(
424425
index=[0, 1, 2],
425426
dtype=geopandas.array.GeometryDtype(),
426427
)
427-
pandas.testing.assert_series_equal(
428+
bigframes.testing.assert_series_equal(
428429
geobf_s_result,
429430
expected,
430431
check_index_type=False,
@@ -465,7 +466,7 @@ def test_geo_st_isclosed(session: bigframes.session.Session):
465466
]
466467
expected_series = pd.Series(data=expected_data, dtype="boolean")
467468

468-
pd.testing.assert_series_equal(
469+
bigframes.testing.assert_series_equal(
469470
bf_result,
470471
expected_series,
471472
# We default to Int64 (nullable) dtype, but pandas defaults to int64 index.

tests/system/small/operations/test_dates.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
from packaging import version
1919
import pandas as pd
20-
import pandas.testing
2120
import pytest
2221

2322
from bigframes import dtypes
23+
import bigframes.testing
2424

2525

2626
def test_date_diff_between_series(session):
@@ -35,7 +35,7 @@ def test_date_diff_between_series(session):
3535
actual_result = (bf_df["col_1"] - bf_df["col_2"]).to_pandas()
3636

3737
expected_result = (pd_df["col_1"] - pd_df["col_2"]).astype(dtypes.TIMEDELTA_DTYPE)
38-
pandas.testing.assert_series_equal(
38+
bigframes.testing.assert_series_equal(
3939
actual_result, expected_result, check_index_type=False
4040
)
4141

@@ -47,7 +47,7 @@ def test_date_diff_literal_sub_series(scalars_dfs):
4747
actual_result = (literal - bf_df["date_col"]).to_pandas()
4848

4949
expected_result = (literal - pd_df["date_col"]).astype(dtypes.TIMEDELTA_DTYPE)
50-
pandas.testing.assert_series_equal(
50+
bigframes.testing.assert_series_equal(
5151
actual_result, expected_result, check_index_type=False
5252
)
5353

@@ -59,7 +59,7 @@ def test_date_diff_series_sub_literal(scalars_dfs):
5959
actual_result = (bf_df["date_col"] - literal).to_pandas()
6060

6161
expected_result = (pd_df["date_col"] - literal).astype(dtypes.TIMEDELTA_DTYPE)
62-
pandas.testing.assert_series_equal(
62+
bigframes.testing.assert_series_equal(
6363
actual_result, expected_result, check_index_type=False
6464
)
6565

@@ -70,7 +70,7 @@ def test_date_series_diff_agg(scalars_dfs):
7070
actual_result = bf_df["date_col"].diff().to_pandas()
7171

7272
expected_result = pd_df["date_col"].diff().astype(dtypes.TIMEDELTA_DTYPE)
73-
pandas.testing.assert_series_equal(
73+
bigframes.testing.assert_series_equal(
7474
actual_result, expected_result, check_index_type=False
7575
)
7676

@@ -86,6 +86,6 @@ def test_date_can_cast_after_accessor(scalars_dfs):
8686
pd.to_datetime(pd_df["date_col"]).dt.isocalendar().week.astype("Int64")
8787
)
8888

89-
pandas.testing.assert_series_equal(
89+
bigframes.testing.assert_series_equal(
9090
actual_result, expected_result, check_dtype=False, check_index_type=False
9191
)

tests/system/small/operations/test_datetimes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,12 @@ def test_timestamp_diff_series_sub_literal(scalars_dfs, column, value):
576576
bf_series = bf_df[column]
577577
pd_series = pd_df[column]
578578

579-
actual_result = (bf_series - value).to_pandas()
579+
# Pandas doesn't handle nulls properly here so we ffill
580+
# overflows for no good reason
581+
# related? https://github.com/apache/arrow/issues/43031
582+
actual_result = (bf_series.ffill() - value).to_pandas()
580583

581-
expected_result = pd_series - value
584+
expected_result = pd_series.ffill() - value
582585
assert_series_equal(actual_result, expected_result)
583586

584587

@@ -594,9 +597,12 @@ def test_timestamp_diff_literal_sub_series(scalars_dfs, column, value):
594597
bf_series = bf_df[column]
595598
pd_series = pd_df[column]
596599

597-
actual_result = (value - bf_series).to_pandas()
600+
# Pandas doesn't handle nulls properly here so we ffill
601+
# overflows for no good reason
602+
# related? https://github.com/apache/arrow/issues/43031
603+
actual_result = (value - bf_series.ffill()).to_pandas()
598604

599-
expected_result = value - pd_series
605+
expected_result = value - pd_series.ffill()
600606
assert_series_equal(actual_result, expected_result)
601607

602608

tests/system/small/test_dataframe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,8 @@ def test_drop_bigframes_index(scalars_dfs):
778778

779779

780780
def test_drop_bigframes_index_with_na(scalars_dfs):
781+
if pd.__version__.startswith("3"):
782+
pytest.skip("Pandas 3.0 doesn't doesn't support drop with pd.NA values")
781783
scalars_df, scalars_pandas_df = scalars_dfs
782784
scalars_df = scalars_df.copy()
783785
scalars_pandas_df = scalars_pandas_df.copy()

0 commit comments

Comments
 (0)