-
Notifications
You must be signed in to change notification settings - Fork 58
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically convert image and html like assignments to uploads #1006
Changes from 5 commits
1dbfe03
86aa720
235922c
073b25c
a81f450
a11c8f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# | ||
# Copyright (c) 2022, Neptune Labs Sp. z o.o. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
import argparse | ||
from datetime import datetime | ||
from typing import Any | ||
|
||
from neptune.common.deprecation import warn_once | ||
from neptune.new.handler import Handler | ||
from neptune.new.internal.utils import ( | ||
is_bool, | ||
is_dict_like, | ||
is_float, | ||
is_float_like, | ||
is_int, | ||
is_string, | ||
is_string_like, | ||
) | ||
from neptune.new.types import ( | ||
Boolean, | ||
File, | ||
Integer, | ||
) | ||
from neptune.new.types.atoms.datetime import Datetime | ||
from neptune.new.types.atoms.float import Float | ||
from neptune.new.types.atoms.string import String | ||
from neptune.new.types.namespace import Namespace | ||
from neptune.new.types.value import Value | ||
from neptune.new.types.value_copy import ValueCopy | ||
|
||
|
||
def cast_value(value: Any) -> Value: | ||
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. As we extracted this func (which is so cool!) what do you think about using a single-dispatch? https://docs.python.org/3.7/library/functools.html#functools.singledispatch You should be able to split this function into multiple one that will be triggered base on arguments type. 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. I think it's a good idea. 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. Or maybe not. |
||
if isinstance(value, Value): | ||
return value | ||
elif isinstance(value, Handler): | ||
return ValueCopy(value) | ||
elif isinstance(value, argparse.Namespace): | ||
return Namespace(vars(value)) | ||
elif File.is_convertable_to_image(value): | ||
return File.as_image(value) | ||
elif File.is_convertable_to_html(value): | ||
return File.as_html(value) | ||
elif is_bool(value): | ||
return Boolean(value) | ||
elif is_int(value): | ||
return Integer(value) | ||
elif is_float(value): | ||
return Float(value) | ||
elif is_string(value): | ||
return String(value) | ||
elif isinstance(value, datetime): | ||
return Datetime(value) | ||
elif is_float_like(value): | ||
return Float(float(value)) | ||
elif is_dict_like(value): | ||
return Namespace(value) | ||
elif is_string_like(value): | ||
warn_once( | ||
message="The object you're logging will be implicitly cast to a string." | ||
" We'll end support of this behavior in `neptune-client==1.0.0`." | ||
" To log the object as a string, use `str(object)` instead.", | ||
stack_level=3, | ||
) | ||
return String(str(value)) | ||
else: | ||
raise TypeError("Value of unsupported type {}".format(type(value))) |
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.
CHANGELOG?