[Numpy-svn] r5821 - in trunk/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Sat Sep 13 13:05:02 CDT 2008


Author: alan.mcintyre
Date: 2008-09-13 13:04:57 -0500 (Sat, 13 Sep 2008)
New Revision: 5821

Modified:
   trunk/numpy/ma/bench.py
   trunk/numpy/ma/core.py
   trunk/numpy/ma/mrecords.py
   trunk/numpy/ma/tests/test_mrecords.py
   trunk/numpy/ma/testutils.py
   trunk/numpy/ma/timer_comparison.py
Log:
Removed unused imports.
Standardize NumPy import as "import numpy as np".


Modified: trunk/numpy/ma/bench.py
===================================================================
--- trunk/numpy/ma/bench.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/bench.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -6,9 +6,9 @@
 #ip = IPython.ipapi.get()
 #from IPython import ipmagic
 import numpy
-from numpy import ma
-from numpy.ma import filled
-from numpy.ma.testutils import assert_equal
+#from numpy import ma
+#from numpy.ma import filled
+#from numpy.ma.testutils import assert_equal
 
 
 #####---------------------------------------------------------------------------

Modified: trunk/numpy/ma/core.py
===================================================================
--- trunk/numpy/ma/core.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/core.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -57,17 +57,14 @@
            'var', 'where',
            'zeros']
 
-import sys
-import types
 import cPickle
 import operator
 
 import numpy as np
-from numpy import ndarray, typecodes, amax, amin, iscomplexobj,\
-    bool_, complex_, float_, int_, object_, str_
+from numpy import ndarray, amax, amin, iscomplexobj, bool_, complex_, float_,\
+                  int_, object_
 from numpy import array as narray
 
-
 import numpy.core.umath as umath
 import numpy.core.numerictypes as ntypes
 from numpy import expand_dims as n_expand_dims

Modified: trunk/numpy/ma/mrecords.py
===================================================================
--- trunk/numpy/ma/mrecords.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/mrecords.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -16,23 +16,21 @@
 __author__ = "Pierre GF Gerard-Marchant"
 
 import sys
-import types
 
 import numpy as np
-from numpy import bool_, complex_, float_, int_, str_, object_, dtype, \
-    chararray, ndarray, recarray, record, array as narray
+from numpy import bool_, dtype, \
+    ndarray, recarray, array as narray
 import numpy.core.numerictypes as ntypes
-from numpy.core.records import find_duplicate, format_parser
 from numpy.core.records import fromarrays as recfromarrays, \
-    fromrecords as recfromrecords
+                               fromrecords as recfromrecords
 
 _byteorderconv = np.core.records._byteorderconv
 _typestr = ntypes._typestr
 
 import numpy.ma as ma
 from numpy.ma import MAError, MaskedArray, masked, nomask, masked_array,\
-    make_mask, mask_or, getdata, getmask, getmaskarray, filled, \
-    default_fill_value, masked_print_option
+                     getdata, getmaskarray, filled
+
 _check_fill_value = ma.core._check_fill_value
 
 import warnings

Modified: trunk/numpy/ma/tests/test_mrecords.py
===================================================================
--- trunk/numpy/ma/tests/test_mrecords.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/tests/test_mrecords.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -8,23 +8,19 @@
 __revision__ = "$Revision: 3473 $"
 __date__     = '$Date: 2007-10-29 17:18:13 +0200 (Mon, 29 Oct 2007) $'
 
-import types
-
 import numpy as np
 from numpy import recarray
 from numpy.core.records import fromrecords as recfromrecords, \
-    fromarrays as recfromarrays
+                               fromarrays as recfromarrays
 
 import numpy.ma.testutils
 from numpy.ma.testutils import *
 
 import numpy.ma as ma
-from numpy.ma import masked, nomask, getdata, getmaskarray
+from numpy.ma import masked, nomask
 
-import numpy.ma.mrecords
-reload(numpy.ma.mrecords)
-from numpy.ma.mrecords import MaskedRecords, mrecarray,\
-    fromarrays, fromtextfile, fromrecords, addfield
+from numpy.ma.mrecords import MaskedRecords, mrecarray, fromarrays, \
+                              fromtextfile, fromrecords, addfield
 
 #..............................................................................
 class TestMRecords(TestCase):
