summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorBrent Pedersen <bpederse@gmail.com>2011-08-16 16:41:48 -0600
committerRalf Gommers <ralf.gommers@googlemail.com>2011-08-18 09:06:21 +0200
commit00962c4b845ec461e38850f8ae17253a4eecabf2 (patch)
tree1040ab5f2dbcb5f4045c5be4613fa7e7e8fb6915 /numpy
parent43862759384a86cb4a95e8adb4d39fa1522acb28 (diff)
downloadnumpy-00962c4b845ec461e38850f8ae17253a4eecabf2.tar.gz
ENH: add useful repr's for finfo, iinfo.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/getlimits.py11
-rw-r--r--numpy/core/tests/test_getlimits.py9
2 files changed, 20 insertions, 0 deletions
diff --git a/numpy/core/getlimits.py b/numpy/core/getlimits.py
index 0cb1fd7f4..4754975e2 100644
--- a/numpy/core/getlimits.py
+++ b/numpy/core/getlimits.py
@@ -180,6 +180,14 @@ nexp =%(nexp)6s min= -max
---------------------------------------------------------------------
''' % self.__dict__
+ def __repr__(self):
+ c = self.__class__.__name__
+ d = self.__dict__.copy()
+ d['klass'] = c
+ return ("%(klass)s(resolution=%(resolution)s, min=-%(_str_max)s," \
+ + " max=%(_str_max)s, dtype=%(dtype)s)") \
+ % d
+
class iinfo(object):
"""
@@ -280,6 +288,9 @@ max = %(max)s
---------------------------------------------------------------------
''' % {'dtype': self.dtype, 'min': self.min, 'max': self.max}
+ def __repr__(self):
+ return "%s(min=%s, max=%s, dtype=%s)" % (self.__class__.__name__,
+ self.min, self.max, self.dtype)
if __name__ == '__main__':
f = finfo(ntypes.single)
diff --git a/numpy/core/tests/test_getlimits.py b/numpy/core/tests/test_getlimits.py
index 569dc0cc6..3570fd718 100644
--- a/numpy/core/tests/test_getlimits.py
+++ b/numpy/core/tests/test_getlimits.py
@@ -55,6 +55,15 @@ class TestIinfo(TestCase):
for T in types:
assert_equal(iinfo(T).max, T(-1))
+class TestRepr(TestCase):
+ def test_iinfo_repr(self):
+ expected = "iinfo(min=-32768, max=32767, dtype=int16)"
+ assert_equal(repr(np.iinfo(np.int16)), expected)
+
+ def test_finfo_repr(self):
+ expected = "finfo(resolution=1e-06, min=-3.4028235e+38," + \
+ " max=3.4028235e+38, dtype=float32)"
+ assert_equal(repr(np.finfo(np.float32)), expected)
def test_instances():
iinfo(10)