Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d2a88d

Browse files
feat(bigquery): add __eq__ method for class PartitionRange and RangePartitioning (#162)
* feat(bigquery): add __eq__ method for class PartitionRange and RangePartitioning* feat(bigquery): change class object to unhashable* feat(bigquery): change the assertion
1 parentdbaf3bd commit0d2a88d

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

‎google/cloud/bigquery/table.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,10 +1891,20 @@ def interval(self, value):
18911891
def_key(self):
18921892
returntuple(sorted(self._properties.items()))
18931893

1894+
def__eq__(self,other):
1895+
ifnotisinstance(other,PartitionRange):
1896+
returnNotImplemented
1897+
returnself._key()==other._key()
1898+
1899+
def__ne__(self,other):
1900+
returnnotself==other
1901+
18941902
def__repr__(self):
18951903
key_vals= ["{}={}".format(key,val)forkey,valinself._key()]
18961904
return"PartitionRange({})".format(", ".join(key_vals))
18971905

1906+
__hash__=None
1907+
18981908

18991909
classRangePartitioning(object):
19001910
"""Range-based partitioning configuration for a table.
@@ -1961,10 +1971,20 @@ def field(self, value):
19611971
def_key(self):
19621972
return (("field",self.field), ("range_",self.range_))
19631973

1974+
def__eq__(self,other):
1975+
ifnotisinstance(other,RangePartitioning):
1976+
returnNotImplemented
1977+
returnself._key()==other._key()
1978+
1979+
def__ne__(self,other):
1980+
returnnotself==other
1981+
19641982
def__repr__(self):
19651983
key_vals= ["{}={}".format(key,repr(val))forkey,valinself._key()]
19661984
return"RangePartitioning({})".format(", ".join(key_vals))
19671985

1986+
__hash__=None
1987+
19681988

19691989
classTimePartitioningType(object):
19701990
"""Specifies the type of time partitioning to perform."""

‎tests/unit/test_table.py‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,6 +3525,37 @@ def test_constructor_w_resource(self):
35253525
assertobject_under_test.end==1234567890
35263526
assertobject_under_test.interval==1000000
35273527

3528+
deftest___eq___start_mismatch(self):
3529+
object_under_test=self._make_one(start=1,end=10,interval=2)
3530+
other=self._make_one(start=2,end=10,interval=2)
3531+
self.assertNotEqual(object_under_test,other)
3532+
3533+
deftest___eq___end__mismatch(self):
3534+
object_under_test=self._make_one(start=1,end=10,interval=2)
3535+
other=self._make_one(start=1,end=11,interval=2)
3536+
self.assertNotEqual(object_under_test,other)
3537+
3538+
deftest___eq___interval__mismatch(self):
3539+
object_under_test=self._make_one(start=1,end=10,interval=2)
3540+
other=self._make_one(start=1,end=11,interval=3)
3541+
self.assertNotEqual(object_under_test,other)
3542+
3543+
deftest___eq___hit(self):
3544+
object_under_test=self._make_one(start=1,end=10,interval=2)
3545+
other=self._make_one(start=1,end=10,interval=2)
3546+
self.assertEqual(object_under_test,other)
3547+
3548+
deftest__eq___type_mismatch(self):
3549+
object_under_test=self._make_one(start=1,end=10,interval=2)
3550+
self.assertNotEqual(object_under_test,object())
3551+
self.assertEqual(object_under_test,mock.ANY)
3552+
3553+
deftest_unhashable_object(self):
3554+
object_under_test1=self._make_one(start=1,end=10,interval=2)
3555+
3556+
withsix.assertRaisesRegex(self,TypeError,r".*unhashable type.*"):
3557+
hash(object_under_test1)
3558+
35283559
deftest_repr(self):
35293560
object_under_test=self._make_one(start=1,end=10,interval=2)
35303561
assertrepr(object_under_test)=="PartitionRange(end=10, interval=2, start=1)"
@@ -3574,6 +3605,57 @@ def test_range_w_wrong_type(self):
35743605
withpytest.raises(ValueError,match="PartitionRange"):
35753606
object_under_test.range_=object()
35763607

3608+
deftest___eq___field_mismatch(self):
3609+
fromgoogle.cloud.bigquery.tableimportPartitionRange
3610+
3611+
object_under_test=self._make_one(
3612+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3613+
)
3614+
other=self._make_one(
3615+
range_=PartitionRange(start=1,end=10,interval=2),field="float_col"
3616+
)
3617+
self.assertNotEqual(object_under_test,other)
3618+
3619+
deftest___eq___range__mismatch(self):
3620+
fromgoogle.cloud.bigquery.tableimportPartitionRange
3621+
3622+
object_under_test=self._make_one(
3623+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3624+
)
3625+
other=self._make_one(
3626+
range_=PartitionRange(start=2,end=20,interval=2),field="float_col"
3627+
)
3628+
self.assertNotEqual(object_under_test,other)
3629+
3630+
deftest___eq___hit(self):
3631+
fromgoogle.cloud.bigquery.tableimportPartitionRange
3632+
3633+
object_under_test=self._make_one(
3634+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3635+
)
3636+
other=self._make_one(
3637+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3638+
)
3639+
self.assertEqual(object_under_test,other)
3640+
3641+
deftest__eq___type_mismatch(self):
3642+
fromgoogle.cloud.bigquery.tableimportPartitionRange
3643+
3644+
object_under_test=self._make_one(
3645+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3646+
)
3647+
self.assertNotEqual(object_under_test,object())
3648+
self.assertEqual(object_under_test,mock.ANY)
3649+
3650+
deftest_unhashable_object(self):
3651+
fromgoogle.cloud.bigquery.tableimportPartitionRange
3652+
3653+
object_under_test1=self._make_one(
3654+
range_=PartitionRange(start=1,end=10,interval=2),field="integer_col"
3655+
)
3656+
withsix.assertRaisesRegex(self,TypeError,r".*unhashable type.*"):
3657+
hash(object_under_test1)
3658+
35773659
deftest_repr(self):
35783660
fromgoogle.cloud.bigquery.tableimportPartitionRange
35793661

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp