-
Notifications
You must be signed in to change notification settings - Fork 26
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
Infer consume operation if not present in dataset interface #859
Merged
RobbeSneyders
merged 5 commits into
main
from
feature/passing-all-columns-to-the-write-component
Feb 20, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
from fondant.core.manifest import Manifest | ||
from fondant.core.schema import Field | ||
from fondant.pipeline import Image, LightweightComponent | ||
from fondant.pipeline.argument_inference import infer_arguments | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -185,25 +184,60 @@ def __init__( | |
self.resources = resources or Resources() | ||
|
||
@classmethod | ||
def from_component_yaml(cls, path, **kwargs) -> "ComponentOp": | ||
def from_component_yaml(cls, path, fields=None, **kwargs) -> "ComponentOp": | ||
if cls._is_custom_component(path): | ||
component_dir = Path(path) | ||
else: | ||
component_dir = cls._get_registry_path(str(path)) | ||
|
||
component_spec = ComponentSpec.from_file( | ||
component_dir / cls.COMPONENT_SPEC_NAME, | ||
) | ||
|
||
# If consumes is not defined in the pipeline, we will try to infer it | ||
if kwargs.get("consumes") is None: | ||
kwargs["consumes"] = cls._infer_consumes(component_spec, fields) | ||
|
||
image = Image( | ||
base_image=component_spec.image, | ||
) | ||
|
||
return cls( | ||
image=image, | ||
component_spec=component_spec, | ||
component_dir=component_dir, | ||
**kwargs, | ||
) | ||
|
||
@classmethod | ||
def _infer_consumes(cls, component_spec, dataset_fields): | ||
"""Infer the consumes section of the component spec.""" | ||
if component_spec.consumes_is_defined is False: | ||
msg = ( | ||
"The consumes section of the component spec is not defined. " | ||
"Can not infer consumes of the OperationSpec. Please define a consumes section " | ||
"in the dataset interface. " | ||
) | ||
logger.info(msg) | ||
return None | ||
|
||
# Component has consumes and additionalProperties, we will load all dataset columns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering about the case here where there's both a schema and |
||
if ( | ||
component_spec.consumes_is_defined | ||
and component_spec.consumes_additional_properties | ||
): | ||
if dataset_fields is None: | ||
logger.info( | ||
"The dataset fields are not defined. Cannot infer consumes.", | ||
) | ||
return None | ||
|
||
return {k: v.type.value for k, v in dataset_fields.items()} | ||
|
||
# Component has consumes and no additionalProperties, we will load only the columns defined | ||
# in the component spec | ||
return {k: v.type.value for k, v in component_spec.consumes.items()} | ||
|
||
@classmethod | ||
def from_ref( | ||
cls, | ||
|
@@ -223,31 +257,14 @@ def from_ref( | |
""" | ||
if inspect.isclass(ref) and issubclass(ref, BaseComponent): | ||
if issubclass(ref, LightweightComponent): | ||
name = ref.__name__ | ||
image = ref.image() | ||
description = ref.__doc__ or "lightweight component" | ||
spec_produces = ref.get_spec_produces() | ||
|
||
spec_consumes = ( | ||
ref.get_spec_consumes(fields, kwargs["consumes"]) | ||
if fields | ||
else {"additionalProperties": True} | ||
) | ||
component_spec = ref.get_component_spec() | ||
|
||
component_spec = ComponentSpec( | ||
name, | ||
image.base_image, | ||
description=description, | ||
consumes=spec_consumes, | ||
produces=spec_produces, | ||
args={ | ||
name: arg.to_spec() | ||
for name, arg in infer_arguments(ref).items() | ||
}, | ||
) | ||
# If consumes is not defined in the pipeline, we will try to infer it | ||
if kwargs.get("consumes") is None: | ||
kwargs["consumes"] = cls._infer_consumes(component_spec, fields) | ||
|
||
operation = cls( | ||
image, | ||
ref.image(), | ||
component_spec, | ||
**kwargs, | ||
) | ||
|
@@ -259,6 +276,7 @@ def from_ref( | |
elif isinstance(ref, (str, Path)): | ||
operation = cls.from_component_yaml( | ||
ref, | ||
fields, | ||
**kwargs, | ||
) | ||
else: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be nice to implement on the spec (same for the produces)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean in the
OperationSpec
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a better look and never mind. I was lost in the many specs 😛 .