-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG + 1] Fix repr on isotropic kernels when a 1-D length scale is given #7259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Shouldn't we test all |
return "{0}(length_scale={1:.3g}, nu={2:.3g})".format( | ||
self.__class__.__name__, self.length_scale, self.nu) | ||
self.__class__.__name__, _squeeze(self.length_scale), self.nu) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reimplemented np.squeeze
because .format
does not play well with a 0-D array.
a = "{0:0.3g}".format(np.array(2))
TypeError: non-empty format string passed to object.__format__
a = "%0.3g" % np.array(2)
a
'2'
Probably should be reported to NumPy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.ravel(length_scale)[0]
or np.atleast_1d(length_scale)[0]
should also work. I think the helper function is a bit obscure to the reader.
For now, I've just added a smoke test. Is that sufficient or should we test if stuff like "length_scale" is there in the string returned by repr? Also ping @jnothman |
lgtm |
I prefer |
Thanks |
What does this implement/fix? Explain your changes.
Moving setting the
length_scale
logic from the constructor to the methods broke__repr__
on a 1-D length_scale isotropic kernel.This was because the formatting expected
self.length_scale
to be a scalar while theself.length_scale
to be an array. To fix this, I squeeze the 1-D length_scale by squeezing it when__repr__
is called.