def test_grouped_item_access(T1):
 for masked in (False, True):
  t1 = Table(T1, masked=masked)
  tg = t1.group_by('a')
  tgs = tg[('a', 'c', 'd')]
  assert np.all((tgs.groups.keys == tg.groups.keys))
  assert np.all((tgs.groups.indices == tg.groups.indices))
  tgsa = tgs.groups.aggregate(np.sum)
  assert (tgsa.pformat() == [' a   c    d ', '--- ---- ---', '  0  0.0   4', '  1  6.0  18', '  2 22.0   6'])
  tgs = tg[('c', 'd')]
  assert np.all((tgs.groups.keys == tg.groups.keys))
  assert np.all((tgs.groups.indices == tg.groups.indices))
  tgsa = tgs.groups.aggregate(np.sum)
  assert (tgsa.pformat() == [' c    d ', '---- ---', ' 0.0   4', ' 6.0  18', '22.0   6'])

def test_grouped_item_access ( T1 ) : for masked in ( False , True ) : t1 = Table ( T1 , masked = masked ) tg = t1 . group_by ( 'a' ) tgs = tg [ ( 'a' , 'c' , 'd' ) ] assert np . all ( ( tgs . groups . keys == tg . groups . keys ) ) assert np . all ( ( tgs . groups . indices == tg . groups . indices ) ) tgsa = tgs . groups . aggregate ( np . sum ) assert ( tgsa . pformat ( ) == [ ' a   c    d ' , '--- ---- ---' , '  0  0.0   4' , '  1  6.0  18' , '  2 22.0   6' ] ) tgs = tg [ ( 'c' , 'd' ) ] assert np . all ( ( tgs . groups . keys == tg . groups . keys ) ) assert np . all ( ( tgs . groups . indices == tg . groups . indices ) ) tgsa = tgs . groups . aggregate ( np . sum ) assert ( tgsa . pformat ( ) == [ ' c    d ' , '---- ---' , ' 0.0   4' , ' 6.0  18' , '22.0   6' ] )
test that column slicing preserves grouping .