Skip to content

Commit 4b6c3d7

Browse files
committed
add and remove methods on SerializableEntitySubset
1 parent 068ac9f commit 4b6c3d7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

python_modules/dagster/dagster/_core/asset_graph_view/serializable_entity_subset.py

+30
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,36 @@ def is_compatible_with_partitions_def(
8080
else:
8181
return partitions_def is None
8282

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+
83113
def __contains__(self, item: AssetKeyPartitionKey) -> bool:
84114
if not self.is_partitioned:
85115
return item.asset_key == self.key and item.partition_key is None and self.bool_value

0 commit comments

Comments
 (0)