From 95a2fba6bad6b9db25309471f34de388077f618f Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Fri, 24 Apr 2026 21:12:43 +0000 Subject: [PATCH] tests(bigframes): re-enable some tests blocking the doctest --- .../bigframes/bigquery/_operations/struct.py | 7 +++--- .../tests/system/small/bigquery/test_json.py | 16 +++++--------- .../tests/system/small/test_series.py | 22 +++++-------------- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/packages/bigframes/bigframes/bigquery/_operations/struct.py b/packages/bigframes/bigframes/bigquery/_operations/struct.py index d26dd53a6f03..ba33457a768c 100644 --- a/packages/bigframes/bigframes/bigquery/_operations/struct.py +++ b/packages/bigframes/bigframes/bigquery/_operations/struct.py @@ -41,11 +41,10 @@ def struct(value: dataframe.DataFrame) -> series.Series: >>> srs = series.Series([{"version": 1, "project": "pandas"}, {"version": 2, "project": "numpy"},]) >>> df = srs.struct.explode() - >>> df = df[["project", "version"]] # set the column order to ensure stable output for doctest >>> bbq.struct(df) - 0 {'project': 'pandas', 'version': 1} - 1 {'project': 'numpy', 'version': 2} - dtype: struct[pyarrow] + 0 {'version': 1, 'project': 'pandas'} + 1 {'version': 2, 'project': 'numpy'} + dtype: struct[pyarrow] Args: value (bigframes.dataframe.DataFrame): diff --git a/packages/bigframes/tests/system/small/bigquery/test_json.py b/packages/bigframes/tests/system/small/bigquery/test_json.py index 9dc4ea328948..c83d38a49067 100644 --- a/packages/bigframes/tests/system/small/bigquery/test_json.py +++ b/packages/bigframes/tests/system/small/bigquery/test_json.py @@ -398,8 +398,8 @@ def test_to_json_from_int(): def test_to_json_from_struct(): s = bpd.Series( [ - {"project": "pandas", "version": 1}, - {"project": "numpy", "version": 2}, + {"version": 1, "project": "pandas"}, + {"version": 2, "project": "numpy"}, ] ) assert dtypes.is_struct_like(s.dtype) @@ -410,9 +410,7 @@ def test_to_json_from_struct(): dtype=dtypes.JSON_DTYPE, ) - actual_json = [json.loads(x) for x in actual.to_pandas()] - expected_json = [json.loads(x) for x in expected.to_pandas()] - assert actual_json == expected_json + pd.testing.assert_series_equal(actual.to_pandas(), expected.to_pandas()) def test_to_json_string_from_int(): @@ -425,8 +423,8 @@ def test_to_json_string_from_int(): def test_to_json_string_from_struct(): s = bpd.Series( [ - {"project": "pandas", "version": 1}, - {"project": "numpy", "version": 2}, + {"version": 1, "project": "pandas"}, + {"version": 2, "project": "numpy"}, ] ) assert dtypes.is_struct_like(s.dtype) @@ -437,9 +435,7 @@ def test_to_json_string_from_struct(): dtype=dtypes.STRING_DTYPE, ) - actual_json = [json.loads(x) for x in actual.to_pandas()] - expected_json = [json.loads(x) for x in expected.to_pandas()] - assert actual_json == expected_json + pd.testing.assert_series_equal(actual.to_pandas(), expected.to_pandas()) def test_json_keys(): diff --git a/packages/bigframes/tests/system/small/test_series.py b/packages/bigframes/tests/system/small/test_series.py index 0ac8f1eb61e9..1d77f299bc03 100644 --- a/packages/bigframes/tests/system/small/test_series.py +++ b/packages/bigframes/tests/system/small/test_series.py @@ -1232,14 +1232,9 @@ def test_divmods_series(scalars_dfs, col_x, col_y, method): scalars_pandas_df[col_y] ) # BigQuery's mod functions return NUMERIC values for non-INT64 inputs. - if bf_div_result.dtype == pd.Int64Dtype(): - bigframes.testing.utils.assert_series_equal( - pd_div_result, bf_div_result.to_pandas(), check_dtype=False - ) - else: - bigframes.testing.utils.assert_series_equal( - pd_div_result, bf_div_result.astype("Float64").to_pandas() - ) + bigframes.testing.utils.assert_series_equal( + pd_div_result, bf_div_result.astype("Float64").to_pandas() + ) if bf_mod_result.dtype == pd.Int64Dtype(): bigframes.testing.utils.assert_series_equal( @@ -1277,14 +1272,9 @@ def test_divmods_scalars(scalars_dfs, col_x, other, method): bf_div_result, bf_mod_result = getattr(scalars_df[col_x], method)(other) pd_div_result, pd_mod_result = getattr(scalars_pandas_df[col_x], method)(other) # BigQuery's mod functions return NUMERIC values for non-INT64 inputs. - if bf_div_result.dtype == pd.Int64Dtype(): - bigframes.testing.utils.assert_series_equal( - pd_div_result, bf_div_result.to_pandas(), check_dtype=False - ) - else: - bigframes.testing.utils.assert_series_equal( - pd_div_result, bf_div_result.astype("Float64").to_pandas() - ) + bigframes.testing.utils.assert_series_equal( + pd_div_result, bf_div_result.astype("Float64").to_pandas() + ) if bf_mod_result.dtype == pd.Int64Dtype(): bigframes.testing.utils.assert_series_equal(