tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
233 stars 17 forks source link

None as Returntype leads to error #269

Open antonykamp opened 5 years ago

antonykamp commented 5 years ago

Hey,

working on the conversion of the tests (#268), I got test failures because of the functions variance and stdev.

Because variance is returning a NoneType object, the function stdev can't pull the root. There is a try-except block already, so the only thing to do is adding 'TypeError'. Maybe the numpy dev changed the exception from AttributeError. to TypeError.

If that's so simple, I would do this with #268.

Grüße

tBuLi commented 5 years ago

Interesting, that does sound like something was changed upstream. Perhaps we could also consider changing it to something like:

if variance is not None: 
    return np.sqrt(variance)
else:
    return None

To prevent this problem from reoccurring. I wouldn't mind if you made this small change already in #268, since it does not affect the tests themselves.

Herzliche Grüße

antonykamp commented 5 years ago

Hey, the small change doesn't affect the results, but your solution is a quite more elegant one than mine :D I'm going to change this quickly.

pckroon commented 5 years ago

return variance and np.sqrt(variance) should also work (iff variance != 0), but you do lose some interpretability.

try:
    return np.sqrt(variance)
except (TypeError, AttributeError):
    return None

would be the more elegant try/except version.

antonykamp commented 5 years ago

I had this for the first time, but the solution by @tBuLi was more readable for me.