Example #1
0
    def test_inconsistent_dtype(self):
        "Test inconsistent dtype"
        data = ["1, 1, 1, 1, -1.1"] * 50
        mdata = StringIO("\n".join(data))

        converters = {4: lambda x:"(%s)" % x}
        kwargs = dict(delimiter=",", converters=converters,
                      dtype=[(_, int) for _ in 'abcde'],)
        assert_raises(ValueError, np.genfromtxt, mdata, **kwargs)
Example #2
0
 def test_invalid_converter(self):
     strip_rand = lambda x : float((asbytes('r') in x.lower() and x.split()[-1]) or
                                   (not asbytes('r') in x.lower() and x.strip() or 0.0))
     strip_per = lambda x : float((asbytes('%') in x.lower() and x.split()[0]) or
                                  (not asbytes('%') in x.lower() and x.strip() or 0.0))
     s = StringIO("D01N01,10/1/2003 ,1 %,R 75,400,600\r\n" \
                           "L24U05,12/5/2003, 2 %,1,300, 150.5\r\n"
                           "D02N03,10/10/2004,R 1,,7,145.55")
     kwargs = dict(converters={2 : strip_per, 3 : strip_rand}, delimiter=",",
                   dtype=None)
     assert_raises(ConverterError, np.genfromtxt, s, **kwargs)
Example #3
0
    def test_vs_nonmasked(self):
        x = np.array((-2, -1, 0, 1, 2, 3) * 4) ** 2
        assert_array_almost_equal(mstats.normaltest(x), stats.normaltest(x))
        assert_array_almost_equal(mstats.skewtest(x), stats.skewtest(x))
        assert_array_almost_equal(mstats.kurtosistest(x), stats.kurtosistest(x))

        funcs = [stats.normaltest, stats.skewtest, stats.kurtosistest]
        mfuncs = [mstats.normaltest, mstats.skewtest, mstats.kurtosistest]
        x = [1, 2, 3, 4]
        for func, mfunc in zip(funcs, mfuncs):
            assert_raises(ValueError, func, x)
            assert_raises(ValueError, mfunc, x)
Example #4
0
    def test_skip_footer_with_invalid(self):
        import warnings
        basestr = '1 1\n2 2\n3 3\n4 4\n5  \n6  \n7  \n'
        warnings.filterwarnings("ignore")
        # Footer too small to get rid of all invalid values 
        assert_raises(ValueError, np.genfromtxt,
                      StringIO(basestr), skip_footer=1)
#        except ValueError:
#            pass
        a = np.genfromtxt(StringIO(basestr), skip_footer=1, invalid_raise=False)
        assert_equal(a, np.array([[1., 1.], [2., 2.], [3., 3.], [4., 4.]]))
        #
        a = np.genfromtxt(StringIO(basestr), skip_footer=3)
        assert_equal(a, np.array([[1., 1.], [2., 2.], [3., 3.], [4., 4.]]))
        #
        basestr = '1 1\n2  \n3 3\n4 4\n5  \n6 6\n7 7\n'
        a = np.genfromtxt(StringIO(basestr), skip_footer=1, invalid_raise=False)
        assert_equal(a, np.array([[1., 1.], [3., 3.], [4., 4.], [6., 6.]]))
        a = np.genfromtxt(StringIO(basestr), skip_footer=3, invalid_raise=False)
        assert_equal(a, np.array([[1., 1.], [3., 3.], [4., 4.]]))
        warnings.resetwarnings()
Example #5
0
 def test_invalid_raise(self):
     "Test invalid raise"
     data = ["1, 1, 1, 1, 1"] * 50
     for i in range(5):
         data[10 * i] = "2, 2, 2, 2 2"
     data.insert(0, "a, b, c, d, e")
     mdata = StringIO("\n".join(data))
     #
     kwargs = dict(delimiter=",", dtype=None, names=True)
     # XXX: is there a better way to get the return value of the callable in
     # assert_warns ?
     ret = {}
     def f(_ret={}):
         _ret['mtest'] = np.ndfromtxt(mdata, invalid_raise=False, **kwargs)
     assert_warns(ConversionWarning, f, _ret=ret)
     mtest = ret['mtest']
     assert_equal(len(mtest), 45)
     assert_equal(mtest, np.ones(45, dtype=[(_, int) for _ in 'abcde']))
     #
     mdata.seek(0)
     assert_raises(ValueError, np.ndfromtxt, mdata,
                   delimiter=",", names=True)
Example #6
0
 def test_invalid_input_size(self):
     assert_raises(ValueError, mstats.ttest_rel,
                   np.arange(10), np.arange(11))
     x = np.arange(24)
     assert_raises(ValueError, mstats.ttest_rel,
                   x.reshape(2, 3, 4), x.reshape(2, 4, 3), axis=1)
     assert_raises(ValueError, mstats.ttest_rel,
                   x.reshape(2, 3, 4), x.reshape(2, 4, 3), axis=2)
Example #7
0
 def test_matrix_builder(self):
     assert_raises(np.ma.MAError, lambda: mr_['1, 2; 3, 4'])
Example #8
0
 def test_empty_file(self):
     "Test that an empty file raises the proper exception"
     data = StringIO()
     assert_raises(IOError, np.ndfromtxt, data)
Example #9
0
 def test_empty_file(self):
     c = StringIO()
     assert_raises(IOError, np.loadtxt, c)