icecream
icecream copied to clipboard
ic have compatible issues with numpy poly
code to reproduce:
x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0,])
y = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0,])
curve = np.polyfit(x, y, 2)
poly = np.poly1d(curve)
# show curve
ic(poly)
print(poly)
The problem is that ic(poly) only show a array, while print shows the whole formula, like this:
I don't think that is actually a compatible issue for icecream.
I think you are printing curve
instead of poly
using ic
in the picture since the name that you are running with icecream is "curve" instead of "poly".
The problem with ic(poly)
:
I also noticed that ic(poly)
is print different output from print(poly)
.
Here is the my input:
And here are the local variables' value in the debugger:
The value for
poly
is actually poly1d([-0.17482517, 1.74825175, -0.34965035])
.
If we go further with the debugger on the line ic(poly)
, the debugger shows that:
It shows that icecream takes the value of poly as its input argument, and printing that as its output. I believe icecream is doing its job well. The fact that
ic(poly)
and print(poly)
print different outputs might be related to numpy.poly1d has some overload function with print()
, while it does not have any with icecream.
I will do some further research about numpy.poly1d to see whether this can be fixed or not! Hope it is useful!
The 'problem' is that print uses the str() function to get the string, whereas icecream uses the repr() function. So, if you want the 'nice' version of poly, just do
ic(str(poly))
With output
ic| str(poly): ' 2
-0.1748 x + 1.748 x - 0.3497'
The only disadvantage is that it shows str(poly) as the variable name and not just poly.