|
5 | 5 | import hashlib
|
6 | 6 | import inspect
|
7 | 7 | import pathlib
|
| 8 | +import warnings |
8 | 9 | from collections import defaultdict
|
9 | 10 | from typing import Callable, List, Union, Any
|
10 | 11 |
|
@@ -72,6 +73,24 @@ def register_function_arguments(self, functionarguments: List[tuple]) -> None:
|
72 | 73 | repr(argtuples)
|
73 | 74 | ] = argtuples
|
74 | 75 |
|
| 76 | + for (argname, argvalue) in argtuples: |
| 77 | + # Check that values of decorated functions are not pandas objects. |
| 78 | + # This function could probably at some point be moved into a pytest |
| 79 | + # fixture (given that plugins use type hints) in order to slightly |
| 80 | + # reduce running time. |
| 81 | + if isinstance(argvalue, (pd.DataFrame, pd.Series)): |
| 82 | + warnings.warn( |
| 83 | + f"{func.__module__}.{func.__name__} is a @webvizstore decorated " |
| 84 | + f"function, and argument {argname} has been given a pandas " |
| 85 | + "object as value. Since pandas.DataFrames and pandas.Series are " |
| 86 | + "known to not have unique/deterministic __repr__ functions, " |
| 87 | + "they do not work well with @webvizstore (or flask-caching). " |
| 88 | + "Consider moving to another object with a deterministic " |
| 89 | + "__repr__ representation more suitable for hashing.", |
| 90 | + RuntimeWarning, |
| 91 | + stacklevel=0, |
| 92 | + ) |
| 93 | + |
75 | 94 | def _unique_path(self, func: Callable, argtuples: tuple) -> str:
|
76 | 95 | """Encodes the argumenttuples as bytes, and then does a sha256 on that.
|
77 | 96 | Mutable arguments are accepted in the argument tuples, however it is
|
|
0 commit comments