petl-developers/petl

Is the behavior of multi-field convert-with-row contractual?

chrullrich opened this issue · 1 comments

petl.transform.conversions.convert() supports converting multiple fields in one call, and supports passing the whole row to the conversion function. It (currently) performs the conversions such that I can (in the simplest case) use a single convert() call to exchange two values because the second conversion function sees the original state of the row, not the result of the first conversion:

>>> import petl
>>> t = petl.io.base.fromcolumns([[0], [1]], header=['a','b'])
>>> t
+---+---+
| a | b |
+===+===+
| 0 | 1 |
+---+---+

>>> mapp = {"a": lambda a, row: row.b, "b": lambda b, row: row.a}
>>> t.convert(mapp, pass_row=True)
+---+---+
| a | b |
+===+===+
| 1 | 0 |
+---+---+

If the second conversion saw the result of the first one, both fields would be equal.

This is not spelled out in the documentation. Can I rely on this behavior, at least to the point that it would be mentioned in release notes if it ever changed?

It would be interesting to clarify the desired behavior and add a test case for assuring that future changes don't break it.