Skip to content

Commit

Permalink
fix: make TimePartitioning repr evaluable (#110)
Browse files Browse the repository at this point in the history
Fixes #109  🦕
  • Loading branch information
francois-baptiste committed Oct 13, 2020
1 parent 5ea1ece commit 20f473b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion google/cloud/bigquery/table.py
Expand Up @@ -2114,7 +2114,20 @@ def to_api_repr(self):
return self._properties

def _key(self):
return tuple(sorted(self._properties.items()))
# because we are only "renaming" top level keys shallow copy is sufficient here.
properties = self._properties.copy()
# calling repr for non built-in type objects.
properties["type_"] = repr(properties.pop("type"))
if "field" in properties:
# calling repr for non built-in type objects.
properties["field"] = repr(properties["field"])
if "requirePartitionFilter" in properties:
properties["require_partition_filter"] = properties.pop(
"requirePartitionFilter"
)
if "expirationMs" in properties:
properties["expiration_ms"] = properties.pop("expirationMs")
return tuple(sorted(properties.items()))

def __eq__(self, other):
if not isinstance(other, TimePartitioning):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_table.py
Expand Up @@ -3711,7 +3711,7 @@ def test___hash__not_equals(self):

def test___repr___minimal(self):
time_partitioning = self._make_one()
expected = "TimePartitioning(type=DAY)"
expected = "TimePartitioning(type_='DAY')"
self.assertEqual(repr(time_partitioning), expected)

def test___repr___explicit(self):
Expand All @@ -3720,7 +3720,7 @@ def test___repr___explicit(self):
time_partitioning = self._make_one(
type_=TimePartitioningType.DAY, field="name", expiration_ms=10000
)
expected = "TimePartitioning(" "expirationMs=10000," "field=name," "type=DAY)"
expected = "TimePartitioning(expiration_ms=10000,field='name',type_='DAY')"
self.assertEqual(repr(time_partitioning), expected)

def test_set_expiration_w_none(self):
Expand Down

0 comments on commit 20f473b

Please sign in to comment.