Ejemplo n.º 1
0
    def test_archive_components_npy_contents_b(self) -> None:
        f1 = ff.parse('s(2,4)|v(int,str,bool,bool)').relabel(index=('a', 'b'))

        with TemporaryDirectory() as fp:
            f1.to_npy(fp)
            with self.assertRaises(UnsupportedOperation):
                _ = NPY(fp, 'w').contents
Ejemplo n.º 2
0
    def test_archive_components_npy_nbytes_a(self) -> None:
        f1 = ff.parse('s(2,4)|v(int,str,bool,bool)').relabel(index=('a', 'b'))

        with TemporaryDirectory() as fp:
            f1.to_npy(fp)
            npy = NPY(fp, 'r')
            self.assertEqual(npy.contents['size'].sum(), npy.nbytes)
Ejemplo n.º 3
0
    def test_archive_components_npz_from_frames_k(self) -> None:
        f1 = ff.parse('s(2,2)|v(int)').relabel(index=('a', 'b'))
        f2 = ff.parse('s(2,2)|v(int)').relabel(index=('c', 'd'))

        with TemporaryDirectory() as fp:
            with self.assertRaises(RuntimeError):
                NPY(fp, 'w').from_frames(frames=(f1, f2), axis=3)
Ejemplo n.º 4
0
    def test_archive_components_npz_from_frames_m(self) -> None:
        f1 = ff.parse('s(2,2)|v(int)').relabel(index=('a', 'b'))
        f2 = ff.parse('s(2,2)|v(int)').relabel(index=('c', 'd'))

        with TemporaryDirectory() as fp:
            with self.assertRaises(UnsupportedOperation):
                NPY(fp, 'r').from_frames(frames=(f1, f2), axis=3)
Ejemplo n.º 5
0
    def test_archive_components_npz_from_frames_f(self) -> None:
        f1 = ff.parse('s(2,2)|v(int)')
        f2 = ff.parse('s(2,2)|v(int)')

        with TemporaryDirectory() as fp:
            with self.assertRaises(RuntimeError):
                NPY(fp, 'w').from_frames(frames=(f1, f2), axis=1)
Ejemplo n.º 6
0
    def test_archive_components_npy_write_arrays_k(self) -> None:

        a1 = np.arange(12).reshape(3, 4)
        a2 = np.array(['a', 'b', 'c'])
        a3 = np.array([True, False, True])

        with TemporaryDirectory() as fp:
            with self.assertRaises(UnsupportedOperation):
                NPY(fp, 'r').from_arrays(blocks=(a1, a2, a3))
Ejemplo n.º 7
0
    def test_archive_components_npz_from_frames_j(self) -> None:
        f1 = ff.parse('s(2,2)|v(float)').relabel(columns=('a', 'b'))
        f2 = ff.parse('s(2,2)|v(float)').relabel(columns=('b', 'c'))

        with TemporaryDirectory() as fp:
            NPY(fp, 'w').from_frames(frames=(f1, f2), axis=0, include_index=False)
            f = Frame.from_npy(fp).fillna(0)
            self.assertEqual(f.to_pairs(),
                    (('a', ((0, 1930.4), (1, -1760.34), (2, 0.0), (3, 0.0))), ('b', ((0, -610.8), (1, 3243.94), (2, 1930.4), (3, -1760.34))), ('c', ((0, 0.0), (1, 0.0), (2, -610.8), (3, 3243.94))))
                    )
Ejemplo n.º 8
0
    def test_archive_components_npy_write_arrays_i(self) -> None:

        a1 = np.arange(12).reshape(3, 4)
        a2 = np.array(['a', 'b', 'c'])
        a3 = np.array([True, False, True])

        with TemporaryDirectory() as fp:
            columns=('a', 'b', 'c', 'd', 'e', 'f')
            with self.assertRaises(RuntimeError):
                NPY(fp, 'w').from_arrays(blocks=(a1, a2, a3), columns=columns, name='bar')
Ejemplo n.º 9
0
    def test_archive_components_npz_from_frames_d(self) -> None:
        f1 = ff.parse('s(2,2)|v(int)').relabel(columns=('a', 'b'))
        f2 = ff.parse('s(2,2)|v(int)').relabel(columns=('c', 'd'))

        with TemporaryDirectory() as fp:
            NPY(fp, 'w').from_frames(frames=(f1, f2), axis=1, include_columns=False)

            f = Frame.from_npy(fp)
            self.assertEqual(f.to_pairs(),
                    ((0, ((0, -88017), (1, 92867))), (1, ((0, 162197), (1, -41157))), (2, ((0, -88017), (1, 92867))), (3, ((0, 162197), (1, -41157))))
                    )
Ejemplo n.º 10
0
    def test_archive_components_npy_write_arrays_j(self) -> None:

        a1 = np.arange(12).reshape(3, 4)
        a2 = np.array(['a', 'b', 'c'])
        a3 = np.array([True, False, True])

        with TemporaryDirectory() as fp:
            columns=np.arange(6).astype('datetime64[D]')
            NPY(fp, 'w').from_arrays(blocks=(a1, a2, a3), columns=columns, name='bar', axis=1)
            f = Frame.from_npy(fp)
            dt64 = np.datetime64
            self.assertEqual(f.to_pairs(),
                    ((dt64('1970-01-01'), ((0, 0), (1, 4), (2, 8))), (dt64('1970-01-02'), ((0, 1), (1, 5), (2, 9))), (dt64('1970-01-03'), ((0, 2), (1, 6), (2, 10))), (dt64('1970-01-04'), ((0, 3), (1, 7), (2, 11))), (dt64('1970-01-05'), ((0, 'a'), (1, 'b'), (2, 'c'))), (dt64('1970-01-06'), ((0, True), (1, False), (2, True))))
                    )
Ejemplo n.º 11
0
    def test_archive_components_npy_write_arrays_h(self) -> None:

        a1 = np.arange(12).reshape(3, 4)
        a2 = np.array(['a', 'b', 'c'])
        a3 = np.array([True, False, True])

        with TemporaryDirectory() as fp:
            columns=Index(('a', 'b', 'c', 'd', 'e', 'f'), name='foo')
            NPY(fp, 'w').from_arrays(blocks=(a1, a2, a3), columns=columns, name='bar', axis=1)

            f = Frame.from_npy(fp)
            self.assertEqual(f.to_pairs(),
                    (('a', ((0, 0), (1, 4), (2, 8))), ('b', ((0, 1), (1, 5), (2, 9))), ('c', ((0, 2), (1, 6), (2, 10))), ('d', ((0, 3), (1, 7), (2, 11))), ('e', ((0, 'a'), (1, 'b'), (2, 'c'))), ('f', ((0, True), (1, False), (2, True))))
                    )
            self.assertEqual(f.name, 'bar')
            self.assertEqual(f.columns.name, 'foo')