本文整理汇总了Python中pandas.util.testing.equalContents方法的典型用法代码示例。如果您正苦于以下问题:Python testing.equalContents方法的具体用法?Python testing.equalContents怎么用?Python testing.equalContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas.util.testing
的用法示例。
在下文中一共展示了testing.equalContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_difference_name_preservation
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_difference_name_preservation(self, second_name, expected, sort):
# TODO: replace with fixturesult
first = self.strIndex[5:20]
second = self.strIndex[:10]
answer = self.strIndex[10:20]
first.name = 'name'
second.name = second_name
result = first.difference(second, sort=sort)
assert tm.equalContents(result, answer)
if expected is None:
assert result.name is None
else:
assert result.name == expected
示例2: test_symmetric_difference
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_symmetric_difference(self, sort):
# smoke
index1 = Index([5, 2, 3, 4], name='index1')
index2 = Index([2, 3, 4, 1])
result = index1.symmetric_difference(index2, sort=sort)
expected = Index([5, 1])
assert tm.equalContents(result, expected)
assert result.name is None
if sort is None:
expected = expected.sort_values()
tm.assert_index_equal(result, expected)
# __xor__ syntax
expected = index1 ^ index2
assert tm.equalContents(result, expected)
assert result.name is None
示例3: test_intersection2
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_intersection2(self):
first = tm.makeDateIndex(10)
second = first[5:]
intersect = first.intersection(second)
assert tm.equalContents(intersect, second)
# GH 10149
cases = [klass(second.values) for klass in [np.array, Series, list]]
for case in cases:
result = first.intersection(case)
assert tm.equalContents(result, second)
third = Index(['a', 'b', 'c'])
result = first.intersection(third)
expected = pd.Index([], dtype=object)
tm.assert_index_equal(result, expected)
示例4: test_symmetric_difference
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_symmetric_difference(self, closed, sort):
index = self.create_index(closed=closed)
result = index[1:].symmetric_difference(index[:-1], sort=sort)
expected = IntervalIndex([index[0], index[-1]])
if sort is None:
tm.assert_index_equal(result, expected)
assert tm.equalContents(result, expected)
# GH 19101: empty result, same dtype
result = index.symmetric_difference(index, sort=sort)
expected = IntervalIndex(np.array([], dtype='int64'), closed=closed)
if sort is None:
tm.assert_index_equal(result, expected)
assert tm.equalContents(result, expected)
# GH 19101: empty result, different dtypes
other = IntervalIndex.from_arrays(index.left.astype('float64'),
index.right, closed=closed)
result = index.symmetric_difference(other, sort=sort)
tm.assert_index_equal(result, expected)
示例5: test_intersection
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_intersection(self, sort):
index = period_range('1/1/2000', '1/20/2000', freq='D')
result = index[:-5].intersection(index[10:], sort=sort)
tm.assert_index_equal(result, index[10:-5])
# not in order
left = _permute(index[:-5])
right = _permute(index[10:])
result = left.intersection(right, sort=sort)
if sort is None:
tm.assert_index_equal(result, index[10:-5])
assert tm.equalContents(result, index[10:-5])
# raise if different frequencies
index = period_range('1/1/2000', '1/20/2000', freq='D')
index2 = period_range('1/1/2000', '1/20/2000', freq='W-WED')
with pytest.raises(period.IncompatibleFrequency):
index.intersection(index2, sort=sort)
index3 = period_range('1/1/2000', '1/20/2000', freq='2D')
with pytest.raises(period.IncompatibleFrequency):
index.intersection(index3, sort=sort)
示例6: test_intersection_base
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_intersection_base(idx, sort):
first = idx[:5]
second = idx[:3]
intersect = first.intersection(second, sort=sort)
if sort is None:
tm.assert_index_equal(intersect, second.sort_values())
assert tm.equalContents(intersect, second)
# GH 10149
cases = [klass(second.values)
for klass in [np.array, Series, list]]
for case in cases:
result = first.intersection(case, sort=sort)
if sort is None:
tm.assert_index_equal(result, second.sort_values())
assert tm.equalContents(result, second)
msg = "other must be a MultiIndex or a list of tuples"
with pytest.raises(TypeError, match=msg):
first.intersection([1, 2, 3], sort=sort)
示例7: test_union_base
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_union_base(idx, sort):
first = idx[3:]
second = idx[:5]
everything = idx
union = first.union(second, sort=sort)
if sort is None:
tm.assert_index_equal(union, everything.sort_values())
assert tm.equalContents(union, everything)
# GH 10149
cases = [klass(second.values)
for klass in [np.array, Series, list]]
for case in cases:
result = first.union(case, sort=sort)
if sort is None:
tm.assert_index_equal(result, everything.sort_values())
assert tm.equalContents(result, everything)
msg = "other must be a MultiIndex or a list of tuples"
with pytest.raises(TypeError, match=msg):
first.union([1, 2, 3], sort=sort)
示例8: test_intersection
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_intersection(idx, sort):
piece1 = idx[:5][::-1]
piece2 = idx[3:]
the_int = piece1.intersection(piece2, sort=sort)
if sort is None:
tm.assert_index_equal(the_int, idx[3:5])
assert tm.equalContents(the_int, idx[3:5])
# corner case, pass self
the_int = idx.intersection(idx, sort=sort)
assert the_int is idx
# empty intersection: disjoint
empty = idx[:2].intersection(idx[2:], sort=sort)
expected = idx[:0]
assert empty.equals(expected)
# can't do in python 3
# tuples = _index.values
# result = _index & tuples
# assert result.equals(tuples)
示例9: test_difference_name_preservation
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_difference_name_preservation(self, second_name, expected):
# TODO: replace with fixturesult
first = self.strIndex[5:20]
second = self.strIndex[:10]
answer = self.strIndex[10:20]
first.name = 'name'
second.name = second_name
result = first.difference(second)
assert tm.equalContents(result, answer)
if expected is None:
assert result.name is None
else:
assert result.name == expected
示例10: test_slice
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_slice(test_data):
numSlice = test_data.series[10:20]
numSliceEnd = test_data.series[-10:]
objSlice = test_data.objSeries[10:20]
assert test_data.series.index[9] not in numSlice.index
assert test_data.objSeries.index[9] not in objSlice.index
assert len(numSlice) == len(numSlice.index)
assert test_data.series[numSlice.index[0]] == numSlice[numSlice.index[0]]
assert numSlice.index[1] == test_data.series.index[11]
assert tm.equalContents(numSliceEnd, np.array(test_data.series)[-10:])
# Test return view.
sl = test_data.series[10:20]
sl[:] = 0
assert (test_data.series[10:20] == 0).all()
示例11: test_timedelta
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_timedelta(self):
# this is valid too
index = date_range('1/1/2000', periods=50, freq='B')
shifted = index + timedelta(1)
back = shifted + timedelta(-1)
self.assert_(tm.equalContents(index, back))
self.assertEqual(shifted.freq, index.freq)
self.assertEqual(shifted.freq, back.freq)
result = index - timedelta(1)
expected = index + timedelta(-1)
self.assert_(result.equals(expected))
# GH4134, buggy with timedeltas
rng = date_range('2013', '2014')
s = Series(rng)
result1 = rng - pd.offsets.Hour(1)
result2 = DatetimeIndex(s - np.timedelta64(100000000))
result3 = rng - np.timedelta64(100000000)
result4 = DatetimeIndex(s - pd.offsets.Hour(1))
self.assert_(result1.equals(result4))
self.assert_(result2.equals(result3))
示例12: test_iter
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_iter(self):
tm.equalContents(list(self.panel), self.panel.items)
示例13: test_keys
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_keys(self):
tm.equalContents(list(self.panel.keys()), self.panel.items)
示例14: test_intersection
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_intersection(self, sort):
first = self.strIndex[:20]
second = self.strIndex[:10]
intersect = first.intersection(second, sort=sort)
if sort is None:
tm.assert_index_equal(intersect, second.sort_values())
assert tm.equalContents(intersect, second)
# Corner cases
inter = first.intersection(first, sort=sort)
assert inter is first
示例15: test_union
# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import equalContents [as 别名]
def test_union(self, sort):
# TODO: Replace with fixturesult
first = self.strIndex[5:20]
second = self.strIndex[:10]
everything = self.strIndex[:20]
union = first.union(second, sort=sort)
if sort is None:
tm.assert_index_equal(union, everything.sort_values())
assert tm.equalContents(union, everything)