Fix issue 2482, test failures in spatial and stats

Added some cleanups in test_stats.py