From 447d0d94edb06f2e798241fbf9a0199b82f2ae0e Mon Sep 17 00:00:00 2001 From: SeqIO Team Date: Mon, 20 Nov 2023 17:15:14 -0800 Subject: [PATCH] Include the case of new key not being in the old mapping. PiperOrigin-RevId: 584167785 --- seqio/preprocessors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/seqio/preprocessors.py b/seqio/preprocessors.py index 19b133be..4dc923b0 100644 --- a/seqio/preprocessors.py +++ b/seqio/preprocessors.py @@ -36,8 +36,8 @@ def rekey(x, key_map=None): examples with the format {'boo': 'something', 'spar': 'something else'} - If a mapping is to an empty key name or None, the new value is set to an empty - string. + If a mapping is to an empty key name or None or it does not exist in the given + mapping x, the new value is set to an empty string. Args: x: an example to process. @@ -48,7 +48,7 @@ def rekey(x, key_map=None): """ if key_map: return { - new_key: x[old_key] if old_key else '' + new_key: x[old_key] if (old_key and old_key in x) else '' for new_key, old_key in key_map.items() } return x