Stacklevel for warnings.

Hi All, Do we have a policy for the stacklevel that should be used in NumPy? How far back should the stack be displayed? I note that the optimum stacklevel may vary between users and developers. Chuck

On Fri, 2018-08-10 at 16:05 -0600, Charles R Harris wrote:
I thought it was so that it will point to the correct user line (or tend to point there). So stacklevel=2 for exposed and higher for private (python) functions IIRC. As for developers, I would hope they are OK with (and know how to) turning the warning into an error. Not sure we discussed it much, I seem to have a vague memory of asking if we are sure this is what we want and at least Ralf agreeing. Also I don't know how consistent it is overall. - Sebastian

On Sat, Aug 11, 2018 at 1:22 AM, Sebastian Berg <sebastian@sipsolutions.net> wrote:
That sounds right to me. I think when it was introduced it was quite consistent, because Sebastian replace warning filters everywhere with suppress_warnings. Would be good to document this in the devguide. Ralf

On Sat, 2018-08-11 at 11:11 -0700, Ralf Gommers wrote:
Yeah, probably reasonably consistent, but I only added a test to check that the stacklevel argument is never missing entirely, it is up to the author to figure out what is the right level (or best easily possible, since sometimes it would be pretty ugly to make it always right). The warning testing (suppress_warnings, etc.) or any of our tests never actually check the stacklevel that I am aware of, or maybe I forgot :), could be something to think about though. I guess we did it around the same time of the general warning testing cleanup probably. - Sebastian

On Fri, 2018-08-10 at 16:05 -0600, Charles R Harris wrote:
I thought it was so that it will point to the correct user line (or tend to point there). So stacklevel=2 for exposed and higher for private (python) functions IIRC. As for developers, I would hope they are OK with (and know how to) turning the warning into an error. Not sure we discussed it much, I seem to have a vague memory of asking if we are sure this is what we want and at least Ralf agreeing. Also I don't know how consistent it is overall. - Sebastian

On Sat, Aug 11, 2018 at 1:22 AM, Sebastian Berg <sebastian@sipsolutions.net> wrote:
That sounds right to me. I think when it was introduced it was quite consistent, because Sebastian replace warning filters everywhere with suppress_warnings. Would be good to document this in the devguide. Ralf

On Sat, 2018-08-11 at 11:11 -0700, Ralf Gommers wrote:
Yeah, probably reasonably consistent, but I only added a test to check that the stacklevel argument is never missing entirely, it is up to the author to figure out what is the right level (or best easily possible, since sometimes it would be pretty ugly to make it always right). The warning testing (suppress_warnings, etc.) or any of our tests never actually check the stacklevel that I am aware of, or maybe I forgot :), could be something to think about though. I guess we did it around the same time of the general warning testing cleanup probably. - Sebastian
participants (3)
-
Charles R Harris
-
Ralf Gommers
-
Sebastian Berg