mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-15 11:22:18 +08:00
Merge pull request #1129 from quantopian/empty-lists
BUG: support passing an empty list to `data` methods.
This commit is contained in:
@@ -1905,6 +1905,21 @@ def handle_data(context, data):
|
||||
|
||||
self.assertEqual(expected, cm.exception.args[0])
|
||||
|
||||
def test_empty_asset_list_to_history(self):
|
||||
algo = TradingAlgorithm(
|
||||
script=dedent("""
|
||||
def initialize(context):
|
||||
pass
|
||||
|
||||
def handle_data(context, data):
|
||||
data.history([], "price", 5, '1d')
|
||||
"""),
|
||||
sim_params=self.sim_params,
|
||||
env=self.env
|
||||
)
|
||||
|
||||
algo.run(self.data_portal)
|
||||
|
||||
|
||||
class TestGetDatetime(TestCase):
|
||||
|
||||
|
||||
@@ -62,18 +62,17 @@ cdef class check_parameters(object):
|
||||
" '%s'" % (func.__name__, field))
|
||||
|
||||
# verify type of each arg
|
||||
i = 0
|
||||
while i < (len(args) - 1):
|
||||
arg = args[i + 1]
|
||||
for i, arg in enumerate(args[1:]):
|
||||
expected_type = self.types[i]
|
||||
|
||||
if isinstance(arg, expected_type):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
elif (i == 0 or i == 1) and _is_iterable(arg):
|
||||
if len(arg) == 0:
|
||||
continue
|
||||
|
||||
if isinstance(arg[0], expected_type):
|
||||
i += 1
|
||||
continue
|
||||
|
||||
expected_type_name = expected_type.__name__ \
|
||||
@@ -91,6 +90,9 @@ cdef class check_parameters(object):
|
||||
if isinstance(arg, self.keys_to_types[keyword]):
|
||||
continue
|
||||
elif keyword in ('assets', 'fields') and _is_iterable(arg):
|
||||
if len(arg) == 0:
|
||||
continue
|
||||
|
||||
if isinstance(arg[0], self.keys_to_types[i]):
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user