當前位置: 首頁>>代碼示例>>Python>>正文


Python pyarrow.deserialize方法代碼示例

本文整理匯總了Python中pyarrow.deserialize方法的典型用法代碼示例。如果您正苦於以下問題:Python pyarrow.deserialize方法的具體用法?Python pyarrow.deserialize怎麽用?Python pyarrow.deserialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyarrow的用法示例。


在下文中一共展示了pyarrow.deserialize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: loads

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def loads(buf):
    mv = memoryview(buf)
    header = read_file_header(mv)
    compress = header.compress

    if compress == CompressType.NONE:
        data = buf[HEADER_LENGTH:]
    else:
        data = decompressors[compress](mv[HEADER_LENGTH:])

    if header.type == SerialType.ARROW:
        try:
            return pyarrow.deserialize(memoryview(data), mars_serialize_context())
        except pyarrow.lib.ArrowInvalid:  # pragma: no cover
            # reconstruct value from buffers of arrow components
            data_view = memoryview(data)
            meta_block_size = np.frombuffer(data_view[0:4], dtype='int32').item()
            meta = pickle.loads(data_view[4:4 + meta_block_size])  # nosec
            buffer_sizes = meta.pop('buffer_sizes')
            bounds = np.cumsum([4 + meta_block_size] + buffer_sizes)
            meta['data'] = [pyarrow.py_buffer(data_view[bounds[idx]:bounds[idx + 1]])
                            for idx in range(len(buffer_sizes))]
            return pyarrow.deserialize_components(meta, mars_serialize_context())
    else:
        return pickle.loads(data) 
開發者ID:mars-project,項目名稱:mars,代碼行數:27,代碼來源:dataserializer.py

示例2: recv_params_from_learner

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def recv_params_from_learner(self):
        """Get new params and sync. return True if success, False otherwise."""
        received = False
        try:
            new_params_id = self.sub_socket.recv(zmq.DONTWAIT)
            received = True
        except zmq.Again:
            # Although learner doesn't send params, don't wait
            pass

        if received:
            new_param_info = pa.deserialize(new_params_id)
            update_step, new_params = new_param_info
            self.update_step = update_step
            self.worker.synchronize(new_params)

            # Add new entry for scores dict
            self.scores[self.update_step] = [] 
開發者ID:medipixel,項目名稱:rl_algorithms,代碼行數:20,代碼來源:worker.py

示例3: run

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def run(self):
        """Run main logging loop; continuously receive data and log."""
        if self.args.log:
            self.set_wandb()

        while self.update_step < self.args.max_update_step:
            self.recv_log_info()
            if self.log_info_queue:  # if non-empty
                log_info_id = self.log_info_queue.pop()
                log_info = pa.deserialize(log_info_id)
                state_dict = log_info["state_dict"]
                log_value = log_info["log_value"]
                self.update_step = log_value["update_step"]

                self.synchronize(state_dict)
                avg_score = self.test(self.update_step)
                log_value["avg_score"] = avg_score
                self.write_log(log_value) 
開發者ID:medipixel,項目名稱:rl_algorithms,代碼行數:20,代碼來源:distributed_logger.py

示例4: recv_worker_data

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def recv_worker_data(self):
        """Receive replay data from worker and incorporate to buffer."""
        received = False
        try:
            new_replay_data_id = self.pull_socket.recv(zmq.DONTWAIT)
            received = True
        except zmq.Again:
            pass

        if received:
            new_replay_data = pa.deserialize(new_replay_data_id)
            experience, priorities = new_replay_data
            for idx in range(len(experience["states"])):
                transition = (
                    experience["states"][idx],
                    experience["actions"][idx],
                    experience["rewards"][idx],
                    experience["next_states"][idx],
                    experience["dones"][idx],
                )
                self.buffer.add(transition)
                self.buffer.update_priorities([len(self.buffer) - 1], priorities[idx]) 
開發者ID:medipixel,項目名稱:rl_algorithms,代碼行數:24,代碼來源:wrapper.py

示例5: load

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def load(self, data):
        # If the type of the input is bytes, then we need to deserialize the
        # input first.
        if type(data) == bytes:
            val = Value()
            val.ParseFromString(data)
        elif type(data).__name__ == Value.__name__:
            # If it's already deserialized, we can just proceed.
            val = data
        else:
            raise ValueError(f'''Input to load was of unsupported type
                             {str(type(data))}.''')

        if val.type == DEFAULT:
            try:
                return self._load_default(val.body)
            except: # Unpickling error.
                return val.body
        elif val.type == STRING:
            return self._load_string(val.body)
        elif val.type == NUMPY:
            return self._load_numpy(val.body) 
