Exemple #1
0
 def from_zip_pickle(cls,
                     fp: PathSpecifier,
                     config: StoreConfigMapInitializer = None) -> 'Bus':
     store = StoreZipPickle(fp)
     return cls(cls._deferred_series(store.labels()),
                store=store,
                config=config)
    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)
Exemple #4
0
    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_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_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_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 from_zip_pickle(
            cls,
            fp: PathSpecifier,
            config: StoreConfigMapInitializer = None) -> 'StoreClientMixin':
        '''
        Given a file path to zipped pickle :obj:`Bus` store, return a :obj:`Bus` instance.

        {args}
        '''
        store = StoreZipPickle(fp)
        return cls._from_store(store, config)  #type: ignore
    def from_zip_pickle(
        cls,
        fp: PathSpecifier,
        config: StoreConfigMapInitializer = None,
        max_persist: tp.Optional[int] = None,
    ) -> 'StoreClientMixin':
        '''
        Given a file path to zipped pickle :obj:`Bus` store, return a :obj:`Bus` instance.

        {args}
        '''
        store = StoreZipPickle(fp)
        return cls._from_store(
            store,  #type: ignore
            config=config,
            max_persist=max_persist,
        )
Exemple #12
0
    def from_zip_pickle(cls,
            fp: PathSpecifier,
            *,
            config: StoreConfigMapInitializer = None,
            max_persist: tp.Optional[int] = None,
            index_constructor: IndexConstructor = None,
            ) -> 'Bus':
        '''
        Given a file path to zipped pickle :obj:`Bus` store, return a :obj:`Bus` instance.

        {args}
        '''
        store = StoreZipPickle(fp)
        return cls._from_store(store,
                config=config,
                max_persist=max_persist,
                index_constructor=index_constructor,
                )
Exemple #13
0
    def from_zip_pickle(cls,
            fp: PathSpecifier,
            *,
            config: StoreConfigMapInitializer = None,
            axis: int = 0,
            retain_labels: bool,
            deepcopy_from_bus: bool = False,
            max_persist: tp.Optional[int] = None,
            ) -> 'Quilt':
        '''
        Given a file path to zipped pickle :obj:`Quilt` store, return a :obj:`Quilt` instance.

        {args}
        '''
        store = StoreZipPickle(fp)
        return cls._from_store(store,
                config=config,
                axis=axis,
                retain_labels=retain_labels,
                deepcopy_from_bus=deepcopy_from_bus,
                max_persist=max_persist,
                )
Exemple #14
0
    def from_zip_pickle(
        cls,
        fp: PathSpecifier,
        *,
        config: StoreConfigMapInitializer = None,
        max_workers: tp.Optional[int] = None,
        chunksize: int = 1,
        use_threads: bool = False,
    ) -> 'Batch':
        '''
        Given a file path to zipped pickle :obj:`Batch` store, return a :obj:`Batch` instance.

        {args}
        '''
        store = StoreZipPickle(fp)
        return cls._from_store(
            store,
            config=config,
            max_workers=max_workers,
            chunksize=chunksize,
            use_threads=use_threads,
        )
    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', ))
Exemple #16
0
 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)