Skip to content
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

allow a hash method to be present for numpy arrays #2649

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions flytekit/types/numpy/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
def extract_metadata(t: Type[np.ndarray]) -> Tuple[Type[np.ndarray], Dict[str, bool]]:
metadata = {}
if get_origin(t) is Annotated:
base_type, metadata = get_args(t)
if isinstance(metadata, OrderedDict):
return base_type, metadata
else:
raise TypeTransformerFailedError(f"{t}'s metadata needs to be of type kwtypes.")
base_type, *annotate_args = get_args(t)

for aa in annotate_args:
if isinstance(aa, OrderedDict):
if metadata != "":
raise TypeTransformerFailedError(f"Meta data was already specified {metadata}, cannot use {aa}")
samhita-alla marked this conversation as resolved.
Show resolved Hide resolved
metadata = aa
elif isinstance(aa, HashMethod):
continue
else:
raise TypeTransformerFailedError(f"{t}'s metadata needs to be of type kwtypes.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
raise TypeTransformerFailedError(f"{t}'s metadata needs to be of type kwtypes.")
raise TypeTransformerFailedError(f"The metadata for {t} must be of type kwtypes or HashMethod.")

shouldn't you also import HashMethod from flytekit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot the import in the PR, probably the reason for some (but definitely not all) test fails.

@samhita-alla Quick question here, you added HashMethod in error message, but how does kwtypes relate to the code, where the check looks for an OrderedDict, not kwtypes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, flytekit's kwtypes is an ordered dict. let's replace kwtypes with ordereddict.


return base_type, metadata

# Return the type itself if no metadata was found.
return t, metadata


Expand Down
Loading