開發者ID:hydro-project,項目名稱:cloudburst,代碼行數:24,代碼來源:serializer.py

示例6: load_pyarrow

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def load_pyarrow(buf):
    assert buf is not None, 'buf should not be None.'
    return pyarrow.deserialize(buf) 
開發者ID:PistonY,項目名稱:torch-toolbox,代碼行數:5,代碼來源:convert_lmdb.py

示例7: loads

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def loads(buf):
        """
        Args:
            buf: the output of `dumps` or `dumps_bytes`.
        """
        import pyarrow as pa
        return pa.deserialize(buf) 
開發者ID:tensorpack,項目名稱:dataflow,代碼行數:9,代碼來源:serialize.py

示例8: load

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def load(file):
    header = read_file_header(file)
    file = open_decompression_file(file, header.compress)

    try:
        buf = file.read()
    finally:
        if header.compress != CompressType.NONE:
            file.close()

    if header.type == SerialType.ARROW:
        return pyarrow.deserialize(memoryview(buf), mars_serialize_context())
    else:
        return pickle.loads(buf) 
開發者ID:mars-project,項目名稱:mars,代碼行數:16,代碼來源:dataserializer.py

示例9: deserialize

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def deserialize(data):
    return pyarrow.deserialize(data, mars_serialize_context()) 
開發者ID:mars-project,項目名稱:mars,代碼行數:4,代碼來源:dataserializer.py

示例10: ray_decompress

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def ray_decompress(data):
    if isinstance(data, bytes) or isinstance(data, string_types):
        data = base64.b64decode(data)
        data = lz4.frame.decompress(data)
        data = pyarrow.deserialize(data)
    return data


# Ray's magic constant worker explorations.. 
開發者ID:rlgraph,項目名稱:rlgraph,代碼行數:11,代碼來源:ray_util.py

示例11: deserialize

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def deserialize(self, serialized_rows):
        return pyarrow.deserialize(serialized_rows, self._get_serialization_context()) 
開發者ID:uber,項目名稱:petastorm,代碼行數:4,代碼來源:pyarrow_serializer.py

示例12: recv_replay_data

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def recv_replay_data(self):
        """Receive replay data from gloal buffer."""
        replay_data_id = self.rep_socket.recv()
        replay_data = pa.deserialize(replay_data_id)
        return replay_data 
開發者ID:medipixel,項目名稱:rl_algorithms,代碼行數:7,代碼來源:learner.py

示例13: send_batch_to_learner

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def send_batch_to_learner(self):
        """Send batch to learner and receive priorities."""
        # Send batch and request priorities (blocking recv)
        batch = self.buffer.sample(self.per_beta)
        batch_id = pa.serialize(batch).to_buffer()
        self.req_socket.send(batch_id)
        self.num_sent = self.num_sent + 1

        # Receive priorities
        new_priors_id = self.req_socket.recv()
        idxes, new_priorities = pa.deserialize(new_priors_id)
        self.buffer.update_priorities(idxes, new_priorities) 
開發者ID:medipixel,項目名稱:rl_algorithms,代碼行數:14,代碼來源:wrapper.py

示例14: loads_pyarrow

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def loads_pyarrow(buf):
    """
    Args:
        buf: the output of `dumps`.
    """
    return pa.deserialize(buf) 
開發者ID:chenyilun95,項目名稱:tf-cpn,代碼行數:8,代碼來源:serialize.py

示例15: loads_pyarrow

# 需要導入模塊: import pyarrow [as 別名]
# 或者: from pyarrow import deserialize [as 別名]
def loads_pyarrow(buf):
    """
    Args:
        buf: the output of `dumps`.
    """
    return pa.deserialize(buf)


# import pyarrow has a lot of side effect:
# https://github.com/apache/arrow/pull/2329
# https://groups.google.com/a/tensorflow.org/forum/#!topic/developers/TMqRaT-H2bI
# So we use msgpack as default. 
開發者ID:microsoft,項目名稱:petridishnn,代碼行數:14,代碼來源:serialize.py


注:本文中的pyarrow.deserialize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。