def test_unique_values_swappeddims(self):
     d = DataAssembly([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
                      coords={
                          'a': ['a', 'b', 'c', 'd'],
                          'b': ['x', 'y', 'z']
                      },
                      dims=['a', 'b'])
     g = d.multi_dim_apply(['b', 'a'], lambda x, **_: x)
     assert g.equals(d)
示例#2
0
 def test_multi_level(self):
     d = 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'])
     g = d.multi_dim_apply(['a', 'b'], lambda x, **_: x)
     assert g.equals(d)
示例#3
0
 def test_nonindex_coord(self):
     d = DataAssembly(
         [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
         coords={
             'a': ['a', 'b', 'c', 'd'],
             'b': ['x', 'y', 'z'],
             # additional coordinate that has no index values.
             # This could e.g. be the result of `.sel(c='remnant')`
             'c': 'remnant'
         },
         dims=['a', 'b'])
     g = d.multi_dim_apply(['a', 'b'], lambda x, **_: x)
     assert g.equals(d)  # also tests that `c` persists
 def test_subtract_mean(self):
     d = DataAssembly(
         [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
         coords={
             'a': ['a', 'b', 'c', 'd'],
             'aa': ('a', ['a', 'a', 'b', 'b']),
             'b': ['x', 'y', 'z']
         },
         dims=['a', 'b'])
     g = d.multi_dim_apply(['aa', 'b'], lambda x, **_: x - x.mean())
     assert g.equals(
         DataAssembly(
             [[-1.5, -1.5, -1.5], [1.5, 1.5, 1.5], [-1.5, -1.5, -1.5],
              [1.5, 1.5, 1.5]],
             coords={
                 'a': ['a', 'b', 'c', 'd'],
                 'aa': ('a', ['a', 'a', 'b', 'b']),
                 'b': ['x', 'y', 'z']
             },
             dims=['a', 'b']))