From 2f2c88b385250fdb31580bd559a7697d7bcb319c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Mon, 2 Dec 2019 17:14:55 +0100 Subject: [PATCH] Show proper location of UnitStrippedWarning Users are interested where in their code they triggered the warning and not the original underlying implementation throwing the warning. By setting the stacklevel accordingly, users see the line of their code, which strips the warning. --- pint/quantity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pint/quantity.py b/pint/quantity.py index 7428cab4c..f093d08db 100644 --- a/pint/quantity.py +++ b/pint/quantity.py @@ -1452,7 +1452,7 @@ def __getattr__(self, item): # Attributes starting with `__array_` are common attributes of NumPy ndarray. # They are requested by numpy functions. if item.startswith('__array_'): - warnings.warn("The unit of the quantity is stripped.", UnitStrippedWarning) + warnings.warn("The unit of the quantity is stripped.", UnitStrippedWarning, stacklevel=2) if isinstance(self._magnitude, ndarray): return getattr(self._magnitude, item) else: