Skip to content

Commit 2b7d7d2

Browse files
committed
fix: error for object dtype on read_pandas
1 parent 1caac27 commit 2b7d7d2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

‎bigframes/session/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
ReadPickleBuffer,
7272
StorageOptions,
7373
)
74+
import pandas.core.dtypes.common as pd_dtypes
7475
import pyarrow as pa
7576

7677
import bigframes._config.bigquery_options as bigquery_options
@@ -1005,6 +1006,13 @@ def _read_pandas(
10051006
"bigframes.pandas.DataFrame."
10061007
)
10071008

1009+
for column_name, dtype in pandas_dataframe.dtypes.items():
1010+
if pd_dtypes.is_object_dtype(dtype):
1011+
raise ValueError(
1012+
f"Column `{column_name}` has an unsupported dtype: `{dtype}`. "
1013+
+ f"{constants.FEEDBACK_LINK}"
1014+
)
1015+
10081016
inline_df = self._read_pandas_inline(pandas_dataframe)
10091017
if inline_df is not None:
10101018
return inline_df

‎tests/system/small/test_session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ def test_read_pandas(session, scalars_dfs):
421421
pd.testing.assert_frame_equal(result, expected)
422422

423423

424+
def test_read_pandas_w_unsupported_object_dtype(session):
425+
with pytest.raises(ValueError, match="unsupported dtype: `object`"):
426+
session.read_pandas(pd.DataFrame({"a": [1, "hello"]}))
427+
428+
424429
def test_read_pandas_inline_respects_location():
425430
options = bigframes.BigQueryOptions(location="europe-west1")
426431
session = bigframes.Session(options)

0 commit comments

Comments
 (0)