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/

    PyCharm gives a warning on PandasData instance creation

    General Code/Help
    pycharm pandasdata pandas
    2
    3
    531
    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.
    • Queeq
      Queeq last edited by Queeq

      Hi,

      This is not really a problem, but a question for education purposes.

      When I try to import data from a DataFrame, PyCharm, apparently, gets confused by absence of arguments of PandasData.__init__(), showing a warning about unexpected data;

      0_1548321457772_c9cb098d-299a-48ca-88a3-9a5655cf104e-image.png

      I found a way to silence it by the following hack (I also need custom column names):

      class PData(bt.feeds.PandasData):
          params = (
              ("open", "o"),
              ("high", "h"),
              ("low", "l"),
              ("close", "c"),
              ("volume", "vol"),
              ("openinterest", None),
          )
      
          def __init__(self, dataname):
              """ This whole function is a dirty hack to silence unexpected
              argument (`dataname`) warning on class instance creation
              Args:
                  dataname (pd.DataFrame): OHLC DataFrame
              """
              self.p.dataname = dataname
              super().__init__()
      

      It's quite annoying. Is there a cleaner way to get rid of it?
      Also, could someone give me a hint on why is it designed this way and how inheritance here actually works? Some link to read more about advantages of this would be nice.

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

        @queeq said in PyCharm gives a warning on PandasData instance creation:

        It's quite annoying. Is there a cleaner way to get rid of it?

        Most of the shells hijacking the Python kernel and getting in the way are actually annoying (Jupyter, Spyder, PyCharm, feel free to name your favourite winner of the hijacker of the day)

        There is for sure a code for PyCharm which you can put in a comment line which disables warnings, same as with PyFlakes, for example.

        @queeq said in PyCharm gives a warning on PandasData instance creation:

        could someone give me a hint on why is it designed this way and how inheritance here actually works?

        Read Docs - Platform Concepts, the section named Parameters

        1 Reply Last reply Reply Quote 0
        • Queeq
          Queeq last edited by

          Thanks. Found how to suppress it indeed. Reference for future generations: https://www.jetbrains.com/help/pycharm/suppressing-inspections.html

          In this case it'll look like this:

          # noinspection PyArgumentList
          data = PData(dataname=df)
          
          1 Reply Last reply Reply Quote 2
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors