@@ -80,6 +80,36 @@ def is_compatible_with_partitions_def(
80
80
else :
81
81
return partitions_def is None
82
82
83
+ def _check_incoming_value_is_compatible (self , value : EntitySubsetValue ) -> None :
84
+ incoming_is_partitioned = not isinstance (value , bool )
85
+ if self .is_partitioned and not incoming_is_partitioned :
86
+ raise ValueError (
87
+ f"Cannot add { value } to subset. The types are incompatible. EntitySubset is partitioned"
88
+ )
89
+ if not self .is_partitioned and incoming_is_partitioned :
90
+ raise ValueError (
91
+ f"Cannot add { value } to subset. The types are incompatible. EntitySubset is not partitioned"
92
+ )
93
+
94
+ def add (self , value : EntitySubsetValue ) -> "SerializableEntitySubset" :
95
+ self ._check_incoming_value_is_compatible (value )
96
+
97
+ if self .is_partitioned :
98
+ return SerializableEntitySubset (
99
+ self .key , self .subset_value | check .inst (value , PartitionsSubset )
100
+ )
101
+ else :
102
+ return SerializableEntitySubset (self .key , True )
103
+
104
+ def remove (self , value : EntitySubsetValue ) -> "SerializableEntitySubset" :
105
+ self ._check_incoming_value_is_compatible (value )
106
+ if self .is_partitioned :
107
+ return SerializableEntitySubset (
108
+ self .key , self .subset_value - check .inst (value , PartitionsSubset )
109
+ )
110
+ else :
111
+ return SerializableEntitySubset (self .key , False )
112
+
83
113
def __contains__ (self , item : AssetKeyPartitionKey ) -> bool :
84
114
if not self .is_partitioned :
85
115
return item .asset_key == self .key and item .partition_key is None and self .bool_value
0 commit comments