Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Is it a bug about some code in backtrader/metabase/AutoInfoClass and I have a question about this class

    General Code/Help
    2
    4
    169
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • tianjixuetu
      tianjixuetu last edited by

      def _derive(cls, name, info, otherbases, recurse=False):
              '''推测各个参数的意义:
              cls:代表一个具体的类,很有可能就是AutoInfoClass本身
              info:代表参数(parameter)
              otherBases:其他的bases
              recurse:递归
              '''
              # collect the 3 set of infos
              # info = OrderedDict(info)
              baseinfo = cls._getpairs().copy()   # 浅拷贝,保证一级目录下不改变
              obasesinfo = OrderedDict()          # 代表其他类的info
              for obase in otherbases:
                  ### 如果是tuple,python3的情况下orderedDict似乎不能够直接用update,会报错
                  **if isinstance(obase, (tuple, dict)):**
                      obasesinfo.update(obase)
                  ### 如果定义_getpairs()是为了获取空的有序字典的话,下面似乎没有意义
                  else:
                      obasesinfo.update(obase._getpairs())
      

      you know OrderedDict.update(something),if something is a tuple,it will raise a error in python3.
      so, I think ,the right code may be if isinstance(obase, (list, dict)).

      My question is :

      I can't understand the the three line in this class,but,after a lot of serch and try,I guess:

      _getpairsbase = classmethod(lambda cls: OrderedDict())
      _getpairs = classmethod(lambda cls: OrderedDict())
      _getrecurse = classmethod(lambda cls: False)
      

      It equals:

      @classmethod
          def _getpairsbase(cls)
              return OrderedDict()
              
          @classmethod
          def _getpairs(cls)
              return OrderedDict()
              
          @classmethod
          def _getrecurse(cls)
              return False
      

      Is it right?

      if so,maybe,there are some code appearing redundant, for example:

      if isinstance(obase, (tuple, dict)):
          obasesinfo.update(obase)
              
      else:
          obasesinfo.update(obase._getpairs())
      

      update an empty OrderedDict ,may add nothing.

      thank you very much. Look forward to seeing backtrader becoming better and better!

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @tianjixuetu last edited by

        @tianjixuetu said in Is it a bug about some code in backtrader/metabase/AutoInfoClass and I have a question about this class:

        you know OrderedDict.update(something),if something is a tuple,it will raise a error in python3.

        No, I don't know and it is NOT the case. If you provide an ill-formed tuple, yes it will raise an error. But the problem is the input provided by the user and not the functionality.

        Beyond reading the code and believing there are errors:

        • Do you have anything which is an actual error related to backtesting?
        1 Reply Last reply Reply Quote 0
        • tianjixuetu
          tianjixuetu last edited by

          Ok,you are right. OrderedDict's update method can accept tuple。I am very sorry.

          from collections import OrderedDict
          o=OrderedDict()
          o.update((('name',"yun"),('age',30)))
          print(o)
          

          can you answer my question about the classmethod you used in this class ? obase._getpairs() get a empty OrderedDict,is it right?

          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            Yes, the default implementations do. What is your point?

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors