本文整理汇总了Python中pandas.compat.text_type方法的典型用法代码示例。如果您正苦于以下问题:Python compat.text_type方法的具体用法?Python compat.text_type怎么用?Python compat.text_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.compat
的用法示例。
在下文中一共展示了compat.text_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_repr_roundtrip
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def test_repr_roundtrip(self):
ci = CategoricalIndex(['a', 'b'], categories=['a', 'b'], ordered=True)
str(ci)
tm.assert_index_equal(eval(repr(ci)), ci, exact=True)
# formatting
if PY3:
str(ci)
else:
compat.text_type(ci)
# long format
# this is not reprable
ci = CategoricalIndex(np.random.randint(0, 5, size=100))
if PY3:
str(ci)
else:
compat.text_type(ci)
示例2: test_map_with_string_constructor
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def test_map_with_string_constructor(self):
raw = [2005, 2007, 2009]
index = PeriodIndex(raw, freq='A')
types = str,
if PY3:
# unicode
types += text_type,
for t in types:
expected = Index(lmap(t, raw))
res = index.map(t)
# should return an Index
assert isinstance(res, Index)
# preserve element types
assert all(isinstance(resi, t) for resi in res)
# lastly, values should compare equal
tm.assert_index_equal(res, expected)
示例3: test_read_csv_local
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def test_read_csv_local(all_parsers, csv1):
prefix = u("file:///") if compat.is_platform_windows() else u("file://")
parser = all_parsers
fname = prefix + compat.text_type(os.path.abspath(csv1))
result = parser.read_csv(fname, index_col=0, parse_dates=True)
expected = DataFrame([[0.980269, 3.685731, -0.364216805298, -1.159738],
[1.047916, -0.041232, -0.16181208307, 0.212549],
[0.498581, 0.731168, -0.537677223318, 1.346270],
[1.120202, 1.567621, 0.00364077397681, 0.675253],
[-0.487094, 0.571455, -1.6116394093, 0.103469],
[0.836649, 0.246462, 0.588542635376, 1.062782],
[-0.157161, 1.340307, 1.1957779562, -1.097007]],
columns=["A", "B", "C", "D"],
index=Index([datetime(2000, 1, 3),
datetime(2000, 1, 4),
datetime(2000, 1, 5),
datetime(2000, 1, 6),
datetime(2000, 1, 7),
datetime(2000, 1, 10),
datetime(2000, 1, 11)], name="index"))
tm.assert_frame_equal(result, expected)
示例4: _evaluate
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def _evaluate(self):
import numexpr as ne
# convert the expression to a valid numexpr expression
s = self.convert()
try:
env = self.expr.env
scope = env.full_scope
truediv = scope['truediv']
_check_ne_builtin_clash(self.expr)
return ne.evaluate(s, local_dict=scope, truediv=truediv)
except KeyError as e:
# python 3 compat kludge
try:
msg = e.message
except AttributeError:
msg = compat.text_type(e)
raise UndefinedVariableError(msg)
示例5: _get_footer
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def _get_footer(self):
footer = ''
if self.length:
if footer:
footer += ', '
footer += "Length: {length}".format(length=len(self.categorical))
level_info = self.categorical._repr_categories_info()
# Levels are added in a newline
if footer:
footer += '\n'
footer += level_info
return compat.text_type(footer)
示例6: to_string
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def to_string(self):
categorical = self.categorical
if len(categorical) == 0:
if self.footer:
return self._get_footer()
else:
return u('')
fmt_values = self._get_formatted_values()
result = [u('{i}').format(i=i) for i in fmt_values]
result = [i.strip() for i in result]
result = u(', ').join(result)
result = [u('[') + result + u(']')]
if self.footer:
footer = self._get_footer()
if footer:
result.append(footer)
return compat.text_type(u('\n').join(result))
示例7: __init__
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [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()
示例8: __init__
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [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()
示例9: init_qt_clipboard
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def init_qt_clipboard():
# $DISPLAY should exist
# Try to import from qtpy, but if that fails try PyQt5 then PyQt4
try:
from qtpy.QtWidgets import QApplication
except ImportError:
try:
from PyQt5.QtWidgets import QApplication
except ImportError:
from PyQt4.QtGui import QApplication
app = QApplication.instance()
if app is None:
app = QApplication([])
def copy_qt(text):
cb = app.clipboard()
cb.setText(text)
def paste_qt():
cb = app.clipboard()
return text_type(cb.text())
return copy_qt, paste_qt
示例10: test_map_with_string_constructor
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def test_map_with_string_constructor(self):
raw = [2005, 2007, 2009]
index = PeriodIndex(raw, freq='A')
types = str,
if compat.PY3:
# unicode
types += compat.text_type,
for t in types:
expected = np.array(lmap(t, raw), dtype=object)
res = index.map(t)
# should return an array
tm.assert_isinstance(res, np.ndarray)
# preserve element types
self.assert_(all(isinstance(resi, t) for resi in res))
# dtype should be object
self.assertEqual(res.dtype, np.dtype('object').type)
# lastly, values should compare equal
assert_array_equal(res, expected)
示例11: _evaluate
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def _evaluate(self):
import numexpr as ne
# add the resolvers to locals
self.expr.add_resolvers_to_locals()
# convert the expression to a valid numexpr expression
s = self.convert()
try:
return ne.evaluate(s, local_dict=self.expr.env.locals,
global_dict=self.expr.env.globals,
truediv=self.expr.truediv)
except KeyError as e:
# python 3 compat kludge
try:
msg = e.message
except AttributeError:
msg = compat.text_type(e)
raise UndefinedVariableError(msg)
示例12: to_string
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def to_string(self):
series = self.series
if len(series) == 0:
return u('')
fmt_index, have_header = self._get_formatted_index()
fmt_values = self._get_formatted_values()
maxlen = max(len(x) for x in fmt_index)
pad_space = min(maxlen, 60)
result = ['%s %s'] * len(fmt_values)
for i, (k, v) in enumerate(zip(fmt_index[1:], fmt_values)):
idx = k.ljust(pad_space)
result[i] = result[i] % (idx, v)
if self.header and have_header:
result.insert(0, fmt_index[0])
footer = self._get_footer()
if footer:
result.append(footer)
return compat.text_type(u('\n').join(result))
示例13: _get_repr
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def _get_repr(
self, name=False, print_header=False, length=True, dtype=True,
na_rep='NaN', float_format=None):
"""
Internal function, should always return unicode string
"""
formatter = fmt.SeriesFormatter(self, name=name, header=print_header,
length=length, dtype=dtype,
na_rep=na_rep,
float_format=float_format)
result = formatter.to_string()
# TODO: following check prob. not neces.
if not isinstance(result, compat.text_type):
raise AssertionError("result must be of type unicode, type"
" of result is {0!r}"
"".format(result.__class__.__name__))
return result
示例14: __init__
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [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()
示例15: test_array_repr_unicode
# 需要导入模块: from pandas import compat [as 别名]
# 或者: from pandas.compat import text_type [as 别名]
def test_array_repr_unicode(self, data):
result = compat.text_type(data)
assert isinstance(result, compat.text_type)