Skip to content

Commit b294f52

Browse files
author
goblincomet
committed
BUG: Better handle indicators that (erroneously) return None
1 parent 74c16ea commit b294f52

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

backtesting/backtesting.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def init():
134134
if isinstance(value, pd.DataFrame):
135135
value = value.values.T
136136

137-
value = try_(lambda: np.asarray(value, order='C'), None)
137+
if value is not None:
138+
value = try_(lambda: np.asarray(value, order='C'), None)
138139
is_arraylike = value is not None
139140

140141
# Optionally flip the array if the user returned e.g. `df.values`
@@ -144,7 +145,7 @@ def init():
144145
if not is_arraylike or not 1 <= value.ndim <= 2 or value.shape[-1] != len(self._data.Close):
145146
raise ValueError(
146147
'Indicators must return (optionally a tuple of) numpy.arrays of same '
147-
'length as `data`(data shape: {}; indicator "{}" shape: {}, value: {})'
148+
'length as `data` (data shape: {}; indicator "{}" shape: {}, returned value: {})'
148149
.format(self._data.Close.shape, name, getattr(value, 'shape', ''), value))
149150

150151
if plot and overlay is None and np.issubdtype(value.dtype, np.number):

0 commit comments

Comments
 (0)