def test_to_npy_f(self) -> None:
     a1 = np.array([('Rex', 9, 81.0), ('Fido', 3, 27.0)],
                   dtype=[('name', 'U10'), ('age', 'i4'), ('weight', 'f4')])
     with temp_file('.npy') as fp:
         with open(fp, 'wb') as f:
             with self.assertRaises(ErrorNPYEncode):
                 NPYConverter.to_npy(f, a1)
    def test_to_npy_b(self) -> None:
        a1 = np.array([None, 'foo', 3], dtype=object)

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                with self.assertRaises(ErrorNPYEncode):
                    NPYConverter.to_npy(f, a1)
    def test_from_npy_a(self) -> None:
        a1 = np.arange(20)

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)
            with open(fp, 'rb') as f:
                a2, _ = NPYConverter.from_npy(f, {})
            self.assertTrue((a1 == a2).all())
    def test_to_npy_e(self) -> None:
        a1 = np.arange(4)
        with temp_file('.npy') as fp:

            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)
            # ensure compatibility with numpy loaders
            a2 = np.load(fp)
            self.assertTrue((a1 == a2).all())
    def test_to_npy_a(self) -> None:
        a1 = np.arange(20)

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)

            a2 = np.load(fp)
            self.assertTrue((a1 == a2).all())
    def test_from_npy_g(self) -> None:
        a1 = np.array([2, 3, 4])

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)
            with open(fp, 'rb') as f:
                a2, _ = NPYConverter.from_npy(f, {}, memory_map=True)
                self.assertEqual(a2.tolist(), [2, 3, 4])
    def test_frame_to_npy_b(self, a1: Frame) -> None:

        header_decode_cache: HeaderDecodeCacheType = {}

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)

            with open(fp, 'rb') as f:
                a2, mm = NPYConverter.from_npy(f,
                        header_decode_cache,
                        memory_map=True,
                        )
                if a2.dtype.kind in DTYPE_INEXACT_KINDS:
                    self.assertAlmostEqualArray(a1, a2)
                else:
                    self.assertTrue((a1 == a2).all())
                self.assertTrue(a1.shape == a2.shape)
Beispiel #8
0
    def test_frame_to_npy_a(self, a1: Frame) -> None:

        header_decode_cache: HeaderDecodeCacheType = {}

        with temp_file('.npy') as fp:
            with open(fp, 'wb') as f:
                NPYConverter.to_npy(f, a1)

            # check compatibility with built-in NPY reading
            a2 = np.load(fp)
            if a2.dtype.kind in DTYPE_INEXACT_KINDS:
                self.assertAlmostEqualArray(a1, a2)
            else:
                self.assertTrue((a1 == a2).all())
            self.assertTrue(a1.shape == a2.shape)

            with open(fp, 'rb') as f:
                a3, _ = NPYConverter.from_npy(f, header_decode_cache)
                if a3.dtype.kind in DTYPE_INEXACT_KINDS:
                    self.assertAlmostEqualArray(a1, a3)
                else:
                    self.assertTrue((a1 == a3).all())
                self.assertTrue(a1.shape == a3.shape)
 def test_to_npy_c(self) -> None:
     a1 = np.arange(12).reshape(2, 3, 2)
     with temp_file('.npy') as fp:
         with open(fp, 'wb') as f:
             with self.assertRaises(ErrorNPYEncode):
                 NPYConverter.to_npy(f, a1)