From caf06a45e3f36cc3d3507be607d8ce99d706080b Mon Sep 17 00:00:00 2001 From: Shuowei Li Date: Fri, 6 Mar 2026 23:11:12 +0000 Subject: [PATCH] fix(describe): add count aggregation for JSON and OBJ_REF types --- bigframes/pandas/core/methods/describe.py | 5 +++++ tests/system/small/pandas/test_describe.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/bigframes/pandas/core/methods/describe.py b/bigframes/pandas/core/methods/describe.py index 6fd7960daf3..f4082a5a25d 100644 --- a/bigframes/pandas/core/methods/describe.py +++ b/bigframes/pandas/core/methods/describe.py @@ -120,5 +120,10 @@ def _get_aggs_for_dtype(dtype) -> list[aggregations.UnaryAggregateOp]: dtypes.TIME_DTYPE, ]: return [aggregations.count_op, aggregations.nunique_op] + elif dtype in [ + dtypes.JSON_DTYPE, + dtypes.OBJ_REF_DTYPE, + ]: + return [aggregations.count_op] else: return [] diff --git a/tests/system/small/pandas/test_describe.py b/tests/system/small/pandas/test_describe.py index 6f288115128..96b8adfd373 100644 --- a/tests/system/small/pandas/test_describe.py +++ b/tests/system/small/pandas/test_describe.py @@ -352,3 +352,22 @@ def test_series_groupby_describe(scalars_dfs): check_dtype=False, check_index_type=False, ) + + +def test_describe_json_and_obj_ref_returns_count(session): + # Test describe() works on JSON and OBJ_REF types (without nunique, which fails) + sql = """ + SELECT + PARSE_JSON('{"a": 1}') AS json_col, + 'gs://cloud-samples-data/vision/ocr/sign.jpg' AS uri_col + """ + df = session.read_gbq(sql) + + df["obj_ref_col"] = df["uri_col"].str.to_blob() + df = df.drop(columns=["uri_col"]) + + res = df.describe(include="all").to_pandas() + + assert "count" in res.index + assert res.loc["count", "json_col"] == 1.0 + assert res.loc["count", "obj_ref_col"] == 1.0