Skip to content

fix: error for object dtype on read_pandas #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion bigframes/session/__init__.py
Original file line number Diff line number Diff line change
@@ -1050,7 +1050,12 @@ def _read_pandas(
inline_df = self._read_pandas_inline(pandas_dataframe)
if inline_df is not None:
return inline_df
return self._read_pandas_load_job(pandas_dataframe, api_name)
try:
return self._read_pandas_load_job(pandas_dataframe, api_name)
except pa.ArrowInvalid as e:
raise pa.ArrowInvalid(
f"Could not convert with a BigQuery type: `{e}`. "
) from e

def _read_pandas_inline(
self, pandas_dataframe: pandas.DataFrame
@@ -1064,6 +1069,10 @@ def _read_pandas_inline(
inline_df = dataframe.DataFrame(
blocks.Block.from_local(pandas_dataframe, self)
)
except pa.ArrowInvalid as e:
raise pa.ArrowInvalid(
f"Could not convert with a BigQuery type: `{e}`. "
) from e
except ValueError: # Thrown by ibis for some unhandled types
return None
except pa.ArrowTypeError: # Thrown by arrow for types without mapping (geo).
6 changes: 6 additions & 0 deletions tests/system/small/test_session.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
import google.cloud.bigquery as bigquery
import numpy as np
import pandas as pd
import pyarrow as pa
import pytest

import bigframes
@@ -436,6 +437,11 @@ def test_read_pandas_index(session):
pd.testing.assert_index_equal(bf_idx.to_pandas(), pd_idx)


def test_read_pandas_w_unsupported_mixed_dtype(session):
with pytest.raises(pa.ArrowInvalid, match="Could not convert"):
session.read_pandas(pd.DataFrame({"a": [1, "hello"]}))


def test_read_pandas_inline_respects_location():
options = bigframes.BigQueryOptions(location="europe-west1")
session = bigframes.Session(options)