Notes supporting issue #256.
import petl.interactive as etl
t1 = etl.wrap([['foo', 'bar'], [1, 'a'], [2, 'b']])
t1
foo | bar |
---|---|
1 | a |
2 | b |
t2 = etl.wrap([['foo', 'bar'], [1, 'a'], [2, 'c']])
t2
foo | bar |
---|---|
1 | a |
2 | c |
t3 = etl.merge(t1, t2, key='foo')
t3
foo | bar |
---|---|
1 | a |
2 | Conflict(['c', 'b']) |
The problem with the above is that you cannot tell from inspecting t3 alone which conflicting value comes from which source.
A workaround as suggested by @pawl is to use the conflicts() function, e.g.:
t4 = (etl
.cat(
t1.addfield('source', 1),
t2.addfield('source', 2)
)
.conflicts(key='foo', exclude='source')
)
t4
foo | bar | source |
---|---|---|
2 | b | 1 |
2 | c | 2 |