Skip to content

Commit

Permalink
Correct detection of missing attributes. (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
shnela committed Dec 12, 2022
1 parent d96459d commit f92ea88
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## neptune-client 0.16.15

### Fixes
- Correct detection of missing attributes ([#1155](https://github.com/neptune-ai/neptune-client/pull/1155))

## neptune-client 0.16.14

### Features
Expand Down
14 changes: 7 additions & 7 deletions src/neptune/new/handler.py
Expand Up @@ -167,7 +167,7 @@ def assign(self, value, wait: bool = False) -> None:
"""
with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
self._container.define(self._path, value)
else:
if isinstance(value, Handler):
Expand Down Expand Up @@ -210,7 +210,7 @@ def upload(self, value, wait: bool = False) -> None:

with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
attr = File(self._container, parse_path(self._path))
self._container.set_attribute(self._path, attr)
attr.upload(value, wait)
Expand All @@ -224,7 +224,7 @@ def upload_files(self, value: Union[str, Iterable[str]], wait: bool = False) ->

with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
attr = FileSet(self._container, parse_path(self._path))
self._container.set_attribute(self._path, attr)
attr.upload_files(value, wait)
Expand Down Expand Up @@ -267,7 +267,7 @@ def log(

with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
if is_collection(value):
if value:
first_value = next(iter(value))
Expand Down Expand Up @@ -387,7 +387,7 @@ def extend(

with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
neptune_value = cast_value_for_extend(values)
attr = ValueToAttributeVisitor(self._container, parse_path(self._path)).visit(neptune_value)
self._container.set_attribute(self._path, attr)
Expand All @@ -414,7 +414,7 @@ def add(self, values: Union[str, Iterable[str]], wait: bool = False) -> None:
verify_type("values", values, (str, Iterable))
with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
attr = StringSet(self._container, parse_path(self._path))
self._container.set_attribute(self._path, attr)
attr.add(values, wait)
Expand Down Expand Up @@ -623,7 +623,7 @@ def track_files(self, path: str, destination: str = None, wait: bool = False) ->
"""
with self._container.lock():
attr = self._container.get_attribute(self._path)
if not attr:
if attr is None:
attr = Artifact(self._container, parse_path(self._path))
self._container.set_attribute(self._path, attr)

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/neptune/new/test_experiment.py
Expand Up @@ -102,6 +102,13 @@ def test_define_conflict(self):
with self.assertRaises(MetadataInconsistency):
exp.define("some/path/value", Float(1))

def test_define_conflict_with_empty_namespace(self):
for exp in self.get_experiments(flush_period=0.5):
with self.subTest(msg=f"For type {exp.container_type}"):
exp.define("some/path/value", {})
with self.assertRaises(MetadataInconsistency):
exp.define("some/path/value", {})

def test_pop(self):
for exp in self.get_experiments(flush_period=0.5):
with self.subTest(msg=f"For type {exp.container_type}"):
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/neptune/new/test_handler.py
Expand Up @@ -491,6 +491,12 @@ def test_assign_dict(self):
self.assertEqual(exp["params/toys"].fetch_last(), "hat")
self.assertEqual(exp["params/nested/nested/deep_secret"].fetch_last(), 15)

def test_assign_empty_dict(self):
with init_run(mode="debug", flush_period=0.5) as exp:
exp["params"] = {}
exp["params"] = {"foo": 5}
self.assertEqual(exp["params/foo"].fetch(), 5)

def test_argparse_namespace(self):
with init_run(mode="debug", flush_period=0.5) as exp:
exp["params"] = argparse.Namespace(
Expand Down

0 comments on commit f92ea88

Please sign in to comment.