From f618e741b1f59494020f76d2484081ae4b7f3abe Mon Sep 17 00:00:00 2001 From: Simon Brugman Date: Tue, 28 Jun 2022 16:14:24 +0200 Subject: [PATCH] feat: string representation for base classes --- popmon/base/module.py | 8 ++++++++ popmon/base/pipeline.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/popmon/base/module.py b/popmon/base/module.py index d46fa5e4..0f524a93 100644 --- a/popmon/base/module.py +++ b/popmon/base/module.py @@ -182,3 +182,11 @@ def transform(self, *args): :rtype: dict """ raise NotImplementedError + + def __repr__(self): + """String representation for modules when printing a pipeline/list of modules""" + name = self.__class__.__name__ + input_keys = [f"{v}='{getattr(self, v)}'" for v in self._input_keys] + output_keys = [f"{v}='{getattr(self, v)}'" for v in self._output_keys] + params = ", ".join(input_keys + output_keys) + return f"{name}({params})" diff --git a/popmon/base/pipeline.py b/popmon/base/pipeline.py index 20c009e4..292f3ea8 100644 --- a/popmon/base/pipeline.py +++ b/popmon/base/pipeline.py @@ -68,3 +68,12 @@ def transform(self, datastore): self.logger.debug(f"transform {module.__class__.__name__}") datastore = module.transform(datastore) return datastore + + def __repr__(self): + """String representation for pipeline""" + name = self.__class__.__name__ + ret = f"{name}: [\n" + for m in self.modules: + ret += "\t" + str(m).replace("\n", "\n\t") + "\n" + ret += "]" + return ret