Skip to content

Commit 82b4f91

Browse files
fix: Use actual BigQuery types rather than ibis types in to_pandas (#500)
* fix: use actual bigframes types rather than ibis types in to_pandas * Use ibis function that properly converts nested bq datatypes to ibis type
1 parent 4bfe094 commit 82b4f91

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

bigframes/dtypes.py

+11
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,17 @@ def ibis_type_from_python_type(t: type) -> ibis_dtypes.DataType:
682682

683683

684684
def ibis_type_from_type_kind(tk: bigquery.StandardSqlTypeNames) -> ibis_dtypes.DataType:
685+
"""Convert bq type to ibis. Only to be used for remote functions, does not handle all types."""
685686
if tk not in SUPPORTED_IO_BIGQUERY_TYPEKINDS:
686687
raise UnsupportedTypeError(tk, SUPPORTED_IO_BIGQUERY_TYPEKINDS)
687688
return third_party_ibis_bqtypes.BigQueryType.to_ibis(tk)
689+
690+
691+
def bf_type_from_type_kind(bf_schema) -> Dict[str, Dtype]:
692+
"""Converts bigquery sql type to the default bigframes dtype."""
693+
ibis_schema: ibis.Schema = third_party_ibis_bqtypes.BigQuerySchema.to_ibis(
694+
bf_schema
695+
)
696+
return {
697+
name: ibis_dtype_to_bigframes_dtype(type) for name, type in ibis_schema.items()
698+
}

bigframes/session/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,10 @@ def _get_table_size(self, destination_table):
18891889
def _rows_to_dataframe(
18901890
self, row_iterator: bigquery.table.RowIterator, dtypes: Dict
18911891
) -> pandas.DataFrame:
1892+
# Can ignore inferred datatype until dtype emulation breaks 1:1 mapping between BQ types and bigframes types
1893+
dtypes_from_bq = bigframes.dtypes.bf_type_from_type_kind(row_iterator.schema)
18921894
arrow_table = row_iterator.to_arrow()
1893-
return bigframes.session._io.pandas.arrow_to_pandas(arrow_table, dtypes)
1895+
return bigframes.session._io.pandas.arrow_to_pandas(arrow_table, dtypes_from_bq)
18941896

18951897
def _start_generic_job(self, job: formatting_helpers.GenericJob):
18961898
if bigframes.options.display.progress_bar is not None:

0 commit comments

Comments
 (0)