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

Proper input value type verification for append method #1254

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
- Change run status to Active / Inactive ([#1233](https://github.com/neptune-ai/neptune-client/pull/1233))
- Package renamed from `neptune-client` to `neptune` ([#1225](https://github.com/neptune-ai/neptune-client/pull/1225))

### Fixes
- Fixed input value type verification for `append()` method ([#1254](https://github.com/neptune-ai/neptune-client/pull/1254))

## neptune-client 0.16.18

### Fixes
Expand Down
7 changes: 1 addition & 6 deletions src/neptune/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,7 @@ def validate_and_transform_to_extend_format(value):
so work can be delegated to `extend` method."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change validate_and_transform_to_extend_format to transform_to_extend_format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if isinstance(value, Namespace) or is_dict_like(value):
return {k: ExtendUtils.validate_and_transform_to_extend_format(v) for k, v in value.items()}
elif is_collection(value):
raise NeptuneUserApiInputException(
"Value cannot be a collection, if you want to `append` multiple values at once use `extend` method."
)
else:
return [value]
return [value]

@staticmethod
def validate_values_for_extend(values, steps, timestamps):
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/neptune/new/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from neptune.exceptions import (
FileNotFound,
NeptuneUserApiInputException,
UnsupportedType,
)
from neptune.types import File as FileVal
from neptune.types.atoms.artifact import Artifact
Expand Down Expand Up @@ -270,15 +271,15 @@ def test_log_many_values(self):

def test_append_many_values_cause_error(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

It sould not be called test_append_many_values_cause_error, now error is caused by non-supported value.
We could test some set, tuple and instance of custom class here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

with init_run(mode="debug", flush_period=0.5) as exp:
with self.assertRaises(NeptuneUserApiInputException):
with self.assertRaises(UnsupportedType):
exp["some/num/val"].append([])
with self.assertRaises(NeptuneUserApiInputException):
with self.assertRaises(UnsupportedType):
exp["some/num/val"].append([5, 10, 15])
with self.assertRaises(NeptuneUserApiInputException):
with self.assertRaises(UnsupportedType):
exp["some/str/val"].append(["some text", "other"])
with self.assertRaises(NeptuneUserApiInputException):
with self.assertRaises(UnsupportedType):
exp["some/num/val"].append({"key-a": [1, 2]})
with self.assertRaises(NeptuneUserApiInputException):
with self.assertRaises(UnsupportedType):
exp["some/img/val"].append(
[
FileVal.as_image(PIL.Image.new("RGB", (60, 30), color="red")),
Expand Down