Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ENH: add useful repr's for finfo, iinfo.
  • Loading branch information
brentp authored and rgommers committed Aug 18, 2011
1 parent 4386275 commit 00962c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions numpy/core/getlimits.py
Expand Up @@ -180,6 +180,14 @@ def __str__(self):
---------------------------------------------------------------------
''' % 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):
"""
Expand Down Expand Up @@ -280,6 +288,9 @@ def __str__(self):
---------------------------------------------------------------------
''' % {'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)
Expand Down
9 changes: 9 additions & 0 deletions numpy/core/tests/test_getlimits.py
Expand Up @@ -55,6 +55,15 @@ def test_unsigned_max(self):
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)
Expand Down

0 comments on commit 00962c4

Please sign in to comment.