当前位置: 首页>>代码示例>>Python>>正文


Python BytesIO.getvalue方法代码示例

本文整理汇总了Python中pandas.compat.BytesIO.getvalue方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.getvalue方法的具体用法?Python BytesIO.getvalue怎么用?Python BytesIO.getvalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.compat.BytesIO的用法示例。


在下文中一共展示了BytesIO.getvalue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _pickle_array

# 需要导入模块: from pandas.compat import BytesIO [as 别名]
# 或者: from pandas.compat.BytesIO import getvalue [as 别名]
def _pickle_array(arr):
    arr = arr.view(np.ndarray)

    buf = BytesIO()
    write_array(buf, arr)

    return buf.getvalue()
开发者ID:bkandel,项目名称:pandas,代码行数:9,代码来源:pickle.py

示例2: compserver

# 需要导入模块: from pandas.compat import BytesIO [as 别名]
# 或者: from pandas.compat.BytesIO import getvalue [as 别名]
def compserver(payload, serial):
    (allow_profiler,
     default_profiler_output,
     profile_by_default) = _get_profiler_info()
    requested_profiler_output = payload.get('profiler_output',
                                            default_profiler_output)
    profile = payload.get('profile')
    profiling = (allow_profiler and
                 (profile or (profile_by_default and requested_profiler_output)))
    if profile and not allow_profiler:
        return ('profiling is disabled on this server', RC.FORBIDDEN)

    with ExitStack() as response_construction_context_stack:
        if profiling:
            from cProfile import Profile

            if (default_profiler_output == ':response' and
                    requested_profiler_output != ':response'):
                # writing to the local filesystem is disabled
                return ("local filepaths are disabled on this server, only"
                        " ':response' is allowed for the 'profiler_output' field",
                        RC.FORBIDDEN)

            profiler_output = requested_profiler_output
            profiler = Profile()
            profiler.enable()
            # ensure that we stop profiling in the case of an exception
            response_construction_context_stack.callback(profiler.disable)

        expr = '<failed to parse expr>'

        @response_construction_context_stack.callback
        def log_time(start=time()):
            flask.current_app.logger.info('compute expr: %s\ntotal time (s): %.3f',
                                          expr,
                                          time() - start)

        ns = payload.get('namespace', {})
        compute_kwargs = payload.get('compute_kwargs') or {}
        odo_kwargs = payload.get('odo_kwargs') or {}
        dataset = _get_data()
        ns[':leaf'] = symbol('leaf', discover(dataset))

        expr = from_tree(payload['expr'], namespace=ns)
        assert len(expr._leaves()) == 1
        leaf = expr._leaves()[0]

        try:
            result = serial.materialize(compute(expr,
                                                {leaf: dataset},
                                                **compute_kwargs),
                                        expr.dshape,
                                        odo_kwargs)
        except NotImplementedError as e:
            return ("Computation not supported:\n%s" % e, RC.NOT_IMPLEMENTED)
        except Exception as e:
            return ("Computation failed with message:\n%s: %s" % (type(e).__name__, e),
                    RC.INTERNAL_SERVER_ERROR)

        response = {'datashape': pprint(expr.dshape, width=0),
                    'data': serial.data_dumps(result),
                    'names': expr.fields}

    if profiling:
        import marshal
        from pstats import Stats

        if profiler_output == ':response':
            from pandas.compat import BytesIO
            file = BytesIO()
        else:
            file = open(_prof_path(profiler_output, expr), 'wb')

        with file:
            # Use marshal to dump the stats data to the given file.
            # This is taken from cProfile which unfortunately does not have
            # an api that allows us to pass the file object directly, only
            # a file path.
            marshal.dump(Stats(profiler).stats, file)
            if profiler_output == ':response':
                response['profiler_output'] = {'__!bytes': file.getvalue()}

    return serial.dumps(response)
开发者ID:NunoEdgarGub1,项目名称:blaze,代码行数:85,代码来源:server.py

示例3: compserver

