本文整理汇总了Python中pandas.util.testing.rands方法的典型用法代码示例。如果您正苦于以下问题:Python testing.rands方法的具体用法?Python testing.rands怎么用?Python testing.rands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.rands方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nonexistent_path
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_nonexistent_path(all_parsers):
# gh-2428: pls no segfault
# gh-14086: raise more helpful FileNotFoundError
parser = all_parsers
path = "%s.csv" % tm.rands(10)
msg = ("does not exist" if parser.engine == "c"
else r"\[Errno 2\]")
with pytest.raises(compat.FileNotFoundError, match=msg) as e:
parser.read_csv(path)
filename = e.value.filename
filename = filename.decode() if isinstance(
filename, bytes) else filename
assert path == filename
示例2: test_repr_truncation
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_repr_truncation(self):
max_len = 20
with option_context("display.max_colwidth", max_len):
df = DataFrame({'A': np.random.randn(10),
'B': [tm.rands(np.random.randint(
max_len - 1, max_len + 1)) for i in range(10)
]})
r = repr(df)
r = r[r.find('\n') + 1:]
adj = fmt._get_adjustment()
for line, value in lzip(r.split('\n'), df['B']):
if adj.len(value) + 1 > max_len:
assert '...' in line
else:
assert '...' not in line
with option_context("display.max_colwidth", 999999):
assert '...' not in repr(df)
with option_context("display.max_colwidth", max_len + 2):
assert '...' not in repr(df)
示例3: test_timestamp_compare
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_timestamp_compare(self):
# make sure we can compare Timestamps on the right AND left hand side
# GH4982
df = DataFrame({'dates1': date_range('20010101', periods=10),
'dates2': date_range('20010102', periods=10),
'intcol': np.random.randint(1000000000, size=10),
'floatcol': np.random.randn(10),
'stringcol': list(tm.rands(10))})
df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT
ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq',
'ne': 'ne'}
for left, right in ops.items():
left_f = getattr(operator, left)
right_f = getattr(operator, right)
# no nats
expected = left_f(df, Timestamp('20010109'))
result = right_f(Timestamp('20010109'), df)
assert_frame_equal(result, expected)
# nats
expected = left_f(df, Timestamp('nat'))
result = right_f(Timestamp('nat'), df)
assert_frame_equal(result, expected)
示例4: test_astype_unicode
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_astype_unicode(self):
# see gh-7758: A bit of magic is required to set
# default encoding to utf-8
digits = string.digits
test_series = [
Series([digits * 10, tm.rands(63), tm.rands(64), tm.rands(1000)]),
Series([u('データーサイエンス、お前はもう死んでいる')]),
]
former_encoding = None
if not compat.PY3:
# In Python, we can force the default encoding for this test
former_encoding = sys.getdefaultencoding()
reload(sys) # noqa
sys.setdefaultencoding("utf-8")
if sys.getdefaultencoding() == "utf-8":
test_series.append(Series([u('野菜食べないとやばい')
.encode("utf-8")]))
for s in test_series:
res = s.astype("unicode")
expec = s.map(compat.text_type)
tm.assert_series_equal(res, expec)
# Restore the former encoding
if former_encoding is not None and former_encoding != "utf-8":
reload(sys) # noqa
sys.setdefaultencoding(former_encoding)
示例5: test_timestamp_compare
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_timestamp_compare(self):
# make sure we can compare Timestamps on the right AND left hand side
# GH#4982
df = pd. DataFrame({'dates1': pd.date_range('20010101', periods=10),
'dates2': pd.date_range('20010102', periods=10),
'intcol': np.random.randint(1000000000, size=10),
'floatcol': np.random.randn(10),
'stringcol': list(tm.rands(10))})
df.loc[np.random.rand(len(df)) > 0.5, 'dates2'] = pd.NaT
ops = {'gt': 'lt', 'lt': 'gt', 'ge': 'le', 'le': 'ge', 'eq': 'eq',
'ne': 'ne'}
for left, right in ops.items():
left_f = getattr(operator, left)
right_f = getattr(operator, right)
# no nats
if left in ['eq', 'ne']:
expected = left_f(df, pd.Timestamp('20010109'))
result = right_f(pd.Timestamp('20010109'), df)
tm.assert_frame_equal(result, expected)
else:
with pytest.raises(TypeError):
left_f(df, pd.Timestamp('20010109'))
with pytest.raises(TypeError):
right_f(pd.Timestamp('20010109'), df)
# nats
expected = left_f(df, pd.Timestamp('nat'))
result = right_f(pd.Timestamp('nat'), df)
tm.assert_frame_equal(result, expected)
示例6: test_rands
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_rands():
r = tm.rands(10)
assert len(r) == 10
示例7: test_internal_eof_byte_to_file
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_internal_eof_byte_to_file(all_parsers):
# see gh-16559
parser = all_parsers
data = b'c1,c2\r\n"test \x1a test", test\r\n'
expected = DataFrame([["test \x1a test", " test"]],
columns=["c1", "c2"])
path = "__%s__.csv" % tm.rands(10)
with tm.ensure_clean(path) as path:
with open(path, "wb") as f:
f.write(data)
result = parser.read_csv(path)
tm.assert_frame_equal(result, expected)
示例8: get_random_path
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def get_random_path():
return u'__%s__.pickle' % tm.rands(10)
示例9: setup_method
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def setup_method(self, method):
self.path = '__%s__.msg' % tm.rands(10)
示例10: test_rands
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_rands():
r = tm.rands(10)
assert(len(r) == 10)
示例11: test_nonexistent_path
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_nonexistent_path(self):
# gh-2428: pls no segfault
# gh-14086: raise more helpful FileNotFoundError
path = '%s.csv' % tm.rands(10)
pytest.raises(compat.FileNotFoundError, self.read_csv, path)
示例12: test_internal_eof_byte_to_file
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_internal_eof_byte_to_file(self):
# see gh-16559
data = b'c1,c2\r\n"test \x1a test", test\r\n'
expected = pd.DataFrame([["test \x1a test", " test"]],
columns=["c1", "c2"])
path = '__%s__.csv' % tm.rands(10)
with tm.ensure_clean(path) as path:
with open(path, "wb") as f:
f.write(data)
result = self.read_csv(path)
tm.assert_frame_equal(result, expected)
示例13: setUp
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def setUp(self):
from pandas.io.tests.generate_legacy_pickles import create_data
self.data = create_data()
self.path = u('__%s__.pickle' % tm.rands(10))
示例14: setUp
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def setUp(self):
warnings.filterwarnings(action='ignore', category=FutureWarning)
self.path = 'tmp.__%s__.h5' % tm.rands(10)
示例15: test_append_with_diff_col_name_types_raises_value_error
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import rands [as 别名]
def test_append_with_diff_col_name_types_raises_value_error(self):
df = DataFrame(np.random.randn(10, 1))
df2 = DataFrame({'a': np.random.randn(10)})
df3 = DataFrame({(1, 2): np.random.randn(10)})
df4 = DataFrame({('1', 2): np.random.randn(10)})
df5 = DataFrame({('1', 2, object): np.random.randn(10)})
with ensure_clean_store(self.path) as store:
name = 'df_%s' % tm.rands(10)
store.append(name, df)
for d in (df2, df3, df4, df5):
with tm.assertRaises(ValueError):
store.append(name, d)