def test_single_dimension(self): d = DataAssembly([[1, 2, 3], [4, 5, 6]], coords={ 'a': ['a', 'b'], 'b': ['x', 'y', 'z'] }, dims=['a', 'b']) g = d.multi_groupby(['a']).mean() assert g.equals( DataAssembly([2, 5], coords={'a': ['a', 'b']}, dims=['a']))
def test_single_dimension_int(self): d = DataAssembly([[1, 2, 3], [4, 5, 6]], coords={ 'a': [1, 2], 'b': [3, 4, 5] }, dims=['a', 'b']) g = d.multi_groupby(['a']).mean() assert g.equals( DataAssembly([2., 5.], coords={'a': [1, 2]}, dims=['a']))
def test_single_coord(self): d = DataAssembly( [[1, 2, 3], [4, 5, 6]], coords={ 'a': ('multi_dim', ['a', 'b']), 'b': ('multi_dim', ['c', 'c']), 'c': ['x', 'y', 'z'] }, dims=['multi_dim', 'c']) g = d.multi_groupby(['a']).mean() assert g.equals( DataAssembly([2, 5], coords={'multi_dim': ['a', 'b']}, dims=['multi_dim']))
def test_multi_dim(self): d = DataAssembly([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], coords={ 'a': ['a', 'a', 'b', 'b'], 'b': ['x', 'y', 'z'] }, dims=['a', 'b']) g = d.multi_groupby(['a', 'b']).mean() assert g.equals( DataAssembly([2.5, 3.5, 4.5], [8.5, 9.5, 10.5], coords={ 'a': ['a', 'b'], 'b': ['x', 'y', 'z'] }, dims=['a', 'b']))
def test_int_multi_coord(self): d = DataAssembly( [1, 2, 3, 4, 5, 6], coords={ 'a': ('multi_dim', [1, 1, 1, 1, 1, 1]), 'b': ('multi_dim', ['a', 'a', 'a', 'b', 'b', 'b']), 'c': ('multi_dim', ['a', 'b', 'c', 'd', 'e', 'f']) }, dims=['multi_dim']) g = d.multi_groupby(['a', 'b']).mean() assert g.equals( DataAssembly([2., 5.], coords={ 'a': ('multi_dim', [1, 1]), 'b': ('multi_dim', ['a', 'b']) }, dims=['multi_dim']))
def test_single_coord(self): d = DataAssembly(data=[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20]], coords={ "greek": ("a", ['alpha', 'beta', 'gamma']), "colors": ("a", ['red', 'green', 'blue']), "compass": ("b", [ 'north', 'south', 'east', 'west', 'northeast', 'southeast', 'southwest' ]), "integer": ("b", [0, 1, 2, 3, 4, 5, 6]), }, dims=("a", "b")) g = d.multi_groupby(['greek']).mean(...) c = DataAssembly( data=[3, 10, 17], coords={'greek': ('greek', ['alpha', 'beta', 'gamma'])}, dims=['greek']) assert g.equals(c)
def test_two_coord(self): assy = DataAssembly( [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17, 18]], coords={ 'up': ("a", ['alpha', 'alpha', 'beta', 'beta', 'beta', 'beta']), 'down': ("a", [1, 1, 1, 1, 2, 2]), 'sideways': ('b', ['x', 'y', 'z']) }, dims=['a', 'b']) assy_grouped = assy.multi_groupby(['up', 'down']).mean(dim="a") assy_2 = DataAssembly( [[2.5, 3.5, 4.5], [8.5, 9.5, 10.5], [14.5, 15.5, 16.5]], coords={ 'up': ("a", ['alpha', 'beta', 'beta']), 'down': ("a", [1, 1, 2]), 'sideways': ('b', ['x', 'y', 'z']) }, dims=['a', 'b']) assert assy_grouped.equals(assy_2)