pyarrow.lib.ArrowTypeError: Expected bytes, got a 'dict' object
See original GitHub issueHi! there is a problem when trying to load using pandas-gbq which using pyarrow a column of the list (array) or dictionary (json) type into the table, while the GBQ documentation says that structure types such as array or json are supported,
df = pd.DataFrame(
{
"my_string": ["a", "b", "c"],
"my_int64": [1, 2, 3],
"my_float64": [4.0, 5.0, 6.0],
"my_bool1": [True, False, True],
"my_bool2": [False, True, False],
"my_struct": [{"test":"str1"},{"test":"str2"},{"test":"str3"}],
}
)
pandas_gbq.to_gbq(df, **gbq_params)
as a result, a stacktrace error occurs:
- in bq_to_arrow_array
- return pyarrow.Array.from_pandas(series, type=arrow_type)
- File “pyarrow/array.pxi”, line 913, in pyarrow.lib.Array.from_pandas
- File “pyarrow/array.pxi”, line 311, in pyarrow.lib.array
- File “pyarrow/array.pxi”, line 83, in pyarrow.lib._ndarray_to_array
- File “pyarrow/error.pxi”, line 122, in pyarrow.lib.check_status
- pyarrow.lib.ArrowTypeError: Expected bytes, got a ‘dict’ object
Can anyone help with it please?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
pyarrow.lib.ArrowTypeError: "Expected a string or bytes object ...
STEP-1: Convert the pandas dataframe into pyarrow table with following line of code. table = pa.Table.from_pandas(df_image_0). STEP-2: Now, ...
Read more >Expected bytes, got a 'int' object) - Stack Overflow
Error while converting pandas dataframe to polars dataframe (pyarrow.lib.ArrowTypeError: Expected bytes, got a 'int' object) · Ask Question.
Read more >[#ARROW-7663] [Python] from_pandas gives TypeError ...
from_pandas sometimes raises a TypeError with an uninformative error message rather than an ArrowTypeError with the full, informative type error for ...
Read more >Pandas to_gbq() TypeError "Expected bytes, got a 'int' object ...
I keep getting an ArrowTypeError: Expected bytes, got a 'int' object. I can confirm the data types of the dataframe match the schema...
Read more >("Expected bytes, got a 'int' object", 'Conversion failed for ...
Was playing around with some charting with the Altair library. Everything was going well until I hit this error when using some of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
any updates on this? getting the same error. the strange thing is that the code works well locally and in compute engine, but fails in cloud run (even though the same service account is being used for both)
Has there been any progress on updating this issue? I am seeing the same error message.
Could we elaborate on:
I believe we can avoid this problem with https://github.com/googleapis/python-bigquery-pandas/issues/339 where instead of pandas-gbq creating the table, we create the table as part of the load job.
As I am seeing the same issue even with a created table, and using (if_exists=‘replace’):
The work-around that helped me to successfully load my table was casting the dataframe column to
string
data type.As an example GCP Cloud Function:
This produces the error mentioned in this thread:
With
requirements.txt
asWhen pushing the column casting I added a single line and ended up with:
This helps to successfully load the table into BigQuery with schema:
If you need the my_struct to be an actual struct consider: