Skip to content

Commit

Permalink
data type consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
sbilge committed Dec 17, 2024
1 parent ac9bd78 commit 95338a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/metldata/builtin_transformations/common/assumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ class in the provided `path_element`, depending on the type of the relation path


def assert_object_path_required(json_schema: Mapping[str, Any], path: str) -> None:
"""Ensures that a path exists and its components are marked as 'required' in the schemapack.
This validates that any transformation relying on that path can depend on its presence
in a datapack.
"""Ensures that a given object path in a JSON schema is marked as required.
This validates that any transformation relying on that path can depend on its
presence in a datapack.
If the path is an empty string, no validation is required.
"""
if not path:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def resolve_active_path_element(
data: DataPack,
source_resource_id: ResourceId,
path_element: RelationPathElement,
) -> set[ResourceId] | frozenset[ResourceId]:
) -> frozenset[ResourceId]:
"""Resolve the given relation inference path element of active type for the given
source resource.
Expand Down Expand Up @@ -95,9 +95,9 @@ def resolve_active_path_element(
raise EvitableTransformationError()
target_resource_ids = source_resource.relations.get(path_element.property)
if target_resource_ids is None:
target_resource_ids = set()
target_resource_ids = frozenset()
elif isinstance(target_resource_ids, str):
target_resource_ids = {target_resource_ids}
target_resource_ids = frozenset({target_resource_ids})
return target_resource_ids


Expand All @@ -106,7 +106,7 @@ def resolve_passive_path_element(
data: DataPack,
source_resource_id: ResourceId,
path_element: RelationPathElement,
) -> set[ResourceId]:
) -> frozenset[ResourceId]:
"""Resolve the given relation inference path element of passive type for the given
source resource.
Expand Down Expand Up @@ -137,15 +137,15 @@ def resolve_passive_path_element(
) or source_resource_id == relation:
target_resource_ids.add(candidate_resource_id)

return target_resource_ids
return frozenset(target_resource_ids)


def resolve_path_element(
*,
data: DataPack,
source_resource_id: ResourceId,
path_element: RelationPathElement,
) -> set[ResourceId] | frozenset[ResourceId]:
) -> frozenset[ResourceId]:
"""Resolve the given relation inference path element for the given source resource.
Args:
Expand All @@ -171,7 +171,7 @@ def resolve_path_element(

def resolve_path(
*, data: DataPack, source_resource_id: ResourceId, path: RelationPath
) -> set[ResourceId]:
) -> frozenset[ResourceId]:
"""Resolve the given relation inference path for the given source resource.
Args:
Expand All @@ -197,7 +197,7 @@ def resolve_path(
)
}

return resource_ids
return frozenset(resource_ids)


def add_inferred_relations(
Expand All @@ -220,9 +220,7 @@ def add_inferred_relations(
update={
"relations": {
**host_resource.relations,
instruction.new_property: frozenset(
target_resource_ids
), # freeze inferred relations for datapack data type compatibility
instruction.new_property: target_resource_ids,
}
}
)
Expand Down

0 comments on commit 95338a2

Please sign in to comment.