Skip to content

Commit

Permalink
fix: broken test after change in python-bigquery
Browse files Browse the repository at this point in the history
Following this change:
googleapis/python-bigquery#1408
the SchemaField __init__ and __repr__ method have evolved.

This broke some tests.
  • Loading branch information
FurcyPin committed Dec 3, 2022
1 parent c8e9c49 commit fd025b2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions bigquery_frame/data_diff/dataframe_comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def _schema_to_string(
c1 STRING (nullable)
c2 INTEGER (nullable)
>>> schema = [
... SchemaField('id', 'INTEGER', 'NULLABLE', 'An id', (), None),
... SchemaField('c1', 'STRING', 'REQUIRED', 'A string column', (), None),
... SchemaField('c2', 'INTEGER', 'NULLABLE', 'An int column', (), None)
... SchemaField(name='id', field_type='INTEGER', mode='NULLABLE', description='An id'),
... SchemaField(name='c1', field_type='STRING', mode='REQUIRED', description='A string column'),
... SchemaField(name='c2', field_type='INTEGER', mode='NULLABLE', description='An int column')
... ]
>>> print('\\n'.join(df_comparator._schema_to_string(schema, include_nullable=True, include_metadata=True)))
id INTEGER (nullable) An id
Expand Down
2 changes: 1 addition & 1 deletion bigquery_frame/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def schema_to_simple_string(schema: List[SchemaField]):
>>> bq = BigQueryBuilder()
>>> df = bq.sql('SELECT 1 as id, STRUCT(1 as a, [STRUCT(2 as c, 3 as d)] as b, [4, 5] as e) as s')
>>> print(df.schema) # noqa: E501
[SchemaField('id', 'INTEGER', 'NULLABLE', None, (), None), SchemaField('s', 'RECORD', 'NULLABLE', None, (SchemaField('a', 'INTEGER', 'NULLABLE', None, (), None), SchemaField('b', 'RECORD', 'REPEATED', None, (SchemaField('c', 'INTEGER', 'NULLABLE', None, (), None), SchemaField('d', 'INTEGER', 'NULLABLE', None, (), None)), None), SchemaField('e', 'INTEGER', 'REPEATED', None, (), None)), None)]
[SchemaField('id', 'INTEGER', 'NULLABLE', None, None, (), None), SchemaField('s', 'RECORD', 'NULLABLE', None, None, (SchemaField('a', 'INTEGER', 'NULLABLE', None, None, (), None), SchemaField('b', 'RECORD', 'REPEATED', None, None, (SchemaField('c', 'INTEGER', 'NULLABLE', None, None, (), None), SchemaField('d', 'INTEGER', 'NULLABLE', None, None, (), None)), None), SchemaField('e', 'INTEGER', 'REPEATED', None, None, (), None)), None)]
>>> schema_to_simple_string(df.schema)
'id:INTEGER,s:STRUCT<a:INTEGER,b:ARRAY<STRUCT<c:INTEGER,d:INTEGER>>,e:ARRAY<INTEGER>>'
Expand Down
10 changes: 5 additions & 5 deletions bigquery_frame/transformations_impl/flatten_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def flatten_schema_field(prefix: str, schema_field: SchemaField, nullable: bool)
mode = "REPEATED"
return [
SchemaField(
prefix,
schema_field.field_type,
mode,
schema_field.description,
schema_field.fields,
name=prefix,
field_type=schema_field.field_type,
mode=mode,
description=schema_field.description,
fields=schema_field.fields,
)
]

Expand Down
38 changes: 19 additions & 19 deletions tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def test_createOrReplaceTempView(bq: BigQueryBuilder):
df2 = bq.sql("""SELECT * FROM pokedex""")

expected = [
SchemaField("id", "INTEGER", "NULLABLE", None, (), None),
SchemaField("name", "STRING", "NULLABLE", None, (), None),
SchemaField("types", "STRING", "REPEATED", None, (), None),
SchemaField("other_col", "INTEGER", "NULLABLE", None, (), None),
SchemaField(name="id", field_type="INTEGER", mode="NULLABLE"),
SchemaField(name="name", field_type="STRING", mode="NULLABLE"),
SchemaField(name="types", field_type="STRING", mode="REPEATED"),
SchemaField(name="other_col", field_type="INTEGER", mode="NULLABLE"),
]

assert df2.schema == expected
Expand All @@ -29,7 +29,7 @@ def test_createOrReplaceTempView_with_reserved_keyword_alias(bq: BigQueryBuilder
bq.sql("""SELECT 1 as id""").createOrReplaceTempView("all")
df = bq.table("all")

expected = [SchemaField("id", "INTEGER", "NULLABLE", None, (), None)]
expected = [SchemaField(name="id", field_type="INTEGER", mode="NULLABLE")]

assert df.schema == expected

Expand Down Expand Up @@ -66,10 +66,10 @@ def test_createOrReplaceTempTable(bq: BigQueryBuilder):
df2 = bq.sql("""SELECT * FROM pokedex""")

expected = [
SchemaField("id", "INTEGER", "NULLABLE", None, (), None),
SchemaField("name", "STRING", "NULLABLE", None, (), None),
SchemaField("types", "STRING", "REPEATED", None, (), None),
SchemaField("other_col", "INTEGER", "NULLABLE", None, (), None),
SchemaField(name="id", field_type="INTEGER", mode="NULLABLE"),
SchemaField(name="name", field_type="STRING", mode="NULLABLE"),
SchemaField(name="types", field_type="STRING", mode="REPEATED"),
SchemaField(name="other_col", field_type="INTEGER", mode="NULLABLE"),
]

assert df2.schema == expected
Expand All @@ -81,7 +81,7 @@ def test_createOrReplaceTempTable_with_reserved_keyword_alias(bq: BigQueryBuilde
bq.sql("""SELECT 1 as id""").createOrReplaceTempTable("all")
df = bq.table("all")

expected = [SchemaField("id", "INTEGER", "NULLABLE", None, (), None)]
expected = [SchemaField(name="id", field_type="INTEGER", mode="NULLABLE")]

assert df.schema == expected

Expand All @@ -98,8 +98,8 @@ def test_select(bq: BigQueryBuilder):
df = bq.sql("""SELECT 1 as c1, 2 as c2""").select("c1", "c2").select(["c1", "c2"])

expected = [
SchemaField("c1", "INTEGER", "NULLABLE", None, (), None),
SchemaField("c2", "INTEGER", "NULLABLE", None, (), None),
SchemaField(name="c1", field_type="INTEGER", mode="NULLABLE"),
SchemaField(name="c2", field_type="INTEGER", mode="NULLABLE"),
]

assert df.schema == expected
Expand All @@ -117,10 +117,10 @@ def test_bare_strings(bq: BigQueryBuilder):
df5 = df4.withColumn("name", "LOWER(name)", replace=True)

expected = [
SchemaField("id", "INTEGER", "NULLABLE", None, (), None),
SchemaField("name", "STRING", "NULLABLE", None, (), None),
SchemaField("types", "STRING", "REPEATED", None, (), None),
SchemaField("nb_types", "INTEGER", "NULLABLE", None, (), None),
SchemaField(name="id", field_type="INTEGER", mode="NULLABLE"),
SchemaField(name="name", field_type="STRING", mode="NULLABLE"),
SchemaField(name="types", field_type="STRING", mode="REPEATED"),
SchemaField(name="nb_types", field_type="INTEGER", mode="NULLABLE"),
]

assert df5.schema == expected
Expand Down Expand Up @@ -176,9 +176,9 @@ def test_drop(bq: BigQueryBuilder):
df2 = df.drop("other_col", "col_that_does_not_exists")

expected = [
SchemaField("id", "INTEGER", "NULLABLE", None, (), None),
SchemaField("name", "STRING", "NULLABLE", None, (), None),
SchemaField("types", "STRING", "REPEATED", None, (), None),
SchemaField(name="id", field_type="INTEGER", mode="NULLABLE"),
SchemaField(name="name", field_type="STRING", mode="NULLABLE"),
SchemaField(name="types", field_type="STRING", mode="REPEATED"),
]

assert df2.schema == expected
Expand Down

0 comments on commit fd025b2

Please sign in to comment.