def testRepr(self): # test tensor repr with np.printoptions(threshold=100): arr = np.random.randint(1000, size=(11, 4, 13)) t = mt.tensor(arr, chunk_size=3) result = repr(t.execute()) expected = repr(arr) self.assertEqual(result, expected) for size in (5, 58, 60, 62, 64): pdf = pd.DataFrame(np.random.randint(1000, size=(size, 10))) # test DataFrame repr df = md.DataFrame(pdf, chunk_size=size // 2) result = repr(df.execute()) expected = repr(pdf) self.assertEqual(result, expected, f'failed repr for DataFrame when size = {size}') # test DataFrame _repr_html_ result = df.execute()._repr_html_() expected = pdf._repr_html_() self.assertEqual( result, expected, f'failed repr html for DataFrame when size = {size}') # test Series repr ps = pdf[0] s = md.Series(ps, chunk_size=size // 2) result = repr(s.execute()) expected = repr(ps) self.assertEqual(result, expected, f'failed repr for Series when size = {size}') # test Index repr pind = pd.date_range('2020-1-1', periods=10) ind = md.Index(pind, chunk_size=5) self.assertIn('DatetimeIndex', repr(ind.execute())) # test groupby repr df = md.DataFrame( pd.DataFrame(np.random.rand(100, 3), columns=list('abc'))) grouped = df.groupby(['a', 'b']).execute() self.assertIn('DataFrameGroupBy', repr(grouped)) # test Categorical repr c = md.qcut(range(5), 3) self.assertIn('Categorical', repr(c)) self.assertIn('Categorical', str(c)) self.assertEqual(repr(c.execute()), repr(pd.qcut(range(5), 3)))
def test_repr(setup): # test tensor repr with np.printoptions(threshold=100): arr = np.random.randint(1000, size=(11, 4, 13)) t = mt.tensor(arr, chunk_size=3) result = repr(t.execute()) expected = repr(arr) assert result == expected for size in (5, 58, 60, 62, 64): pdf = pd.DataFrame(np.random.randint(1000, size=(size, 10))) # test DataFrame repr df = md.DataFrame(pdf, chunk_size=size // 2) result = repr(df.execute()) expected = repr(pdf) assert result == expected # test DataFrame _repr_html_ result = df.execute()._repr_html_() expected = pdf._repr_html_() assert result == expected # test Series repr ps = pdf[0] s = md.Series(ps, chunk_size=size // 2) result = repr(s.execute()) expected = repr(ps) assert result == expected # test Index repr pind = pd.date_range('2020-1-1', periods=10) ind = md.Index(pind, chunk_size=5) assert 'DatetimeIndex' in repr(ind.execute()) # test groupby repr df = md.DataFrame(pd.DataFrame(np.random.rand(100, 3), columns=list('abc'))) grouped = df.groupby(['a', 'b']).execute() assert 'DataFrameGroupBy' in repr(grouped) # test Categorical repr c = md.qcut(range(5), 3) assert 'Categorical' in repr(c) assert 'Categorical' in str(c) assert repr(c.execute()) == repr(pd.qcut(range(5), 3))