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


Python common.get_filepath_or_buffer方法代码示例

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


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

示例1: write

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def write(self, df, path, compression='snappy',
              coerce_timestamps='ms', index=None, partition_cols=None,
              **kwargs):
        self.validate_dataframe(df)
        path, _, _, _ = get_filepath_or_buffer(path, mode='wb')

        if index is None:
            from_pandas_kwargs = {}
        else:
            from_pandas_kwargs = {'preserve_index': index}
        table = self.api.Table.from_pandas(df, **from_pandas_kwargs)
        if partition_cols is not None:
            self.api.parquet.write_to_dataset(
                table, path, compression=compression,
                coerce_timestamps=coerce_timestamps,
                partition_cols=partition_cols, **kwargs)
        else:
            self.api.parquet.write_table(
                table, path, compression=compression,
                coerce_timestamps=coerce_timestamps, **kwargs) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:parquet.py

示例2: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, filepath_or_buffer, index=None, encoding='ISO-8859-1',
                 chunksize=None):

        self._encoding = encoding
        self._lines_read = 0
        self._index = index
        self._chunksize = chunksize

        if isinstance(filepath_or_buffer, str):
            (filepath_or_buffer, encoding,
             compression, should_close) = get_filepath_or_buffer(
                filepath_or_buffer, encoding=encoding)

        if isinstance(filepath_or_buffer, (str, compat.text_type, bytes)):
            self.filepath_or_buffer = open(filepath_or_buffer, 'rb')
        else:
            # Copy to BytesIO, and ensure no encoding
            contents = filepath_or_buffer.read()
            try:
                contents = contents.encode(self._encoding)
            except UnicodeEncodeError:
                pass
            self.filepath_or_buffer = compat.BytesIO(contents)

        self._read_header() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:sas_xport.py

示例3: write

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def write(self, df, path, compression='snappy',
              coerce_timestamps='ms', **kwargs):
        self.validate_dataframe(df)
        if self._pyarrow_lt_070:
            self._validate_write_lt_070(df)
        path, _, _, _ = get_filepath_or_buffer(path, mode='wb')

        if self._pyarrow_lt_060:
            table = self.api.Table.from_pandas(df, timestamps_to_ms=True)
            self.api.parquet.write_table(
                table, path, compression=compression, **kwargs)

        else:
            table = self.api.Table.from_pandas(df)
            self.api.parquet.write_table(
                table, path, compression=compression,
                coerce_timestamps=coerce_timestamps, **kwargs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:parquet.py

示例4: read

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def read(self, path, columns=None, **kwargs):
        path, _, _, should_close = get_filepath_or_buffer(path)
        if self._pyarrow_lt_070:
            result = self.api.parquet.read_pandas(path, columns=columns,
                                                  **kwargs).to_pandas()
        else:
            kwargs['use_pandas_metadata'] = True
            result = self.api.parquet.read_table(path, columns=columns,
                                                 **kwargs).to_pandas()
        if should_close:
            try:
                path.close()
            except:  # noqa: flake8
                pass

        return result 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:parquet.py

示例5: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, filepath_or_buffer, index=None, encoding='ISO-8859-1',
                 chunksize=None):

        self._encoding = encoding
        self._lines_read = 0
        self._index = index
        self._chunksize = chunksize

        if isinstance(filepath_or_buffer, str):
            (filepath_or_buffer, encoding,
             compression, should_close) = get_filepath_or_buffer(
                filepath_or_buffer, encoding=encoding)

        if isinstance(filepath_or_buffer, (str, compat.text_type, bytes)):
            self.filepath_or_buffer = open(filepath_or_buffer, 'rb')
        else:
            # Copy to BytesIO, and ensure no encoding
            contents = filepath_or_buffer.read()
            try:
                contents = contents.encode(self._encoding)
            except:
                pass
            self.filepath_or_buffer = compat.BytesIO(contents)

        self._read_header() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:sas_xport.py

示例6: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, path_or_buf, encoding='cp1252'):
        super(StataReader, self).__init__(encoding)
        self.col_sizes = ()
        self._has_string_data = False
        self._missing_values = False
        self._data_read = False
        self._value_labels_read = False
        if isinstance(path_or_buf, str):
            path_or_buf, encoding = get_filepath_or_buffer(
                path_or_buf, encoding=self._default_encoding
            )

        if isinstance(path_or_buf, (str, compat.text_type, bytes)):
            self.path_or_buf = open(path_or_buf, 'rb')
        else:
            self.path_or_buf = path_or_buf

        self._read_header() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:stata.py

示例7: write

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def write(self, df, path, compression='snappy',
              coerce_timestamps='ms', **kwargs):
        self.validate_dataframe(df)
        if self._pyarrow_lt_070:
            self._validate_write_lt_070(df)
        path, _, _ = get_filepath_or_buffer(path)

        if self._pyarrow_lt_060:
            table = self.api.Table.from_pandas(df, timestamps_to_ms=True)
            self.api.parquet.write_table(
                table, path, compression=compression, **kwargs)

        else:
            table = self.api.Table.from_pandas(df)
            self.api.parquet.write_table(
                table, path, compression=compression,
                coerce_timestamps=coerce_timestamps, **kwargs) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:19,代码来源:parquet.py

