Skip to content

Commit b4bb48f

Browse files
committed
cast to list and make a copy of list that is modified inplace
1 parent 135b21e commit b4bb48f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

adaptive/learner/average_learner1D.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def tell_many_at_point(self, x, ys):
359359
----------
360360
x : float
361361
Value from the function domain.
362-
ys : Sequence[float]
362+
ys : List[float]
363363
List of data samples at ``x``.
364364
"""
365365
# Check x is within the bounds
@@ -369,16 +369,18 @@ def tell_many_at_point(self, x, ys):
369369
"remove x or enlarge the bounds of the learner"
370370
)
371371

372+
ys = list(ys) # cast to list *and* make a copy
372373
y_avg = np.mean(ys)
373374
# If x is a new point:
374375
if x not in self.data:
375376
y = ys.pop(0)
376377
self._update_data(x, y, "new")
377378
self._update_data_structures(x, y, "new")
379+
378380
# If x is not a new point or if there were more than 1 sample in ys:
379-
if len(ys):
381+
if len(ys) > 0:
380382
self.data[x] = y_avg
381-
self._data_samples.update({x: ys + self._data_samples[x]})
383+
self._data_samples[x].extend(ys)
382384
n = len(self._data_samples[x])
383385
self._number_samples[x] = n
384386
# `self._update_data(x, y, "new")` included the point

0 commit comments

Comments
 (0)