def test_get_column(): t = gt.Table() t.add_column('a', [1, 2, 3, 4, 5]) t.add_column('b', [1, 2, 3]) t.add_column('c', [3, 4, 5], align='bottom') c = t.get('a') assert np.all(c.values == np.array([1, 2, 3, 4, 5]))
def test_gh6(): ta = gt.Table({ 'A': [1, 2, 3, 1, 2, 3, 6], 'B': [0.2, 0.4, 0.4548, 0.34465, 0.4, 0.315456, 0.5454545] }) tb = gt.Table({ 'A': [1, 2, 5, 7, 8, 3], 'C': [564, 4545, 8989, 45, 23, 78] }) merged1 = gt.merge(ta, tb, 'A') print('fffff') tc = gt.Table({ 'A': [1, 7], 'D': [np.datetime64('2017-02-15'), np.datetime64('2017-03-28')] }) merged2 = gt.merge(merged1, tc, 'A') assert merged2.index.sum(axis=1).tolist() == [len(l) for l in merged2.data]
def test_get_table(): t = gt.Table() t.add_column('a', [1, 2, 3, 4, 5]) t.add_column('b', [1, 2, 3]) t.add_column('c', [3, 4, 5], align='bottom') t1 = t.get(['a', 'b']) print(t1.index) assert np.all(t1.a.values == np.array([1, 2, 3, 4, 5])) assert np.all(t1.a.index == np.array([1, 1, 1, 1, 1]))
def test_reduce_sum_1(): t = gt.Table() t.add_column('a', [1, 2, 2, 3, 4, 5]) t.add_column('b', [1, 2, 3]) t.add_column('c', [3, 4, 5], align='bottom') t1 = gtable.reduce_by_key(t, 'a', 'sum') assert np.all(t1.b.values == np.array([1, 5])) assert np.all(t1.b.index == np.array([1, 1, 0, 0, 0])) assert np.all(t1.c.values == np.array([3, 4, 5])) assert np.all(t1.c.index == np.array([0, 0, 1, 1, 1]))
def test_reduce_std(): t = gt.Table() t.add_column('a', ['a', 'b', 'b', 'c', 'c', 'd']) t.add_column('b', [1, 2, 3]) t.add_column('c', [3, 4, 5], align='bottom') t1 = t.reduce_by_key('a').std() assert np.all(t1.a.values == np.array(list('abcd'))) assert np.all(t1.a.index == np.array([1, 1, 1, 1])) assert np.all(t1.b.values == np.array([0, 0.5])) assert np.all(t1.b.index == np.array([1, 1, 0, 0])) assert np.all(t1.c.values == np.array([0.5, 0])) assert np.all(t1.c.index == np.array([0, 0, 1, 1]))
def test_reduce_prod_1(): t = gt.Table() t.add_column('a', ['a', 'b', 'b', 'c', 'c', 'd']) t.add_column('b', [1, 2, 3]) t.add_column('c', [3, 4, 5], align='bottom') t1 = gtable.reduce_by_key(t, 'a', 'prod') assert np.all(t1.a.values == np.array(list('abcd'))) assert np.all(t1.a.index == np.array([1, 1, 1, 1])) assert np.all(t1.b.values == np.array([1, 6])) assert np.all(t1.b.index == np.array([1, 1, 0, 0])) assert np.all(t1.c.values == np.array([12, 5])) assert np.all(t1.c.index == np.array([0, 0, 1, 1]))
def test_required_column_present(): d = {'A': [1, 2, 3, 4], 'B': [2.2, 1.5, 7.3, 2.6]} t = gt.Table(d) with pytest.raises(KeyError): t.required_column('B', np.dtype(('U', 10)))
def setup(self): self.t = gt.Table() self.t.add_column('a', [1, 2, 2, 3, 4, 5]) self.t.add_column('b', [1, 2, 3]) self.t.add_column('c', [3, 4, 5], align='bottom')