`n % 1 != 0` is not a valid test for float: In []: 1.1 % 1 == 0 Out[]: False but: In []: 1.0 % 1 == 0 Out[]: True hence it's really necessary to explicitly test for type in this case.