Skip to content

Commit

Permalink
test: fix unit tests affected by pyarrow changes (#28)
Browse files Browse the repository at this point in the history
* testing: fix unit tests affected by pyarrow changes.

Previously, tests attempted to set field metadata in cases where there
was no metadata values to communicate.  Changes in pyarrow consider this
invalid as there's an expectation that metadata should be coercable to
bytes.

This change alters testing behavior to only propagate column
description metadata when it is present.
  • Loading branch information
shollyman committed May 21, 2020
1 parent b059924 commit 77b373b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -30,7 +30,7 @@
extras = {
"pandas": "pandas>=0.17.1",
"fastavro": "fastavro>=0.21.2",
"pyarrow": "pyarrow>=0.13.0, != 0.14.0",
"pyarrow": "pyarrow>=0.15.0",
}

package_root = os.path.abspath(os.path.dirname(__file__))
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_reader_v1.py
Expand Up @@ -233,12 +233,14 @@ def _bq_to_avro_schema(bq_columns):

def _bq_to_arrow_schema(bq_columns):
def bq_col_as_field(column):
doc = column.get("description")
metadata = None
if column.get("description") is not None:
metadata = {"description": column.get("description")}
name = column["name"]
type_ = BQ_TO_ARROW_TYPES[column["type"]]
mode = column.get("mode", "nullable").lower()

return pyarrow.field(name, type_, mode == "nullable", {"description": doc})
return pyarrow.field(name, type_, mode == "nullable", metadata)

return pyarrow.schema(bq_col_as_field(c) for c in bq_columns)

Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_reader_v1beta1.py
Expand Up @@ -234,12 +234,14 @@ def _bq_to_avro_schema(bq_columns):

def _bq_to_arrow_schema(bq_columns):
def bq_col_as_field(column):
doc = column.get("description")
metadata = None
if column.get("description") is not None:
metadata = {"description": column.get("description")}
name = column["name"]
type_ = BQ_TO_ARROW_TYPES[column["type"]]
mode = column.get("mode", "nullable").lower()

return pyarrow.field(name, type_, mode == "nullable", {"description": doc})
return pyarrow.field(name, type_, mode == "nullable", metadata)

return pyarrow.schema(bq_col_as_field(c) for c in bq_columns)

Expand Down

0 comments on commit 77b373b

Please sign in to comment.