0

Just subclassed pandas.DataFrame and wrapped loc as such:

import pandas.DataFrame

class XXX(pandas.DataFrame):

    def __init__(self):
        super(Override, self).__init__(columns=['operation'])

    def add_row(self, index, value):
        self.loc[index] = value

And here's what I get when adding a row:

============================= ERRORS =============================
Traceback (most recent call last):
  File "/home/samuel/git/xxx/tests/test_xxx.py", line 21, in setUp
    self.override.add_override(ticker, override)
  File "/home/samuel/git/xxx/xxx.py", line 198, in add_override
    self.loc[ticker] = override
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/indexing.py", line 190, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/indexing.py", line 451, in _setitem_with_indexer
    self.obj._data = self.obj.append(value)._data
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/frame.py", line 6692, in append
    sort=sort)
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/reshape/concat.py", line 229, in concat
    return op.get_result()
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/reshape/concat.py", line 431, in get_result
    return (cons._from_axes(new_data, self.new_axes)
  File "/home/samuel/.local/lib/python2.7/site-packages/pandas/core/generic.py", line 341, in _from_axes
    return cls(data, **kwargs)
TypeError: __init__() takes exactly 1 argument (2 given)
Samuel
  • 2,106
  • 1
  • 17
  • 27
  • Are you sure it's `add_row` but not `__init__`? – Quang Hoang Jul 05 '19 at 14:01
  • @QuangHoang I can instanciate my class, no problem. But calling `add_row` gives the error. – Samuel Jul 05 '19 at 14:02
  • @cs95 I see no reference to this particular issue in the answer you propose – Samuel Jul 05 '19 at 14:35
  • You have not subclassed the frame correctly. Take a look at the answers in the link (which are based on the docs) and see if your code works with the updated implementation. If not, you can edit your question with your updated error and I will reopen it. – cs95 Jul 05 '19 at 14:36

0 Answers0