Note that the function I used doesn't return the first most frequent but the lowest most frequent to be consistent with scipy. When scipy will be fixed, the tests won't pass and we will need to change the code to be consistent with the new behaviour of scipyt.stats.mode. I'll add a comment about this in the test.