[Numpy-svn] r6323 - in trunk/numpy/lib: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Jan 14 02:56:31 EST 2009


Author: stefan
Date: 2009-01-14 01:56:10 -0600 (Wed, 14 Jan 2009)
New Revision: 6323

Modified:
   trunk/numpy/lib/getlimits.py
   trunk/numpy/lib/tests/test_getlimits.py
Log:
Fix finfo to work on all instances, not just NumPy scalars.

Modified: trunk/numpy/lib/getlimits.py
===================================================================
--- trunk/numpy/lib/getlimits.py	2009-01-14 07:55:16 UTC (rev 6322)
+++ trunk/numpy/lib/getlimits.py	2009-01-14 07:56:10 UTC (rev 6323)
@@ -88,6 +88,12 @@
     _finfo_cache = {}
 
     def __new__(cls, dtype):
+        try:
+            dtype = np.dtype(dtype)
+        except TypeError:
+            # In case a float instance was given
+            dtype = np.dtype(type(dtype))
+
         obj = cls._finfo_cache.get(dtype,None)
         if obj is not None:
             return obj
@@ -220,8 +226,11 @@
     _min_vals = {}
     _max_vals = {}
 
-    def __init__(self, type):
-        self.dtype = np.dtype(type)
+    def __init__(self, int_type):
+        try:
+            self.dtype = np.dtype(int_type)
+        except TypeError:
+            self.dtype = np.dtype(type(int_type))
         self.kind = self.dtype.kind
         self.bits = self.dtype.itemsize * 8
         self.key = "%s%d" % (self.kind, self.bits)
@@ -258,7 +267,7 @@
 
     def __str__(self):
         """String representation."""
-        return '''
+        return '''\
 Machine parameters for %(dtype)s
 ---------------------------------------------------------------------
 min = %(min)s

Modified: trunk/numpy/lib/tests/test_getlimits.py
===================================================================
--- trunk/numpy/lib/tests/test_getlimits.py	2009-01-14 07:55:16 UTC (rev 6322)
+++ trunk/numpy/lib/tests/test_getlimits.py	2009-01-14 07:56:10 UTC (rev 6323)
@@ -51,5 +51,9 @@
             assert_equal(iinfo(T).max, T(-1))
 
 
+def test_instances():
+    iinfo(10)
+    finfo(3.0)
+
 if __name__ == "__main__":
     run_module_suite()




More information about the Numpy-svn mailing list