Exemplo n.º 1
0
 def test_transforms(self):
     # Add transform at initialisation
     indexer = DaskLazyIndexer(self.data_dask, transforms=[lambda x: 0 * x])
     np.testing.assert_array_equal(indexer[:], np.zeros_like(indexer))
     # Add transform before first use of object
     indexer = DaskLazyIndexer(self.data_dask)
     indexer.add_transform(lambda x: 0 * x)
     np.testing.assert_array_equal(indexer[:], np.zeros_like(indexer))
     # Add transform after first use of object
     indexer = DaskLazyIndexer(self.data_dask)
     indexer.dataset
     indexer.add_transform(lambda x: 0 * x)
     np.testing.assert_array_equal(indexer[:], np.zeros_like(indexer))
Exemplo n.º 2
0
 def test_str_repr(self):
     def transform1(x):
         return x
     transform2 = lambda x: x  # noqa: E731
     class Transform3:         # noqa: E306
         def __call__(self, x):
             return x
     transform3 = Transform3()
     transform4 = partial(transform1)
     transforms = [transform1, transform2, transform3, transform4]
     indexer = DaskLazyIndexer(self.data_dask, transforms=transforms)
     expected = 'x | transform1 | <lambda> | Transform3 | transform1'
     expected += f' -> {indexer.shape} {indexer.dtype}'
     assert_equal(str(indexer), expected)
     # Simply exercise repr - no need to check result
     repr(indexer)
Exemplo n.º 3
0
 def _test_with(self, stage1=(), stage2=()):
     npy1 = numpy_oindex(self.data, stage1)
     npy2 = numpy_oindex(npy1, stage2)
     indexer = DaskLazyIndexer(self.data_dask, stage1)
     np.testing.assert_array_equal(indexer[stage2], npy2)
Exemplo n.º 4
0
 def test_stage1_multiple_boolean_indices(self):
     stage1 = tuple([True] * d for d in self.data.shape)
     indexer = DaskLazyIndexer(self.data_dask, stage1)
     np.testing.assert_array_equal(indexer[:], self.data)
Exemplo n.º 5
0
 def test_stage1_slices(self):
     stage1 = np.s_[5:, :, 1::2]
     indexer = DaskLazyIndexer(self.data_dask, stage1)
     np.testing.assert_array_equal(indexer[:], self.data[stage1])