Skip to content

Commit

Permalink
Show proper location of UnitStrippedWarning
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marscher authored Dec 2, 2019
1 parent e6ae929 commit 2f2c88b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pint/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2f2c88b

Please sign in to comment.