diff --git a/adaptive/learner/learner1D.py b/adaptive/learner/learner1D.py index dc7f8d93e3de33dd53f7aef1510c020a3a1d7995..a08a09b5621a5a13d4fab2e899b1e39b7798c63f 100644 --- a/adaptive/learner/learner1D.py +++ b/adaptive/learner/learner1D.py @@ -219,6 +219,10 @@ class Learner1D(BaseLearner): real = y is not None if real: + # either it is a float/int, if not, try casting to a np.array + if not isinstance(y, (float, int)): + y = np.asarray(y, dtype=float) + # Add point to the real data dict self.data[x] = y # remove from set of pending points diff --git a/adaptive/tests/test_learner.py b/adaptive/tests/test_learner.py index 4867952e61a4499afb0efbc0fb0fd5bcd4a2aeec..d3352e123e7dc334b2370cc0f602f1895ae90910 100644 --- a/adaptive/tests/test_learner.py +++ b/adaptive/tests/test_learner.py @@ -188,6 +188,19 @@ def test_uniform_sampling2D(learner_type, f, learner_kwargs): assert max(distances) < math.sqrt(dx**2 + dy**2) +@pytest.mark.parametrize('learner_type, bounds', [ + (Learner1D, (-1, 1)), + (Learner2D, [(-1, 1), (-1, 1)]), + (LearnerND, [(-1, 1), (-1, 1), (-1, 1)]), +]) +def test_learner_accepts_lists(learner_type, bounds): + def f(x): + return [0, 1] + + learner = learner_type(f, bounds=bounds) + simple(learner, goal=lambda l: l.npoints > 10) + + @run_with(xfail(Learner1D), Learner2D, LearnerND) def test_adding_existing_data_is_idempotent(learner_type, f, learner_kwargs): """Adding already existing data is an idempotent operation.