Example #1
0
    def test_get_array_ragged(self):
        """get_array_ragged should return a raggend array of all elements in the storage."""

        store = FlattenedStorage(elem=[[1], [2, 3], [4, 5, 6]],
                                 chunk=[-1, -2, -3])
        val = store.get_array_ragged("elem")
        self.assertEqual(val.shape, (3, ), "shape not correct!")
        for i, v in enumerate(val):
            self.assertEqual(len(v), store._per_chunk_arrays["length"][i],
                             f"array {i} has incorrect length!")
            self.assertTrue(np.array_equal(v, [[1], [2, 3], [4, 5, 6]][i]),
                            f"array {i} has incorrect values, {v}!")
        self.assertTrue(
            np.array_equal(
                store.get_array("chunk"),
                store.get_array_ragged("chunk"),
            ),
            "get_array_ragged does not give same result as get_array for per chunk array"
        )
Example #2
0
 def test_get_array_ragged_dtype_stability(self):
     """get_array_ragged should (only!) convert top-most dimension to dtype=object and be of shape (n,) """
     # regression test
     store = FlattenedStorage(elem=[[1, 2], [3, 4], [5, 6]])
     ragged = store.get_array_ragged("elem")
     self.assertEqual(ragged.dtype, np.dtype("O"),
                      "Top most dtype not object!")
     self.assertEqual(len(ragged.shape), 1, "Shape not (n,)!")
     for array in store._per_element_arrays:
         for a in ragged:
             self.assertEqual(
                 a.dtype, store._per_element_arrays[array].dtype,
                 "Nested array returned from get_array_ragged has wrong dtype!"
             )