Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make the same Table* instances equal to each other #867

Merged
merged 6 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make Table instances hashable
  • Loading branch information
plamut committed Aug 11, 2021
commit ae220ecd133e3823ed6584b96490a618435a2202
3 changes: 2 additions & 1 deletion google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,8 @@ def __eq__(self, other):
return NotImplemented
return self._properties["tableReference"] == other._properties["tableReference"]

__hash__ = None
def __hash__(self):
return hash((self.project, self.dataset_id, self.table_id))

def __repr__(self):
return "Table({})".format(repr(self.reference))
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,15 @@ def test__eq__different_table(self):

assert table_1 != table_2

def test_hashable(self):
table_1 = self._make_one("project_foo.dataset_bar.table_baz")
table_1.description = "This is a table"

table_1b = self._make_one("project_foo.dataset_bar.table_baz")
table_1b.description = "Metadata is irrelevant for hashes"

assert hash(table_1) == hash(table_1b)

def test_schema_setter_non_sequence(self):
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
Expand Down