Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions backtrader/lineiterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
import operator
import sys

try:
collectionsAbc = collections.abc
except AttributeError:
collectionsAbc = collections

from .utils.py3 import map, range, zip, with_metaclass, string_types
from .utils import DotDict

Expand Down Expand Up @@ -226,15 +231,15 @@ def bindlines(self, owner=None, own=None):

if isinstance(owner, string_types):
owner = [owner]
elif not isinstance(owner, collections.Iterable):
elif not isinstance(owner, collectionsAbc.Iterable):
owner = [owner]

if not own:
own = range(len(owner))

if isinstance(own, string_types):
own = [own]
elif not isinstance(own, collections.Iterable):
elif not isinstance(own, collectionsAbc.Iterable):
own = [own]

for lineowner, lineown in zip(owner, own):
Expand Down
52 changes: 52 additions & 0 deletions tests/test_lineiterator_bindlines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python
# -*- coding: utf-8; py-indent-offset:4 -*-
###############################################################################
#
# Copyright (C) 2015-2023 Daniel Rodriguez
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import datetime

import testcommon

import backtrader as bt


class BindLinesStrategy(bt.Strategy):
params = dict(main=False)

def __init__(self):
self.sma = bt.ind.SMA(self.data, period=5)
self.sma.bindlines()


def test_bindlines_python_310_collections_abc(main=False):
data = testcommon.getdata(0,
fromdate=datetime.datetime(2006, 1, 1),
todate=datetime.datetime(2006, 1, 31))

testcommon.runtest([data],
BindLinesStrategy,
runonce=False,
preload=False,
exbar=False,
main=main)


if __name__ == '__main__':
test_bindlines_python_310_collections_abc(main=True)