These are very clunky and confusing, the tests should be compressed with property based testing and the logic clearer. Using pandas tables of numpy array would also help in the lookup table