general design policy: returning nan or raising exception in corner cases

9 views
Skip to first unread message

josef...@gmail.com

unread,
Mar 2, 2018, 11:07:46 AM3/2/18
to pystatsmodels
https://github.com/statsmodels/statsmodels/issues/4282#issuecomment-369957965

Should we return nan or raise an exception in corner cases that "don't make sense".

An example is when the sample size is too small to compute the relevant statistics, other cases are corner cases like zero variance.

We never spelled out a general policy for those cases, but discussion in individual issues where this showed up where usually in favor of returning nans.

This is a bit again related to library versus interactive usage. Most of the time in library usage we don't want that our program or loops to stop, while in interactive work we can immediately investigate an exception.

In scipy.stats, AFAIR:
If there missing value handling with vectorized computation, the return is nan in those cases because other parts will still be valid.
Several hypothesis tests and statistics raise if the sample size is too small.
(As a result, in statsmodels we catch, try--except, some of those cases because we want a nan, e.g. in summary, and not an exception.)

Statsmodels is still missing explicit handling of corner cases in most functions, i.e. the outcome depends on what happens on the usual code path. To change this is work, we need to identify the cases and add unit tests for whatever outcome should happen in those cases.


Josef



Reply all
Reply to author
Forward
0 new messages