Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asizeof does not properly size namedtuples #35

Closed
Paul-E opened this issue Apr 25, 2016 · 2 comments
Closed

asizeof does not properly size namedtuples #35

Paul-E opened this issue Apr 25, 2016 · 2 comments

Comments

@Paul-E
Copy link

Paul-E commented Apr 25, 2016

If I run asizeof on a normal tuple, I get the following:

>>> from pympler import asizeof
>>> asizeof.asizeof(list(range(1000)), "foo")
41160

If I create a named tuple and run asizeof on that object, I don't get the correct size:

>>> from pympler import asizeof
>>> from collections import namedtuple
>>> TestTuple = namedtuple("TestTuple", ["a", "b"])
>>> asizeof.asizeof(TestTuple(list(range(1000)), "foo"))
120

I believe asizeof should be returning roughly the same values for these calls.

This output was produced on Python 3.4 using pympler 0.4.3. Perhaps this is related to #10?

chrisklaiber pushed a commit to chrisklaiber/pympler that referenced this issue Jun 24, 2016
This change includes values when sizing a namedtuple. Before this values were
ignored:

  >>> from pympler import asizeof
  >>> import collections
  >>> Point = collections.namedtuple('Point', ('x', 'y'))
  >>>
  >>> print(asizeof.asized(Point(x=11, y=22), detail=1).format())
  Point(x=11, y=22) size=136 flat=72
      __slots__ size=64 flat=64
      __class__ size=0 flat=0

Now values appear like a tuple's do:

  >>> print(asizeof.asized(Point(x=11, y=22), detail=1).format())
  Point(x=11, y=22) size=184 flat=72
      __slots__ size=64 flat=64
      11 size=24 flat=24
      22 size=24 flat=24
      __class__ size=0 flat=0
  >>> print(asizeof.asized((11, 22), detail=1).format())
  (11, 22) size=120 flat=72
      11 size=24 flat=24
      22 size=24 flat=24

Fixes pympler#35

The modified namedtuple test also passes:

  $ python test/runtest.py --verbose=3 test/asizeof
@kwlzn
Copy link

kwlzn commented Aug 22, 2016

+1

@Pankrat
Copy link
Member

Pankrat commented Sep 4, 2016

Thanks for the report and the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants