Skip to content

Commit

Permalink
Only use arg when pyarrow>=4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Sep 22, 2021
1 parent a9ec5ca commit 4e46f83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 9 additions & 4 deletions google/cloud/bigquery/_pandas_helpers.py
Expand Up @@ -570,18 +570,23 @@ def dataframe_to_parquet(
compliant Parquet nested type (lists). Defaults to ``True``.
https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#nested-types
https://arrow.apache.org/docs/python/generated/pyarrow.parquet.write_table.html#pyarrow-parquet-write-table
This argument is ignored for ``pyarrow`` versions earlier than ``4.0.0``.
"""
pyarrow = _helpers.PYARROW_VERSIONS.try_import(raise_if_error=True)

import pyarrow.parquet

kwargs = (
{"use_compliant_nested_type": parquet_use_compliant_nested_type}
if _helpers._PYARROW_VERSION.major >= 4
else {}
)

bq_schema = schema._to_schema_fields(bq_schema)
arrow_table = dataframe_to_arrow(dataframe, bq_schema)
pyarrow.parquet.write_table(
arrow_table,
filepath,
compression=parquet_compression,
use_compliant_nested_type=parquet_use_compliant_nested_type,
arrow_table, filepath, compression=parquet_compression, **kwargs,
)


Expand Down
8 changes: 7 additions & 1 deletion google/cloud/bigquery/client.py
Expand Up @@ -2547,6 +2547,8 @@ def load_table_from_dataframe(
``DataFrame.to_parquet()`` method.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_parquet.html#pandas.DataFrame.to_parquet
This argument is ignored for ``pyarrow`` versions before ``4.0.0``.
This argument is only present to allow for backwards compatibility with
tables created using an old version of this method.
timeout (Optional[float]):
Expand Down Expand Up @@ -2679,7 +2681,11 @@ def load_table_from_dataframe(
tmppath,
engine="pyarrow",
compression=parquet_compression,
use_compliant_nested_type=parquet_use_compliant_nested_type,
**{
"use_compliant_nested_type": parquet_use_compliant_nested_type
}
if _PYARROW_VERSION.major >= 4
else {},
)

else:
Expand Down

0 comments on commit 4e46f83

Please sign in to comment.