def test_time(): fns = ["collagen", dust(), spectra20nea(), "peach_juice.dpt"] for fn in fns: print(fn) data = Table(fn) print(data.X.shape) data[0, 2] = np.nan t = time.time() interpolated = Interpolate(getx(data), handle_nans=False)(data) print("no nan", time.time() - t) t = time.time() intp = Interpolate(getx(data), handle_nans=True) intp.interpfn = interp1d_with_unknowns_numpy interpolated = intp(data) print("nan handling with numpy", time.time() - t) intp.interpfn = interp1d_with_unknowns_scipy interpolated = intp(data) print("nan handling with scipy", time.time() - t) assert (not np.any(np.isnan(interpolated.X)))
def test_unknown_elsewhere_different(self): data = Orange.data.Table("iris") data.X[0, 1] = np.nan data.X[1, 1] = np.nan data.X[1, 2] = np.nan im = Interpolate(getx(data)) im.interpfn = interp1d_with_unknowns_numpy interpolated = im(data) self.assertAlmostEqual(interpolated.X[0, 1], 3.25) self.assertAlmostEqual(interpolated.X[1, 1], 3.333333333333334) self.assertAlmostEqual(interpolated.X[1, 2], 1.766666666666667) self.assertFalse(np.any(np.isnan(interpolated.X))) im.interpfn = interp1d_with_unknowns_scipy interpolated = im(data) self.assertAlmostEqual(interpolated.X[0, 1], 3.25) self.assertAlmostEqual(interpolated.X[1, 1], 3.333333333333334) self.assertAlmostEqual(interpolated.X[1, 2], 1.766666666666667) self.assertFalse(np.any(np.isnan(interpolated.X))) save_X = interpolated.X im.interpfn = interp1d_wo_unknowns_scipy interpolated = im(data) self.assertTrue(np.any(np.isnan(interpolated.X))) # parts without unknown should be the same np.testing.assert_almost_equal(data.X[2:], save_X[2:])