From 0e673f5411d3b5fadfa32301245117edc1d1a485 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Mon, 9 Jul 2018 13:06:29 +0200 Subject: [PATCH] removed copy method, added nicer repr, test repr --- iminuit/_libiminuit.pyx | 24 +++++++++++------------- iminuit/tests/test_iminuit.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/iminuit/_libiminuit.pyx b/iminuit/_libiminuit.pyx index dcfea9e12..671cafff0 100644 --- a/iminuit/_libiminuit.pyx +++ b/iminuit/_libiminuit.pyx @@ -134,14 +134,11 @@ cdef class BasicView: cdef int i = key if isinstance(key, (int, long)) else self._minuit.var2pos[key] self._set(i, value) - def copy(self): - return dict(self) - - def __str__(self): - s = "%s{" % self.__class__.__name__ - items = [" '{0}'={1}".format(k, v) for (k, v) in self.items()] - s += ",\n".join(items) - s += "\n}" + def __repr__(self): + s = "<%s of Minuit at %x>" % (self.__class__.__name__, id(self._minuit)) + for (k, v) in self.items(): + s += "\n {0}: {1}".format(k, v) + s += "\n" return s @@ -166,11 +163,12 @@ cdef class ArgsView: raise IndexError self._state.SetValue(i, value) - def copy(self): - return tuple(self) - - def __str__(self): - return 'ArgsView[' + ', '.join(str(x) for x in self) + ']' + def __repr__(self): + s = "" % id(self._minuit) + for v in self: + s += "\n {0}".format(v) + s += "\n" + return s cdef class ValueView(BasicView): diff --git a/iminuit/tests/test_iminuit.py b/iminuit/tests/test_iminuit.py index 258abb160..cb2a3c86b 100644 --- a/iminuit/tests/test_iminuit.py +++ b/iminuit/tests/test_iminuit.py @@ -235,6 +235,20 @@ def test_from_array_func_with_broadcasting(): assert_allclose(np.diag(c), (1, 1)) +def test_view_repr(): + m = Minuit(func3, print_level=0, errordef=1, + x=1, y=2, error_x=3, error_y=4) + mid = id(m) + assert repr(m.values) == """ + x: 1.0 + y: 2.0 +""" % mid + assert repr(m.args) == """ + 1.0 + 2.0 +""" % mid + + def test_no_resume(): m = Minuit(func3, print_level=0, pedantic=False) m.migrad()