8

In python2.7, following the pympler example:

from anotherfile import somefunction, somecustomclass
from os import path, listdir
import pandas as pd
import gc
from pympler import tracker, muppy, summary

all_objects = muppy.get_objects()
print 'all objects: ', len(all_objects)
sum1 = summary.summarize(all_objects)
summary.print_(sum1)

This is the first code after the imports. It results in

/usr/bin/python2.7 /myprog.py
all objects:  98755
Traceback (most recent call last):
File "/myprog.py", line 12, in <module>
sum1 = summary.summarize(all_objects)
File "/usr/local/lib/python2.7/dist-packages/pympler/summary.py", line 131, in summarize
total_size[otype] = _getsizeof(o)
File "/usr/local/lib/python2.7/dist-packages/pandas/core/base.py", line 130, in __sizeof__
return super(self, PandasObject).__sizeof__()
TypeError: super() argument 1 must be type, not FrozenList

Process finished with exit code 1

I get the same error when I try to initialize a SummaryTracker object.

It looks like a bug in Pympler, but the fact that I can't find any mentions of it contradicts this. According to the official documentation, "Pympler is written entirely in Python, with no dependencies to external libraries. It has been tested with Python 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4 on Linux, Windows and MacOS X." In fact, running only the following code with python 2.7 in a new python file does not produce any errors and works as expected:

from pympler import muppy, tracker

tr = tracker.SummaryTracker()
tr.print_diff()

So what am I missing?

Darina
  • 1,488
  • 8
  • 17

3 Answers3

2

it seems to be a problem in pandas library. I solved it by editing the library code. The track of the error indicates you which line is wrong:

File "/usr/local/lib/python2.7/dist-packages/pandas/core/base.py", line 130, in __sizeof__ 
return super(self, PandasObject).__sizeof__()

You just have to change the order of the parameters like this:

return super(PandasObject, self).__sizeof__()

I did it and I was able to run normally my program.

1

This is Pandas issue #12924. PandasObject.__sizeof__ had the arguments in the wrong order for the super call. The fix has been pulled, and it should be available in the next release. In the meantime, you could edit pandas/core/base.py to switch the argument order, or you could test for the bug's presence and monkey-patch the method with a corrected version.

user2357112
  • 260,549
  • 28
  • 431
  • 505
0

Probably the code is supposed to work with Python3, only. In this question, there's the same error for python2 and if you look at the accepted response it says:

super() (without arguments) was introduced in python3:

super() -> same as super(class, )

so that would be the python2 equivalent for new-style classes:

super(CurrentClass, self)

You'll probably have to use python3 if you don't want to alter the library code.

Community
  • 1
  • 1
DomTomCat
  • 8,189
  • 1
  • 49
  • 64
  • Thanks, I should have mentioned that I've already considered that (will add to the original question), Pympler documentation states that "Pympler is written entirely in Python, with no dependencies to external libraries. It has been tested with Python 2.5, 2.6, 2.7, 3.1, 3.2, 3.3, 3.4 on Linux, Windows and MacOS X." – Darina Jun 03 '16 at 12:06