Skip to content

Commit

Permalink
Merge #907
Browse files Browse the repository at this point in the history
907: [Quantity] Show proper location of UnitStrippedWarning r=hgrecco a=marscher

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.

Co-authored-by: Martin K. Scherer <marscher@users.noreply.github.com>
  • Loading branch information
bors[bot] and marscher authored Dec 2, 2019
2 parents e6ae929 + 2f2c88b commit cf05eb8
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 cf05eb8

Please sign in to comment.