def test_store_zip_pickle_a(self) -> None: f1, f2, f3 = get_test_framesA() with temp_file('.zip') as fp: st = StoreZipPickle(fp) st.write((f.name, f) for f in (f1, f2, f3)) labels = tuple(st.labels(strip_ext=False)) self.assertEqual(labels, ('foo.pickle', 'bar.pickle', 'baz.pickle')) for label, frame in ((f.name, f) for f in (f1, f2, f3)): frame_stored = st.read(label) self.assertEqual(frame_stored.shape, frame.shape) self.assertTrue((frame_stored == frame).all().all()) self.assertEqual(frame.to_pairs(0), frame_stored.to_pairs(0)) frame_stored_2 = st.read(label, container_type=FrameGO) self.assertEqual(frame_stored_2.__class__, FrameGO) self.assertEqual(frame_stored_2.shape, frame.shape) frame_stored_3 = st.read(label, container_type=FrameHE) self.assertEqual(frame_stored_3.__class__, FrameHE) self.assertEqual(frame_stored_3.shape, frame.shape)
def test_store_zip_pickle_a(self) -> None: f1 = Frame.from_dict(dict(a=(1, 2), b=(3, 4)), index=('x', 'y'), name='foo') f2 = Frame.from_dict(dict(a=(1, 2, 3), b=(4, 5, 6)), index=('x', 'y', 'z'), name='bar') f3 = Frame.from_dict(dict(a=(10, 20), b=(50, 60)), index=('p', 'q'), name='baz') with temp_file('.zip') as fp: st = StoreZipPickle(fp) st.write((f.name, f) for f in (f1, f2, f3)) labels = tuple(st.labels(strip_ext=False)) self.assertEqual(labels, ('foo.pickle', 'bar.pickle', 'baz.pickle')) for label, frame in ((f.name, f) for f in (f1, f2, f3)): frame_stored = st.read(label) self.assertEqual(frame_stored.shape, frame.shape) self.assertTrue((frame_stored == frame).all().all()) self.assertEqual(frame.to_pairs(0), frame_stored.to_pairs(0)) frame_stored_2 = st.read(label, container_type=FrameGO) self.assertEqual(frame_stored_2.__class__, FrameGO) self.assertEqual(frame_stored_2.shape, frame.shape)
def test_store_zip_pickle_c(self) -> None: f1, *_ = get_test_framesA(FrameGO) with temp_file('.zip') as fp: st = StoreZipPickle(fp) st.write(((f1.name, f1), )) frame_stored = st.read(f1.name) self.assertEqual(frame_stored.shape, f1.shape) self.assertTrue(frame_stored.__class__ is Frame)
def to_zip_pickle(self, fp: PathSpecifier, config: StoreConfigMapInitializer = None) -> None: ''' Write the complete :obj:`Bus` as a zipped archive of pickles. {args} ''' store = StoreZipPickle(fp) # config must be None for pickels, will raise otherwise store.write(self.items(), config=config)
def to_zip_pickle(self, fp: PathSpecifier, *, config: StoreConfigMapInitializer = None) -> None: ''' Write the complete :obj:`Bus` as a zipped archive of pickles. {args} ''' store = StoreZipPickle(fp) config = self._filter_config(config) store.write(self._items_store(), config=config)
def test_store_zip_pickle_c(self) -> None: f1 = FrameGO.from_dict(dict(a=(1, 2), b=(3, 4)), index=('x', 'y'), name='foo') config = StoreConfig(index_depth=1, include_index=True) config_map = StoreConfigMap.from_config(config) with temp_file('.zip') as fp: st = StoreZipPickle(fp) # raise if trying to store a FrameGO with self.assertRaises(NotImplementedError): st.write(((f1.name, f1), ))
def test_store_zip_pickle_b(self) -> None: f1 = Frame.from_dict(dict(a=(1, 2), b=(3, 4)), index=('x', 'y'), name='foo') config = StoreConfig(index_depth=1, include_index=True) config_map = StoreConfigMap.from_config(config) with temp_file('.zip') as fp: st = StoreZipPickle(fp) st.write(((f1.name, f1), )) frame_stored = st.read(f1.name) self.assertEqual(frame_stored.shape, f1.shape)
def test_store_zip_pickle_e(self) -> None: f1, f2, f3 = get_test_framesA(FrameGO) with temp_file('.zip') as fp: st = StoreZipPickle(fp) st.write((f.name, f) for f in (f1, f2, f3)) post = tuple(st.read_many(('baz', 'bar', 'foo'), container_type=Frame)) self.assertEqual(len(post), 3) self.assertEqual(post[0].name, 'baz') self.assertEqual(post[1].name, 'bar') self.assertEqual(post[2].name, 'foo') self.assertTrue(post[0].__class__ is Frame) self.assertTrue(post[1].__class__ is Frame) self.assertTrue(post[2].__class__ is Frame)
def test_store_zip_pickle_d(self) -> None: f1, *_ = get_test_framesA() with temp_file('.zip') as fp: for read_max_workers in (1, 2): config = StoreConfig( index_depth=1, include_index=True, label_encoder=lambda x: x.upper(), #type: ignore label_decoder=lambda x: x.lower(), read_max_workers=read_max_workers, ) st = StoreZipPickle(fp) st.write(((f1.name, f1), ), config=config) frame_stored = st.read(f1.name, config=config) self.assertEqual(tuple(st.labels()), ('FOO', )) self.assertEqual(tuple(st.labels(config=config)), ('foo', ))
def to_zip_pickle(self, fp: PathSpecifier, config: StoreConfigMapInitializer = None) -> None: store = StoreZipPickle(fp) # config must be None for pickels, will raise otherwise store.write(self.items(), config=config)