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

Commit 3ef34fd

Browse files
committed
fix: handle unsupported types and empty results in describe
1 parent 43353e2 commit 3ef34fd

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

bigframes/pandas/core/methods/describe.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ def describe(
5656
"max",
5757
]
5858
).intersection(describe_block.column_labels.get_level_values(-1))
59-
describe_block = describe_block.stack(override_labels=stack_cols)
60-
61-
return dataframe.DataFrame(describe_block).droplevel(level=0)
59+
if not stack_cols.empty:
60+
describe_block = describe_block.stack(override_labels=stack_cols)
61+
return dataframe.DataFrame(describe_block).droplevel(level=0)
62+
return dataframe.DataFrame(describe_block)
6263

6364

6465
def _describe(
@@ -120,5 +121,7 @@ def _get_aggs_for_dtype(dtype) -> list[aggregations.UnaryAggregateOp]:
120121
dtypes.TIME_DTYPE,
121122
]:
122123
return [aggregations.count_op, aggregations.nunique_op]
124+
elif dtypes.is_json_like(dtype) or dtype == dtypes.OBJ_REF_DTYPE:
125+
return [aggregations.count_op]
123126
else:
124127
return []

tests/system/small/pandas/test_describe.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,41 @@ def test_series_groupby_describe(scalars_dfs):
352352
check_dtype=False,
353353
check_index_type=False,
354354
)
355+
356+
357+
def test_describe_json_and_obj_ref_returns_count(session):
358+
# Test describe() works on JSON and OBJ_REF types (without nunique, which fails)
359+
sql = """
360+
SELECT
361+
PARSE_JSON('{"a": 1}') AS json_col,
362+
'gs://cloud-samples-data/vision/ocr/sign.jpg' AS uri_col
363+
"""
364+
df = session.read_gbq(sql)
365+
366+
df["obj_ref_col"] = df["uri_col"].str.to_blob()
367+
df = df.drop(columns=["uri_col"])
368+
369+
res = df.describe(include="all").to_pandas()
370+
371+
assert "count" in res.index
372+
assert res.loc["count", "json_col"] == 1.0
373+
assert res.loc["count", "obj_ref_col"] == 1.0
374+
375+
376+
def test_describe_with_unsupported_type_returns_empty_dataframe(session):
377+
df = session.read_gbq("SELECT ST_GEOGPOINT(1.0, 2.0) AS geo_col")
378+
379+
res = df.describe().to_pandas()
380+
381+
assert len(res.columns) == 0
382+
assert len(res.index) == 1
383+
384+
385+
def test_describe_empty_dataframe_returns_empty_dataframe(session):
386+
df = session.read_gbq("SELECT 1 AS int_col LIMIT 0")
387+
df = df.drop(columns=["int_col"])
388+
389+
res = df.describe().to_pandas()
390+
391+
assert len(res.columns) == 0
392+
assert len(res.index) == 1

0 commit comments

Comments
 (0)