WIP: cleanup conventions.encode_cf_variable

Almost ready, except for failing tests on Python 3.