Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/bigframes/bigframes/bigquery/_operations/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<project: string, version: int64>[pyarrow]
0 {'version': 1, 'project': 'pandas'}
1 {'version': 2, 'project': 'numpy'}
dtype: struct<version: int64, project: string>[pyarrow]

Args:
value (bigframes.dataframe.DataFrame):
Expand Down
16 changes: 6 additions & 10 deletions packages/bigframes/tests/system/small/bigquery/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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():
Expand Down
22 changes: 6 additions & 16 deletions packages/bigframes/tests/system/small/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading