我想使用<ul>
<li>
<h3>h3<br>h3<br>h3</h3>
<h3>h3</h3>
<h3>h3</h3>
</li>
<li>
<h4>h4</h4>
<h4>h4</h4>
<h4>h4</h4>
</li>
<li>
<p>p</p>
<p>p</p>
<p>p<br>p</p>
</li>
</ul>
模块检查两个pandas.Series
对象是否具有相同的内容:
unittest
根据 self.assertSequenceEqual(
df['some_column'],
someOtherSeries)
文档,上述内容应该有效(基于the docs)。但是,当我运行上面的单元测试时,我得到了这个:
unittest
如何测试系列是否相同?
请注意,将系列转换为======================================================================
ERROR: test_my_test (my_module.test.test_my_module.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/src/my_module/my_module/test/test_my_test.py", line 28, in test_my_test
someOtherSeries)
File "/usr/local/lib/python2.7/unittest/case.py", line 663, in assertSequenceEqual
if seq1 == seq2:
File "/usr/local/lib/python2.7/site-packages/pandas/core/generic.py", line 917, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
对象似乎可以解决这个问题,但感觉就像是黑客攻击:
list
答案 0 :(得分:3)
请注意,df['some_column'].values
是numpy
数组。要测试 numpy
数组的等值(等价),您可以使用numpy.testing
:
from numpy import testing
testing.assert_array_equal(df['some_column'].values, someOtherSeries.values)
如果数组是浮点数,则应考虑numpy.testing.assert_almost_equal
testing.assert_almost_equal(df['some_column'].values, someOtherSeries.values)
直接等同浮点数是有问题的。