File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
tests/system/small/pandas Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -3417,6 +3417,11 @@ def unpivot(
34173417 joined_array , (labels_mapping , column_mapping ) = labels_array .relational_join (
34183418 array_value , type = "cross"
34193419 )
3420+
3421+ if not labels_array .column_ids :
3422+ # A valid unpivot operation requires at least one row label to disambiguate the output rows.
3423+ raise ValueError ("unpivot requires non-empty row_labels" )
3424+
34203425 new_passthrough_cols = [column_mapping [col ] for col in passthrough_columns ]
34213426 # Last column is offsets
34223427 index_col_ids = [labels_mapping [col ] for col in labels_array .column_ids [:- 1 ]]
Original file line number Diff line number Diff 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
6465def _describe (
@@ -120,10 +121,7 @@ def _get_aggs_for_dtype(dtype) -> list[aggregations.UnaryAggregateOp]:
120121 dtypes .TIME_DTYPE ,
121122 ]:
122123 return [aggregations .count_op , aggregations .nunique_op ]
123- elif dtype in [
124- dtypes .JSON_DTYPE ,
125- dtypes .OBJ_REF_DTYPE ,
126- ]:
124+ elif dtypes .is_json_like (dtype ) or dtype == dtypes .OBJ_REF_DTYPE :
127125 return [aggregations .count_op ]
128126 else :
129127 return []
Original file line number Diff line number Diff line change @@ -371,3 +371,22 @@ def test_describe_json_and_obj_ref_returns_count(session):
371371 assert "count" in res .index
372372 assert res .loc ["count" , "json_col" ] == 1.0
373373 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
You can’t perform that action at this time.
0 commit comments