def test_archive_components_npz_write_arrays_b(self) -> None: with temp_file('.zip') as fp: a1 = np.arange(12).reshape(3, 4) a2 = np.array([3, 4]) with self.assertRaises(RuntimeError): NPZ(fp, 'w').from_arrays(blocks=(a1, a2), axis=1) with self.assertRaises(RuntimeError): NPZ(fp, 'w').from_arrays(blocks=(a2, a1), axis=1)
def test_archive_components_npz_contents_a(self) -> None: f1 = ff.parse('s(2,4)|v(int,str,bool,bool)').relabel(index=('a', 'b')) with temp_file('.zip') as fp: f1.to_npz(fp) post = NPZ(fp).contents self.assertEquals(post.shape, (5, 4)) self.assertTrue(post['size'].sum() > 0)
def test_archive_components_npz_write_arrays_f(self) -> None: a1 = np.arange(12).reshape(3, 4) a2 = np.array([10, 20, 30, 40]).reshape(1, 4) a3 = np.arange(8).reshape(2, 4) with temp_file('.zip') as fp: NPZ(fp, 'w').from_arrays(blocks=(a1, a2, a3), axis=0) f = Frame.from_npz(fp) self.assertEqual(f.shape, (6, 4))
def test_archive_components_npz_write_arrays_a(self) -> None: with temp_file('.zip') as fp: a1 = np.arange(12).reshape(3, 4) NPZ(fp, 'w').from_arrays(blocks=(a1, )) f = Frame.from_npz(fp) self.assertEqual(f.values.tolist(), a1.tolist()) self.assertIs(f.index._map, None) self.assertIs(f.columns._map, None)
def test_archive_components_npz_write_arrays_d(self) -> None: with temp_file('.zip') as fp: from static_frame.core.index_datetime import IndexYear a1 = np.arange(12).reshape(3, 4) a2 = np.array(['a', 'b', 'c']) a3 = np.array([True, False, True]) index = np.array(['2021', '2022', '1542'], dtype='datetime64[Y]') NPZ(fp, 'w').from_arrays(blocks=(a1, a2, a3), index=index, axis=1) f = Frame.from_npz(fp) self.assertIs(f.index.__class__, IndexYear) self.assertEqual([dt.kind for dt in f.dtypes.values], ['i', 'i', 'i', 'i', 'U', 'b'])
def test_archive_components_npz_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 temp_file('.zip') as fp: columns=Index(('a', 'b', 'c', 'd', 'e', 'f'), name='foo') NPZ(fp, 'w').from_arrays(blocks=(a1, a2, a3), columns=columns, name='bar', axis=1) f = Frame.from_npz(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')
def test_archive_components_npz_write_arrays_g(self) -> None: a1 = np.arange(12).reshape(3, 4) a2 = np.array(['a', 'b', 'c']) a3 = np.array([True, False, True]) with temp_file('.zip') as fp: index = Index((10, 20, 30), name='foo') NPZ(fp, 'w').from_arrays(blocks=(a1, a2, a3), index=index, name='bar', axis=1) f = Frame.from_npz(fp) self.assertEqual(f.to_pairs(), ((0, ((10, 0), (20, 4), (30, 8))), (1, ((10, 1), (20, 5), (30, 9))), (2, ((10, 2), (20, 6), (30, 10))), (3, ((10, 3), (20, 7), (30, 11))), (4, ((10, 'a'), (20, 'b'), (30, 'c'))), (5, ((10, True), (20, False), (30, True)))) ) self.assertEqual(f.name, 'bar') self.assertEqual(f.index.name, 'foo')
def test_archive_components_npz_write_arrays_j(self) -> None: with temp_file('.zip') as fp: a1 = np.arange(12).reshape(3, 4) with self.assertRaises(RuntimeError): NPZ(fp, 'foo').from_arrays(blocks=(a1, ))
def test_archive_components_npz_write_arrays_c(self) -> None: with temp_file('.zip') as fp: a1 = np.arange(12).reshape(3, 4) index = Index((10, 20, 30)) NPZ(fp, 'w').from_arrays(blocks=(a1, ), index=index)