@@ -432,7 +428,6 @@
 'strings',4,-1e-10,,,1
 """
         import os
-        from datetime import datetime
         import tempfile
         (tmp_fd,tmp_fl) = tempfile.mkstemp()
         os.write(tmp_fd, fcontent)

Modified: trunk/numpy/ma/testutils.py
===================================================================
--- trunk/numpy/ma/testutils.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/testutils.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -16,12 +16,10 @@
 from numpy import ndarray, float_
 import numpy.core.umath as umath
 from numpy.testing import *
-from numpy.testing.utils import build_err_msg, rand
 import numpy.testing.utils as utils
 
-import core
-from core import mask_or, getmask, getmaskarray, masked_array, nomask, masked
-from core import fix_invalid, filled, equal, less
+from core import mask_or, getmask, masked_array, nomask, masked, filled, \
+                 equal, less
 
 #------------------------------------------------------------------------------
 def approx (a, b, fill_value=True, rtol=1.e-5, atol=1.e-8):

Modified: trunk/numpy/ma/timer_comparison.py
===================================================================
--- trunk/numpy/ma/timer_comparison.py	2008-09-13 08:09:02 UTC (rev 5820)
+++ trunk/numpy/ma/timer_comparison.py	2008-09-13 18:04:57 UTC (rev 5821)
@@ -1,17 +1,15 @@
-
 import timeit
 
-import numpy
-from numpy import int_, float_, bool_
-import numpy.core.fromnumeric as fromnumeric
+import numpy as np
+from numpy import float_
+import np.core.fromnumeric as fromnumeric
 
-from numpy.testing.utils import build_err_msg, rand
+from np.testing.utils import build_err_msg
 
+np.seterr(all='ignore')
 
-numpy.seterr(all='ignore')
+pi = np.pi
 
-pi = numpy.pi
-
 class moduletester:
     #-----------------------------------
     def __init__(self, module):
@@ -61,15 +59,15 @@
         y = self.filled(self.masked_array(yf, mask=m), fill_value)
         if (x.dtype.char != "O"):
             x = x.astype(float_)
-            if isinstance(x, numpy.ndarray) and x.size > 1:
-                x[numpy.isnan(x)] = 0
-            elif numpy.isnan(x):
+            if isinstance(x, np.ndarray) and x.size > 1:
+                x[np.isnan(x)] = 0
+            elif np.isnan(x):
                 x = 0
         if (y.dtype.char != "O"):
             y = y.astype(float_)
-            if isinstance(y, numpy.ndarray) and y.size > 1:
-                y[numpy.isnan(y)] = 0
-            elif numpy.isnan(y):
+            if isinstance(y, np.ndarray) and y.size > 1:
+                y[np.isnan(y)] = 0
+            elif np.isnan(y):
                 y = 0
         try:
             cond = (x.shape==() or y.shape==()) or x.shape == y.shape
@@ -110,23 +108,23 @@
     #----------------------------------
     def test_0(self):
         "Tests creation"
-        x = numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
+        x = np.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
         m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
         xm = self.masked_array(x, mask=m)
         xm[0]
     #----------------------------------
     def test_1(self):
         "Tests creation"
-        x = numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
-        y = numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
+        x = np.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
+        y = np.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
         a10 = 10.
         m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
         m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]
         xm = self.masked_array(x, mask=m1)
         ym = self.masked_array(y, mask=m2)
-        z = numpy.array([-.5, 0., .5, .8])
+        z = np.array([-.5, 0., .5, .8])
         zm = self.masked_array(z, mask=[0,1,0,0])
-        xf = numpy.where(m1, 1.e+20, x)
+        xf = np.where(m1, 1.e+20, x)
         xm.set_fill_value(1.e+20)
         #.....
         assert((xm-ym).filled(0).any())
@@ -146,13 +144,13 @@
     #----------------------------------
     def test_2(self):
         "Tests conversions and indexing"
-        x1 = numpy.array([1,2,4,3])
+        x1 = np.array([1,2,4,3])
         x2 = self.array(x1, mask=[1,0,0,0])
         x3 = self.array(x1, mask=[0,1,0,1])
         x4 = self.array(x1)
     # test conversion to strings
         junk, garbage = str(x2), repr(x2)
-#        assert_equal(numpy.sort(x1), self.sort(x2, fill_value=0))
+#        assert_equal(np.sort(x1), self.sort(x2, fill_value=0))
     # tests of indexing
         assert type(x2[1]) is type(x1[1])
         assert x1[1] == x2[1]
@@ -178,12 +176,12 @@
         x4[:] = self.masked_array([1,2,3,4],[0,1,1,0])
 #        assert self.allequal(self.getmask(x4), self.array([0,1,1,0]))
 #        assert self.allequal(x4, self.array([1,2,3,4]))
-        x1 = numpy.arange(5)*1.0
+        x1 = np.arange(5)*1.0
         x2 = self.masked_values(x1, 3.0)
 #        assert self.allequal(x1,x2)
 #        assert self.allequal(self.array([0,0,0,1,0], self.MaskType), x2.mask)
         x1 = self.array([1,'hello',2,3],object)
-        x2 = numpy.array([1,'hello',2,3],object)
+        x2 = np.array([1,'hello',2,3],object)
         s1 = x1[1]
         s2 = x2[1]
         assert x1[1:1].shape == (0,)
@@ -216,15 +214,15 @@
     def test_4(self):
         "Test of take, transpose, inner, outer products"
         x = self.arange(24)
-        y = numpy.arange(24)
+        y = np.arange(24)
         x[5:6] = self.masked
         x = x.reshape(2,3,4)
         y = y.reshape(2,3,4)
-        assert self.allequal(numpy.transpose(y,(2,0,1)), self.transpose(x,(2,0,1)))
-        assert self.allequal(numpy.take(y, (2,0,1), 1), self.take(x, (2,0,1), 1))
-        assert self.allequal(numpy.inner(self.filled(x,0), self.filled(y,0)),
+        assert self.allequal(np.transpose(y,(2,0,1)), self.transpose(x,(2,0,1)))
+        assert self.allequal(np.take(y, (2,0,1), 1), self.take(x, (2,0,1), 1))
+        assert self.allequal(np.inner(self.filled(x,0), self.filled(y,0)),
                             self.inner(x, y))
-        assert self.allequal(numpy.outer(self.filled(x,0), self.filled(y,0)),
+        assert self.allequal(np.outer(self.filled(x,0), self.filled(y,0)),
                             self.outer(x, y))
         y = self.array(['abc', 1, 'def', 2, 3], object)
         y[2] = self.masked
@@ -396,8 +394,8 @@
         self.assert_array_equal(self.average(x, axis=0), 2.5)
         self.assert_array_equal(self.average(x, axis=0, weights=w1), 2.5)
         y = self.array([self.arange(6), 2.0*self.arange(6)])
-        self.assert_array_equal(self.average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.)
-        self.assert_array_equal(self.average(y, axis=0), numpy.arange(6) * 3./2.)
+        self.assert_array_equal(self.average(y, None), np.add.reduce(np.arange(6))*3./12.)
+        self.assert_array_equal(self.average(y, axis=0), np.arange(6) * 3./2.)
         self.assert_array_equal(self.average(y, axis=1), [self.average(x,axis=0), self.average(x,axis=0) * 2.0])
         self.assert_array_equal(self.average(y, None, weights=w2), 20./6.)
         self.assert_array_equal(self.average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.])
@@ -420,7 +418,7 @@
     #------------------------
     def test_A(self):
         x = self.arange(24)
-        y = numpy.arange(24)
+        y = np.arange(24)
         x[5:6] = self.masked
         x = x.reshape(2,3,4)
 
@@ -431,10 +429,10 @@
     setup_base = "from __main__ import moduletester \n"\
                  "import numpy\n" \
                  "tester = moduletester(module)\n"
-#    setup_new = "import numpy.ma.core_ini as module\n"+setup_base
-    setup_cur = "import numpy.ma.core as module\n"+setup_base
-#    setup_alt = "import numpy.ma.core_alt as module\n"+setup_base
-#    setup_tmp = "import numpy.ma.core_tmp as module\n"+setup_base
+#    setup_new = "import np.ma.core_ini as module\n"+setup_base
+    setup_cur = "import np.ma.core as module\n"+setup_base
+#    setup_alt = "import np.ma.core_alt as module\n"+setup_base
+#    setup_tmp = "import np.ma.core_tmp as module\n"+setup_base
 
     (nrepeat, nloop) = (10, 10)
 
@@ -445,10 +443,10 @@
             cur = timeit.Timer(func, setup_cur).repeat(nrepeat, nloop*10)
 #            alt = timeit.Timer(func, setup_alt).repeat(nrepeat, nloop*10)
 #            tmp = timeit.Timer(func, setup_tmp).repeat(nrepeat, nloop*10)
-#            new = numpy.sort(new)
-            cur = numpy.sort(cur)
-#            alt = numpy.sort(alt)
-#            tmp = numpy.sort(tmp)
+#            new = np.sort(new)
+            cur = np.sort(cur)
+#            alt = np.sort(alt)
+#            tmp = np.sort(tmp)
             print "#%i" % i +50*'.'
             print eval("moduletester.test_%i.__doc__" % i)
 #            print "core_ini     : %.3f - %.3f" % (new[0], new[1])



More information about the Numpy-svn mailing list