From 885ccd4b2c581b64856e465d720460ab12d438ba Mon Sep 17 00:00:00 2001 From: Piotr Jander Date: Fri, 9 Jul 2021 12:20:54 +0200 Subject: [PATCH] Delete namespace (and all child fields and namespaces) (#619) --- CHANGELOG.md | 2 ++ neptune/new/run.py | 14 +++++++++++++- tests/neptune/new/test_run.py | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1f8ee622..8cbafe19f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/neptune/new/run.py b/neptune/new/run.py index 1383842d3..7d2822881 100644 --- a/neptune/new/run.py +++ b/neptune/new/run.py @@ -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 diff --git a/tests/neptune/new/test_run.py b/tests/neptune/new/test_run.py index b046b45a5..715a7cf22 100644 --- a/tests/neptune/new/test_run.py +++ b/tests/neptune/new/test_run.py @@ -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))