Skip to content

Commit

Permalink
COMPAT/TST: sparse formatting test for platform, xref #13163
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed May 16, 2016
1 parent 62bed0e commit 4e4a7d9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pandas/sparse/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ class TestSeriesFormatting(tm.TestCase):

_multiprocess_can_split_ = True

@property
def dtype_format_for_platform(self):
return '' if use_32bit_repr else ', dtype=int32'

def test_sparse_max_row(self):
s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse()
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
dfm = self.dtype_format_for_platform
exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n"
"4 NaN\ndtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
"Block lengths: array([1, 1]{0})".format(dfm))
self.assertEqual(result, exp)

with option_context("display.max_rows", 3):
Expand All @@ -33,7 +37,7 @@ def test_sparse_max_row(self):
exp = ("0 1.0\n ... \n4 NaN\n"
"dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dtype))
"Block lengths: array([1, 1]{0})".format(dfm))
self.assertEqual(result, exp)

def test_sparse_mi_max_row(self):
Expand All @@ -42,19 +46,19 @@ def test_sparse_mi_max_row(self):
s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan],
index=idx).to_sparse()
result = repr(s)
dtype = '' if use_32bit_repr else ', dtype=int32'
dfm = self.dtype_format_for_platform
exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n"
"C 0 3.0\n 1 NaN\n 2 NaN\n"
"dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3], dtype=int32)\n"
"Block lengths: array([1, 1]{0})".format(dtype))
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
self.assertEqual(result, exp)

with option_context("display.max_rows", 3):
# GH 13144
result = repr(s)
exp = ("A 0 1.0\n ... \nC 2 NaN\n"
"dtype: float64\nBlockIndex\n"
"Block locations: array([0, 3], dtype=int32)\n"
"Block lengths: array([1, 1]{0})".format(dtype))
"Block locations: array([0, 3]{0})\n"
"Block lengths: array([1, 1]{0})".format(dfm))
self.assertEqual(result, exp)

0 comments on commit 4e4a7d9

Please sign in to comment.