Skip to content

Commit 20f473b

Browse files
fix: make TimePartitioning repr evaluable (#110)
Fixes #109 🦕
1 parent 5ea1ece commit 20f473b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

google/cloud/bigquery/table.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,20 @@ def to_api_repr(self):
21142114
return self._properties
21152115

21162116
def _key(self):
2117-
return tuple(sorted(self._properties.items()))
2117+
# because we are only "renaming" top level keys shallow copy is sufficient here.
2118+
properties = self._properties.copy()
2119+
# calling repr for non built-in type objects.
2120+
properties["type_"] = repr(properties.pop("type"))
2121+
if "field" in properties:
2122+
# calling repr for non built-in type objects.
2123+
properties["field"] = repr(properties["field"])
2124+
if "requirePartitionFilter" in properties:
2125+
properties["require_partition_filter"] = properties.pop(
2126+
"requirePartitionFilter"
2127+
)
2128+
if "expirationMs" in properties:
2129+
properties["expiration_ms"] = properties.pop("expirationMs")
2130+
return tuple(sorted(properties.items()))
21182131

21192132
def __eq__(self, other):
21202133
if not isinstance(other, TimePartitioning):

tests/unit/test_table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,7 +3711,7 @@ def test___hash__not_equals(self):
37113711

37123712
def test___repr___minimal(self):
37133713
time_partitioning = self._make_one()
3714-
expected = "TimePartitioning(type=DAY)"
3714+
expected = "TimePartitioning(type_='DAY')"
37153715
self.assertEqual(repr(time_partitioning), expected)
37163716

37173717
def test___repr___explicit(self):
@@ -3720,7 +3720,7 @@ def test___repr___explicit(self):
37203720
time_partitioning = self._make_one(
37213721
type_=TimePartitioningType.DAY, field="name", expiration_ms=10000
37223722
)
3723-
expected = "TimePartitioning(" "expirationMs=10000," "field=name," "type=DAY)"
3723+
expected = "TimePartitioning(expiration_ms=10000,field='name',type_='DAY')"
37243724
self.assertEqual(repr(time_partitioning), expected)
37253725

37263726
def test_set_expiration_w_none(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy