Skip to content

Commit bcd9cb7

Browse files
committed
Fix: Handle single-column DataFrame dtypes in TableWidget
1 parent 169b9f4 commit bcd9cb7

File tree

4 files changed

+8
-86
lines changed

4 files changed

+8
-86
lines changed

bigframes/core/blocks.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,28 +3471,6 @@ def _pd_index_to_array_value(
34713471
Create an ArrayValue from a list of label tuples.
34723472
The last column will be row offsets.
34733473
"""
3474-
if index.empty:
3475-
id_gen = bigframes.core.identifiers.standard_id_strings()
3476-
col_ids = [next(id_gen) for _ in range(index.nlevels + 1)]
3477-
3478-
data_dict = {}
3479-
if isinstance(index, pd.MultiIndex):
3480-
dtypes = index.dtypes.values.tolist()
3481-
else:
3482-
dtypes = [index.dtype]
3483-
3484-
for col_id, dtype in zip(col_ids[:-1], dtypes):
3485-
try:
3486-
bf_dtype = bigframes.dtypes.bigframes_type(dtype)
3487-
pa_type = bigframes.dtypes.bigframes_dtype_to_arrow_dtype(bf_dtype)
3488-
except TypeError:
3489-
pa_type = pa.string()
3490-
data_dict[col_id] = pa.array([], type=pa_type)
3491-
3492-
data_dict[col_ids[-1]] = pa.array([], type=pa.int64())
3493-
table = pa.Table.from_pydict(data_dict)
3494-
return core.ArrayValue.from_pyarrow(table, session=session)
3495-
34963474
rows = []
34973475
labels_as_tuples = utils.index_as_tuples(index)
34983476
for row_offset in range(len(index)):

bigframes/display/anywidget.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
111111
# TODO(b/463754889): Support non-string column labels for sorting.
112112
if all(isinstance(col, str) for col in dataframe.columns):
113113
# TODO(b/462525985): dataframe.dtypes should always be a Series.
114-
items = (
115-
dataframe.dtypes.items()
116-
if isinstance(dataframe.dtypes, pd.Series)
117-
else [(dataframe.columns[0], dataframe.dtypes)]
118-
)
114+
if isinstance(dataframe.dtypes, pd.Series):
115+
items = dataframe.dtypes.items()
116+
else:
117+
items = [(dataframe.columns[0], dataframe.dtypes)]
119118
self.orderable_columns = [
120119
str(col_name) for col_name, dtype in items if dtypes.is_orderable(dtype)
121120
]

bigframes/session/bq_caching_executor.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,13 @@ def _export_gbq(
326326
session=array_value.session,
327327
)
328328

329-
has_complex_col = any(
330-
t in (bigframes.dtypes.TIMEDELTA_DTYPE, bigframes.dtypes.OBJ_REF_DTYPE)
331-
for t in array_value.schema.dtypes
329+
has_timedelta_col = any(
330+
t == bigframes.dtypes.TIMEDELTA_DTYPE for t in array_value.schema.dtypes
332331
)
333332

334-
if spec.if_exists != "append" and has_complex_col:
333+
if spec.if_exists != "append" and has_timedelta_col:
335334
# Only update schema if this is not modifying an existing table, and the
336-
# new table contains complex columns (timedelta, object reference).
335+
# new table contains timedelta columns.
337336
table = self.bqclient.get_table(spec.table)
338337
table.schema = array_value.schema.to_bigquery()
339338
self.bqclient.update_table(table, ["schema"])

tests/unit/core/test_blocks_unpivot.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)