Skip to content

Commit

Permalink
fix: Makes TimePartitioning printable representation evaluable
Browse files Browse the repository at this point in the history
  • Loading branch information
francois-baptiste authored and François BAPTISTE committed May 19, 2020
1 parent 23a173b commit 1450f4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions google/cloud/bigquery/table.py
Expand Up @@ -2128,7 +2128,14 @@ def to_api_repr(self):
return self._properties

def _key(self):
return tuple(sorted(self._properties.items()))
properties = self._properties.copy()
if "type" in properties.keys():
properties["type_"] = properties.pop("type")
if "requirePartitionFilter" in properties.keys():
properties["require_partition_filter"] = properties.pop("requirePartitionFilter")
if "expirationMs" in properties.keys():
properties["expiration_ms"] = properties.pop("expirationMs")
return tuple(sorted(properties.items()))

def __eq__(self, other):
if not isinstance(other, TimePartitioning):
Expand All @@ -2142,7 +2149,7 @@ def __hash__(self):
return hash(self._key())

def __repr__(self):
key_vals = ["{}={}".format(key, val) for key, val in self._key()]
key_vals = ["{}={}".format(key, repr(val)) for key, val in self._key()]
return "TimePartitioning({})".format(",".join(key_vals))


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_table.py
Expand Up @@ -3743,7 +3743,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 @@ -3752,7 +3752,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 1450f4f

Please sign in to comment.