old_contents: from __future__ import print_function, division, absolute_import
  
  import sys
  
  import pytest
  
  from distributed.sizeof import sizeof, getsizeof
  
  
  def test_base():
      assert sizeof(1) == getsizeof(1)
  
  
  def test_containers():
      assert sizeof([1, 2, [3]]) > (getsizeof(3) * 3 + getsizeof([]))
  
  
  def test_numpy():
      np = pytest.importorskip('numpy')
      assert sizeof(np.empty(1000, dtype='f8')) == 8000
      dt = np.dtype('f8')
      assert sizeof(dt) == sys.getsizeof(dt)
  
  
  def test_pandas():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': [1, 2, 3], 'y': ['a'*100, 'b'*100, 'c'*100]},
                        index=[10, 20, 30])
  
      assert sizeof(df) >= sizeof(df.x) + sizeof(df.y) - sizeof(df.index)
      assert sizeof(df.x) >= sizeof(df.index)
      if pd.__version__ >= '0.17.1':
          assert sizeof(df.y) >= 100 * 3
      assert sizeof(df.index) >= 20
  
      assert isinstance(sizeof(df), int)
      assert isinstance(sizeof(df.x), int)
      assert isinstance(sizeof(df.index), int)
  
  
  def test_sparse_matrix():
      sparse = pytest.importorskip('scipy.sparse')
      sp = sparse.eye(10)
      assert sizeof(sp.todia()) >= 152
      assert sizeof(sp.tobsr()) >= 232
      assert sizeof(sp.tocoo()) >= 252
      assert sizeof(sp.tocsc()) >= 232
      assert sizeof(sp.tocsr()) >= 260
      assert sizeof(sp.todok()) >= 260
      assert sizeof(sp.tolil()) >= 324
  
  
  def test_serires_object_dtype():
      pd = pytest.importorskip('pandas')
      s = pd.Series(['a'] * 1000)
      assert sizeof('a') * 1000 < sizeof(s) < 2 * sizeof('a') * 1000
  
      s = pd.Series(['a' * 1000] * 1000)
      assert sizeof(s) > 1000000
  
  
  def test_dataframe_object_dtype():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': ['a'] * 1000})
      assert sizeof('a') * 1000 < sizeof(df) < 2 * sizeof('a') * 1000
  
      s = pd.Series(['a' * 1000] * 1000)
      assert sizeof(s) > 1000000
  
  
  def test_empty():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': [1, 2, 3], 'y': ['a'*100, 'b'*100, 'c'*100]},
                        index=[10, 20, 30])
      empty = df.head(0)
  
      assert sizeof(empty) > 0
      assert sizeof(empty.x) > 0
      assert sizeof(empty.y) > 0
      assert sizeof(empty.index) > 0
  
new_contents: from __future__ import print_function, division, absolute_import
  
  import sys
  
  import pytest
  
  from distributed.sizeof import sizeof, getsizeof
  
  
  def test_base():
      assert sizeof(1) == getsizeof(1)
  
  
  def test_containers():
      assert sizeof([1, 2, [3]]) > (getsizeof(3) * 3 + getsizeof([]))
  
  
  def test_numpy():
      np = pytest.importorskip('numpy')
      assert sizeof(np.empty(1000, dtype='f8')) == 8000
      dt = np.dtype('f8')
      assert sizeof(dt) == sys.getsizeof(dt)
  
  
  def test_pandas():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': [1, 2, 3], 'y': ['a'*100, 'b'*100, 'c'*100]},
                        index=[10, 20, 30])
  
      assert sizeof(df) >= sizeof(df.x) + sizeof(df.y) - sizeof(df.index)
      assert sizeof(df.x) >= sizeof(df.index)
      if pd.__version__ >= '0.17.1':
          assert sizeof(df.y) >= 100 * 3
      assert sizeof(df.index) >= 20
  
      assert isinstance(sizeof(df), int)
      assert isinstance(sizeof(df.x), int)
      assert isinstance(sizeof(df.index), int)
  
  
  def test_sparse_matrix():
      sparse = pytest.importorskip('scipy.sparse')
      sp = sparse.eye(10)
      assert sizeof(sp.todia()) >= 152  # these are the 32 bit values
      assert sizeof(sp.tobsr()) >= 232
      assert sizeof(sp.tocoo()) >= 248
      assert sizeof(sp.tocsc()) >= 232
      assert sizeof(sp.tocsr()) >= 238
      assert sizeof(sp.todok()) >= 192
      assert sizeof(sp.tolil()) >= 210
  
  
  def test_serires_object_dtype():
      pd = pytest.importorskip('pandas')
      s = pd.Series(['a'] * 1000)
      assert sizeof('a') * 1000 < sizeof(s) < 2 * sizeof('a') * 1000
  
      s = pd.Series(['a' * 1000] * 1000)
      assert sizeof(s) > 1000000
  
  
  def test_dataframe_object_dtype():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': ['a'] * 1000})
      assert sizeof('a') * 1000 < sizeof(df) < 2 * sizeof('a') * 1000
  
      s = pd.Series(['a' * 1000] * 1000)
      assert sizeof(s) > 1000000
  
  
  def test_empty():
      pd = pytest.importorskip('pandas')
      df = pd.DataFrame({'x': [1, 2, 3], 'y': ['a'*100, 'b'*100, 'c'*100]},
                        index=[10, 20, 30])
      empty = df.head(0)
  
      assert sizeof(empty) > 0
      assert sizeof(empty.x) > 0
      assert sizeof(empty.y) > 0
      assert sizeof(empty.index) > 0
  
subject: Make sizeof test robust to 32bit values (#948)