Skip to content

Commit

Permalink
Delete namespace (and all child fields and namespaces) (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrJander authored Jul 9, 2021
1 parent 2c68569 commit 885ccd4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## neptune-client 0.10.1

### Features
- Delete namespace (and all child fields and namespaces) ([#619](https://github.com/neptune-ai/neptune-client/pull/619))
- .pop() works invoked on a field ([#617](https://github.com/neptune-ai/neptune-client/pull/617))
- Logging version when using python logger integration ([#622](https://github.com/neptune-ai/neptune-client/pull/622))

## neptune-client 0.10.0
Expand Down
14 changes: 13 additions & 1 deletion neptune/new/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,22 @@ def pop(self, path: str, wait: bool = False) -> None:
"""
verify_type("path", path, str)
with self._lock:
parsed_path = parse_path(path)
self._pop_impl(parse_path(path), wait)

def _pop_impl(self, parsed_path: List[str], wait: bool):
attribute = self._structure.get(parsed_path)
if isinstance(attribute, NamespaceAttr):
self._pop_namespace(attribute, wait)
else:
self._op_processor.enqueue_operation(DeleteAttribute(parsed_path), wait)
self._structure.pop(parsed_path)

def _pop_namespace(self, namespace: NamespaceAttr, wait: bool):
children = list(namespace)
for key in children:
sub_attr_path = namespace._path + [key] # pylint: disable=protected-access
self._pop_impl(sub_attr_path, wait)

def lock(self) -> threading.RLock:
return self._lock

Expand Down
8 changes: 8 additions & 0 deletions tests/neptune/new/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_pop(self):
self.assertTrue('num' in exp.get_structure()['some']['path'])
self.assertTrue('text' not in exp.get_structure()['some']['path'])

def test_pop_namespace(self):
exp = init(mode="debug", flush_period=0.5)
exp.define("some/path/subpath/num", Float(3))
exp.define("some/path/text", String("Some text"))
exp.define("some/otherpath", Float(4))
exp.pop("some/path")
self.assertTrue('path' not in exp.get_structure()['some'])

def test_run_as_handler(self):
exp = init(mode="debug", flush_period=0.5)
exp.define("some/path/num", Float(3))
Expand Down

0 comments on commit 885ccd4

Please sign in to comment.