示例8: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, filepath_or_buffer, index=None, encoding='ISO-8859-1',
                 chunksize=None):

        self._encoding = encoding
        self._lines_read = 0
        self._index = index
        self._chunksize = chunksize

        if isinstance(filepath_or_buffer, str):
            filepath_or_buffer, encoding, compression = get_filepath_or_buffer(
                filepath_or_buffer, encoding=encoding)

        if isinstance(filepath_or_buffer, (str, compat.text_type, bytes)):
            self.filepath_or_buffer = open(filepath_or_buffer, 'rb')
        else:
            # Copy to BytesIO, and ensure no encoding
            contents = filepath_or_buffer.read()
            try:
                contents = contents.encode(self._encoding)
            except:
                pass
            self.filepath_or_buffer = compat.BytesIO(contents)

        self._read_header() 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:26,代码来源:sas_xport.py

示例9: test_get_filepath_or_buffer_with_path

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def test_get_filepath_or_buffer_with_path(self):
        filename = '~/sometest'
        filepath_or_buffer, _, _, should_close = icom.get_filepath_or_buffer(
            filename)
        assert filepath_or_buffer != filename
        assert os.path.isabs(filepath_or_buffer)
        assert os.path.expanduser(filename) == filepath_or_buffer
        assert not should_close 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:test_common.py

示例10: test_get_filepath_or_buffer_with_buffer

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def test_get_filepath_or_buffer_with_buffer(self):
        input_buffer = StringIO()
        filepath_or_buffer, _, _, should_close = icom.get_filepath_or_buffer(
            input_buffer)
        assert filepath_or_buffer == input_buffer
        assert not should_close 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_common.py

示例11: read

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def read(self, path, columns=None, **kwargs):
        path, _, _, should_close = get_filepath_or_buffer(path)

        kwargs['use_pandas_metadata'] = True
        result = self.api.parquet.read_table(path, columns=columns,
                                             **kwargs).to_pandas()
        if should_close:
            try:
                path.close()
            except:  # noqa: flake8
                pass

        return result 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:parquet.py

示例12: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, path_or_buf, index=None, convert_dates=True,
                 blank_missing=True, chunksize=None, encoding=None,
                 convert_text=True, convert_header_text=True):

        self.index = index
        self.convert_dates = convert_dates
        self.blank_missing = blank_missing
        self.chunksize = chunksize
        self.encoding = encoding
        self.convert_text = convert_text
        self.convert_header_text = convert_header_text

        self.default_encoding = "latin-1"
        self.compression = ""
        self.column_names_strings = []
        self.column_names = []
        self.column_formats = []
        self.columns = []

        self._current_page_data_subheader_pointers = []
        self._cached_page = None
        self._column_data_lengths = []
        self._column_data_offsets = []
        self._column_types = []

        self._current_row_in_file_index = 0
        self._current_row_on_page_index = 0
        self._current_row_in_file_index = 0

        self._path_or_buf, _, _, _ = get_filepath_or_buffer(path_or_buf)
        if isinstance(self._path_or_buf, compat.string_types):
            self._path_or_buf = open(self._path_or_buf, 'rb')
            self.handle = self._path_or_buf

        self._get_properties()
        self._parse_metadata() 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:38,代码来源:sas7bdat.py

示例13: test_get_filepath_or_buffer_with_path

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def test_get_filepath_or_buffer_with_path(self):
        filename = '~/sometest'
        filepath_or_buffer, _, _, should_close = common.get_filepath_or_buffer(
            filename)
        assert filepath_or_buffer != filename
        assert isabs(filepath_or_buffer)
        assert os.path.expanduser(filename) == filepath_or_buffer
        assert not should_close 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:test_common.py

示例14: test_get_filepath_or_buffer_with_buffer

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def test_get_filepath_or_buffer_with_buffer(self):
        input_buffer = StringIO()
        filepath_or_buffer, _, _, should_close = common.get_filepath_or_buffer(
            input_buffer)
        assert filepath_or_buffer == input_buffer
        assert not should_close 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_common.py

示例15: __init__

# 需要导入模块: from pandas.io import common [as 别名]
# 或者: from pandas.io.common import get_filepath_or_buffer [as 别名]
def __init__(self, path_or_buf, index=None, convert_dates=True,
                 blank_missing=True, chunksize=None, encoding=None,
                 convert_text=True, convert_header_text=True):

        self.index = index
        self.convert_dates = convert_dates
        self.blank_missing = blank_missing
        self.chunksize = chunksize
        self.encoding = encoding
        self.convert_text = convert_text
        self.convert_header_text = convert_header_text

        self.default_encoding = "latin-1"
        self.compression = ""
        self.column_names_strings = []
        self.column_names = []
        self.column_types = []
        self.column_formats = []
        self.columns = []

        self._current_page_data_subheader_pointers = []
        self._cached_page = None
        self._column_data_lengths = []
        self._column_data_offsets = []
        self._current_row_in_file_index = 0
        self._current_row_on_page_index = 0
        self._current_row_in_file_index = 0

        self._path_or_buf, _, _, _ = get_filepath_or_buffer(path_or_buf)
        if isinstance(self._path_or_buf, compat.string_types):
            self._path_or_buf = open(self._path_or_buf, 'rb')
            self.handle = self._path_or_buf

        self._get_properties()
        self._parse_metadata() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:37,代码来源:sas7bdat.py


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