# 需要导入模块: from pandas.compat import BytesIO [as 别名]
# 或者: from pandas.compat.BytesIO import getvalue [as 别名]

#.........这里部分代码省略.........
                                                          expected_keys),
                RC.BAD_REQUEST)

    app = flask.current_app
    (allow_profiler,
     default_profiler_output,
     profile_by_default) = _get_profiler_info()
    requested_profiler_output = payload.get(u'profiler_output',
                                            default_profiler_output)
    profile = payload.get(u'profile')
    profiling = (allow_profiler and
                 (profile or (profile_by_default and requested_profiler_output)))
    if profile and not allow_profiler:
        return ('profiling is disabled on this server', RC.FORBIDDEN)

    with ExitStack() as response_construction_context_stack:
        if profiling:
            from cProfile import Profile

            if (default_profiler_output == ':response' and
                    requested_profiler_output != ':response'):
                # writing to the local filesystem is disabled
                return ("local filepaths are disabled on this server, only"
                        " ':response' is allowed for the 'profiler_output' field",
                        RC.FORBIDDEN)

            profiler_output = requested_profiler_output
            profiler = Profile()
            profiler.enable()
            # ensure that we stop profiling in the case of an exception
            response_construction_context_stack.callback(profiler.disable)

        expr = '<failed to parse expr>'

        @response_construction_context_stack.callback
        def log_time(start=time()):
            app.logger.info('compute expr: %s\ntotal time (s): %.3f',
                            expr,
                            time() - start)

        ns = payload.get(u'namespace', {})
        compute_kwargs = payload.get(u'compute_kwargs') or {}
        odo_kwargs = payload.get(u'odo_kwargs') or {}
        dataset = _get_data()
        ns[':leaf'] = symbol('leaf', discover(dataset))

        expr = from_tree(payload[u'expr'], namespace=ns)

        if len(expr._leaves()) != 1:
            return ('too many leaves, expected 1 got %d' % len(expr._leaves()),
                    RC.BAD_REQUEST)

        leaf = expr._leaves()[0]

        formatter = getattr(flask.current_app, 'log_exception_formatter',
                            _default_log_exception_formatter)
        try:
            result = serial.materialize(compute(expr,
                                                {leaf: dataset},
                                                **compute_kwargs),
                                        expr.dshape,
                                        odo_kwargs)
        except NotImplementedError as e:
            # Note: `sys.exc_info()[2]` holds the current traceback, for
            # Python 2 / 3 compatibility. It's important not to store a local
            # reference to it.
            formatted_tb = formatter(sys.exc_info()[2])
            error_msg = "Computation not supported:\n%s\n%s" % (e, formatted_tb)
            app.logger.error(error_msg)
            return (error_msg, RC.NOT_IMPLEMENTED)
        except Exception as e:
            formatted_tb = formatter(sys.exc_info()[2])
            error_msg = "Computation failed with message:\n%s: %s\n%s" % (type(e).__name__, e, formatted_tb)
            app.logger.error(error_msg)
            return (error_msg, RC.INTERNAL_SERVER_ERROR)

        response = {u'datashape': pprint(expr.dshape, width=0),
                    u'data': serial.data_dumps(result),
                    u'names': expr.fields}

    if profiling:
        import marshal
        from pstats import Stats

        if profiler_output == ':response':
            from pandas.compat import BytesIO
            file = BytesIO()
        else:
            file = open(_prof_path(profiler_output, expr), 'wb')

        with file:
            # Use marshal to dump the stats data to the given file.
            # This is taken from cProfile which unfortunately does not have
            # an api that allows us to pass the file object directly, only
            # a file path.
            marshal.dump(Stats(profiler).stats, file)
            if profiler_output == ':response':
                response[u'profiler_output'] = {'__!bytes': file.getvalue()}

    return serial.dumps(response)
开发者ID:necaris,项目名称:blaze,代码行数:104,代码来源:server.py


注:本文中的pandas.compat.BytesIO.getvalue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。