作为单元测试的一部分,我尝试比较两个Cashflow
对象,它们只包含一个Series
在单元测试中,我有以下内容,其中cashflowobj_1
和cashflowobj_2
是包含Series
的Cashflow
对象:
self.assert_(cashflowobj_1==cashflowobj_2)
这两个系列看起来与下面看到的完全相同,但是测试返回Series are not equal
,所以我想知道我用来检查它们相等性的函数中是否有问题cashflowobj_1.amounts
和cashflowobj_2.amounts
分别是Series
:
cashflowobj_1.amounts
:
1983-05-15 1
1983-11-15 1
1984-05-15 1
1984-11-15 101
cashflowobj_2.amounts
:
1983-05-15 1
1983-11-15 1
1984-05-15 1
1984-11-15 101
用于检查Cashflow
对象是否相等的函数,该函数位于Cashflow
类中:
def __eq__(self, other):
'''
Series being equal
'''
if ((len(self.amounts) == len(other.amounts))) and ((all(i in self.amounts for i in other.amounts))):
print('Series are equal')
return(1)
else:
print('Series are not equal')
return(0)
编辑:解决@matt的问题:索引都是datetime.date()
对象。值为float64
你不是只想看看级数是否相等吗?假设你说的是熊猫系列
使用Series.equals()函数
相关问题 更多 >
编程相关推荐