尝试set在 python 中做一个简单的差异,并获得表明差异运算符什么都不做的结果。例如。有代码
蟒蛇版本 2.7.15+
assert isinstance(left_frame, h2o.H2OFrame)
assert isinstance(right_frame, h2o.H2OFrame)
assert isinstance(left_key, str)
assert isinstance(right_key, str)
# ensure that the primary_key exists in both frames
assert left_key in left_frame.columns, 'left_key: {} does not exist in left_frame'.format(left_key)
assert right_key in right_frame.columns, 'right_key: {} does not exist in right_frame'.format(right_key)
# ensure that the primary_key is the only common column between the left and right frame
left_non_pk_cols = set(left_frame.columns) - set(left_key)
assert left_on not in left_non_pk_cols, '%s' % left_key
right_non_pk_cols = set(right_frame.columns) - set(right_key)
assert right_on not in right_non_pk_cols, '%s' % right_key
left_non_pk_cols_in_right = left_non_pk_cols.intersection(right_non_pk_cols)
assert len(left_non_pk_cols_in_right) == 0,\
'The primary_key is not the only common column between frames, h2o merge will not work as expected\n%s\n%s\n%s' \
% (left_non_pk_cols, right_non_pk_cols, left_non_pk_cols_in_right)
我得到错误
assert left_key not in left_non_pk_cols, '%s' % left_key
AssertionError: <the left_key value>
这对我来说真的很奇怪。在终端(具有相同的 python 版本)中运行一个简化的示例案例
assert u'1' not in (set([u'1', u'2', u'3']) - set(u'1'))
# noting that the H2OFrames `.columns` field is a list of unicode strings
根本不抛出任何错误并按预期完成(打印结果时set,一切看起来都应该(无u'1'元素))。
使用.difference()方法而不是-运算符也不会产生任何差异。
有谁知道这里会发生什么或做其他事情来获取更多调试信息?