|
15 | 15 | import pandas.testing |
16 | 16 | import pytest |
17 | 17 |
|
| 18 | +import bigframes.pandas as bpd |
| 19 | + |
18 | 20 |
|
19 | 21 | def test_df_describe_non_temporal(scalars_dfs): |
20 | 22 | # TODO: supply a reason why this isn't compatible with pandas 1.x |
@@ -352,3 +354,40 @@ def test_series_groupby_describe(scalars_dfs): |
352 | 354 | check_dtype=False, |
353 | 355 | check_index_type=False, |
354 | 356 | ) |
| 357 | + |
| 358 | + |
| 359 | +def test_describe_json_and_obj_ref_returns_count(session): |
| 360 | + # Test describe() works on JSON and OBJ_REF types (without nunique, which fails) |
| 361 | + sql = """ |
| 362 | + SELECT |
| 363 | + PARSE_JSON('{"a": 1}') AS json_col, |
| 364 | + 'gs://cloud-samples-data/vision/ocr/sign.jpg' AS uri_col |
| 365 | + """ |
| 366 | + df = session.read_gbq(sql) |
| 367 | + |
| 368 | + df["obj_ref_col"] = df["uri_col"].str.to_blob() |
| 369 | + df = df.drop(columns=["uri_col"]) |
| 370 | + |
| 371 | + res = df.describe(include="all").to_pandas() |
| 372 | + |
| 373 | + assert "count" in res.index |
| 374 | + assert res.loc["count", "json_col"] == 1.0 |
| 375 | + assert res.loc["count", "obj_ref_col"] == 1.0 |
| 376 | + |
| 377 | + |
| 378 | +def test_describe_with_unsupported_type_returns_empty_dataframe(session): |
| 379 | + df = session.read_gbq("SELECT ST_GEOGPOINT(1.0, 2.0) AS geo_col") |
| 380 | + |
| 381 | + res = df.describe().to_pandas() |
| 382 | + |
| 383 | + assert len(res.columns) == 0 |
| 384 | + assert len(res.index) == 1 |
| 385 | + |
| 386 | + |
| 387 | +def test_describe_empty_dataframe_returns_empty_dataframe(session): |
| 388 | + df = bpd.DataFrame() |
| 389 | + |
| 390 | + res = df.describe().to_pandas() |
| 391 | + |
| 392 | + assert len(res.columns) == 0 |
| 393 | + assert len(res.index) == 1 |
0 commit comments