當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。