From 930435bb64bc1555d1aac3b1f6d57b394ec5061c Mon Sep 17 00:00:00 2001 From: Asgeir Nyvoll Date: Fri, 28 Feb 2020 13:16:34 +0100 Subject: [PATCH] Webvizstore default value error example (#205) * Webvizstore default value error example * webvizstore bug fix default values * Added ExamplePortable to basic_example.yaml for testing --- examples/basic_example.yaml | 5 +++++ webviz_config/plugins/_example_portable.py | 16 +++++++++++++--- webviz_config/webviz_store.py | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/basic_example.yaml b/examples/basic_example.yaml index 73d879bb..e1d465d1 100644 --- a/examples/basic_example.yaml +++ b/examples/basic_example.yaml @@ -64,3 +64,8 @@ pages: name: Kari Nordmann phone: 12345678 email: someother@email.com + + - title: Example portable + content: + - ExamplePortable: + some_number: 42 diff --git a/webviz_config/plugins/_example_portable.py b/webviz_config/plugins/_example_portable.py index 69cb56b3..9c576685 100644 --- a/webviz_config/plugins/_example_portable.py +++ b/webviz_config/plugins/_example_portable.py @@ -12,22 +12,32 @@ def __init__(self, some_number: int): super().__init__() self.some_number = some_number + self.some_string = "a" def add_webvizstore(self) -> List[tuple]: - return [(input_data_function, [{"some_number": self.some_number}])] + return [ + ( + input_data_function, + [{"some_string": self.some_string, "some_number": self.some_number}], + ) + ] @property def layout(self) -> str: - return str(input_data_function(self.some_number)) + return str(input_data_function(self.some_string, some_number=self.some_number)) @CACHE.memoize(timeout=CACHE.TIMEOUT) @webvizstore -def input_data_function(some_number: int) -> pd.DataFrame: +def input_data_function( + some_string: str, some_number: int, some_bool: bool = True +) -> pd.DataFrame: print("This time I'm actually doing the calculation...") return pd.DataFrame( data={ "col1": [some_number, some_number * 2], "col2": [some_number * 3, some_number * 4], + "col3": [some_string, some_string + "b"], + "col4": [some_bool, not some_bool], } ) diff --git a/webviz_config/webviz_store.py b/webviz_config/webviz_store.py index b4a13cfd..0dfc2e9b 100644 --- a/webviz_config/webviz_store.py +++ b/webviz_config/webviz_store.py @@ -67,7 +67,7 @@ def register_function_arguments(self, functionarguments: List[tuple]) -> None: undec_func = WebvizStorage._undecorate(func) for args in arglist: argtuples = WebvizStorage._dict_to_tuples( - WebvizStorage.complete_kwargs(func, args) + WebvizStorage.complete_kwargs(undec_func, args) ) if repr(argtuples) not in self.storage_function_argvalues[undec_func]: self.storage_function_argvalues[undec_func][