Skip to content

Commit adb08bd

Browse files
committed
Check whether to use function default values
1 parent 777c6d0 commit adb08bd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

adaptive/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import inspect
55
import os
66
import pickle
7+
import warnings
78
from contextlib import contextmanager
89
from itertools import product
910

@@ -135,4 +136,19 @@ def partial_function_from_dataframe(function, df, function_prefix: str = "functi
135136
kwargs[k] = v
136137
if not kwargs:
137138
return function
139+
140+
sig = inspect.signature(function)
141+
for k, v in kwargs.items():
142+
if k not in sig.parameters:
143+
raise ValueError(
144+
f"The DataFrame contains a default parameter"
145+
f" ({k}={v}) but the function does not have that parameter."
146+
)
147+
default = sig.parameters[k].default
148+
if default != inspect._empty and kwargs[k] != default:
149+
warnings.warn(
150+
f"The DataFrame contains a default parameter"
151+
f" ({k}={v}) but the function already has a default ({k}={default})."
152+
" The DataFrame's value will be used."
153+
)
138154
return functools.partial(function, **kwargs)

0 commit comments

Comments
 (0)