|
11 | 11 | import pytest |
12 | 12 |
|
13 | 13 | from pandas import (DataFrame, compat, option_context) |
14 | | -from pandas.compat import StringIO, lrange, u |
| 14 | +from pandas.compat import StringIO, lrange, u, PYPY |
15 | 15 | import pandas.io.formats.format as fmt |
16 | 16 | import pandas as pd |
17 | 17 |
|
@@ -332,13 +332,25 @@ def test_info_memory_usage(self): |
332 | 332 | res = buf.getvalue().splitlines() |
333 | 333 | assert re.match(r"memory usage: [^+]+$", res[-1]) |
334 | 334 |
|
335 | | - assert (df_with_object_index.memory_usage( |
336 | | - index=True, deep=True).sum() > df_with_object_index.memory_usage( |
337 | | - index=True).sum()) |
| 335 | + if PYPY: |
| 336 | + assert (df_with_object_index.memory_usage( |
| 337 | + index=True, deep=True).sum() == |
| 338 | + df_with_object_index.memory_usage( |
| 339 | + index=True).sum()) |
338 | 340 |
|
339 | | - df_object = pd.DataFrame({'a': ['a']}) |
340 | | - assert (df_object.memory_usage(deep=True).sum() > |
341 | | - df_object.memory_usage().sum()) |
| 341 | + df_object = pd.DataFrame({'a': ['a']}) |
| 342 | + assert (df_object.memory_usage(deep=True).sum() == |
| 343 | + df_object.memory_usage().sum()) |
| 344 | + |
| 345 | + else: |
| 346 | + assert (df_with_object_index.memory_usage( |
| 347 | + index=True, deep=True).sum() > |
| 348 | + df_with_object_index.memory_usage( |
| 349 | + index=True).sum()) |
| 350 | + |
| 351 | + df_object = pd.DataFrame({'a': ['a']}) |
| 352 | + assert (df_object.memory_usage(deep=True).sum() > |
| 353 | + df_object.memory_usage().sum()) |
342 | 354 |
|
343 | 355 | # Test a DataFrame with duplicate columns |
344 | 356 | dtypes = ['int64', 'int64', 'int64', 'float64'] |
@@ -377,10 +389,12 @@ def test_info_memory_usage(self): |
377 | 389 | df.memory_usage(index=True) |
378 | 390 | df.index.values.nbytes |
379 | 391 |
|
380 | | - # sys.getsizeof will call the .memory_usage with |
381 | | - # deep=True, and add on some GC overhead |
382 | | - diff = df.memory_usage(deep=True).sum() - sys.getsizeof(df) |
383 | | - assert abs(diff) < 100 |
| 392 | + mem = df.memory_usage(deep=True).sum() |
| 393 | + if not PYPY: |
| 394 | + # sys.getsizeof will call the .memory_usage with |
| 395 | + # deep=True, and add on some GC overhead |
| 396 | + diff = mem - sys.getsizeof(df) |
| 397 | + assert abs(diff) < 100 |
384 | 398 |
|
385 | 399 | def test_info_memory_usage_qualified(self): |
386 | 400 |
|
|
0 commit comments