本文整理汇总了Python中pandas.util.testing.makeCustomIndex方法的典型用法代码示例。如果您正苦于以下问题:Python testing.makeCustomIndex方法的具体用法?Python testing.makeCustomIndex怎么用?Python testing.makeCustomIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.makeCustomIndex方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_join_on_fails_with_different_right_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_right_index(self):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
msg = (r'len\(left_on\) must equal the number of levels in the index'
' of "right"')
with pytest.raises(ValueError, match=msg):
merge(df, df2, left_on='a', right_index=True)
示例2: test_join_on_fails_with_different_left_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_left_index(self):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)},
index=tm.makeCustomIndex(3, 2))
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)})
msg = (r'len\(right_on\) must equal the number of levels in the index'
' of "left"')
with pytest.raises(ValueError, match=msg):
merge(df, df2, right_on='b', left_index=True)
示例3: test_join_on_fails_with_different_column_counts
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_column_counts(self):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
msg = r"len\(right_on\) must equal len\(left_on\)"
with pytest.raises(ValueError, match=msg):
merge(df, df2, right_on='a', left_on=['a', 'b'])
示例4: test_raise_on_panel_with_multiindex
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_raise_on_panel_with_multiindex(self, parser, engine):
p = tm.makePanel(7)
p.items = tm.makeCustomIndex(len(p.items), nlevels=2)
with pytest.raises(NotImplementedError):
pd.eval('p + 1', parser=parser, engine=engine)
示例5: test_fails_on_no_datetime_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_fails_on_no_datetime_index(self):
index_names = ('Int64Index', 'Index', 'Float64Index', 'MultiIndex')
index_funcs = (tm.makeIntIndex,
tm.makeUnicodeIndex, tm.makeFloatIndex,
lambda m: tm.makeCustomIndex(m, 2))
n = 2
for name, func in zip(index_names, index_funcs):
index = func(n)
df = DataFrame({'a': np.random.randn(n)}, index=index)
with tm.assert_raises_regex(TypeError,
"Only valid with "
"DatetimeIndex, TimedeltaIndex "
"or PeriodIndex, but got an "
"instance of %r" % name):
df.groupby(TimeGrouper('D'))
示例6: test_join_on_fails_with_different_right_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_right_index(self):
with pytest.raises(ValueError):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
merge(df, df2, left_on='a', right_index=True)
示例7: test_join_on_fails_with_different_left_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_left_index(self):
with pytest.raises(ValueError):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)},
index=tm.makeCustomIndex(10, 2))
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)})
merge(df, df2, right_on='b', left_index=True)
示例8: test_join_on_fails_with_different_column_counts
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_column_counts(self):
with pytest.raises(ValueError):
df = DataFrame({'a': np.random.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': np.random.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
merge(df, df2, right_on='a', left_on=['a', 'b'])
示例9: test_fails_on_no_datetime_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_fails_on_no_datetime_index(self):
index_names = ('Int64Index', 'PeriodIndex', 'Index', 'Float64Index',
'MultiIndex')
index_funcs = (tm.makeIntIndex, tm.makePeriodIndex,
tm.makeUnicodeIndex, tm.makeFloatIndex,
lambda m: tm.makeCustomIndex(m, 2))
n = 2
for name, func in zip(index_names, index_funcs):
index = func(n)
df = DataFrame({'a': np.random.randn(n)}, index=index)
with tm.assertRaisesRegexp(TypeError,
"axis must be a DatetimeIndex, "
"but got an instance of %r" % name):
df.groupby(TimeGrouper('D'))
示例10: test_join_on_fails_with_different_right_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_right_index(self):
with tm.assertRaises(ValueError):
df = DataFrame({'a': tm.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': tm.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
merge(df, df2, left_on='a', right_index=True)
示例11: test_join_on_fails_with_different_left_index
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_left_index(self):
with tm.assertRaises(ValueError):
df = DataFrame({'a': tm.choice(['m', 'f'], size=3),
'b': np.random.randn(3)},
index=tm.makeCustomIndex(10, 2))
df2 = DataFrame({'a': tm.choice(['m', 'f'], size=10),
'b': np.random.randn(10)})
merge(df, df2, right_on='b', left_index=True)
示例12: test_join_on_fails_with_different_column_counts
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_join_on_fails_with_different_column_counts(self):
with tm.assertRaises(ValueError):
df = DataFrame({'a': tm.choice(['m', 'f'], size=3),
'b': np.random.randn(3)})
df2 = DataFrame({'a': tm.choice(['m', 'f'], size=10),
'b': np.random.randn(10)},
index=tm.makeCustomIndex(10, 2))
merge(df, df2, right_on='a', left_on=['a', 'b'])
示例13: test_raise_on_panel_with_multiindex
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import makeCustomIndex [as 别名]
def test_raise_on_panel_with_multiindex(self, parser, engine):
tm.skip_if_no_ne()
p = tm.makePanel(7)
p.items = tm.makeCustomIndex(len(p.items), nlevels=2)
with pytest.raises(NotImplementedError):
pd.eval('p + 1', parser=parser, engine=engine)