Skip to content

Commit

Permalink
ENH(py): Increase warning stacklevels for tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSWang committed Sep 19, 2024
1 parent afeebca commit a5211d5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/triumvirate/_arrayops.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ def extrap_loglin_oscil(a, n_ext):
if len(a) < 8:
warnings.warn(
"Array length is less than 8. Extrapolation may not be accurate.",
UserWarning
UserWarning,
stacklevel=3,
)

# Check for sign changes and restrict extrapolation to a range
Expand Down Expand Up @@ -407,7 +408,8 @@ def extrap_loglin_oscil(a, n_ext):
warnings.warn(
"Divergent behaviour detected at the left tail. "
"Constant padding is used instead.",
DivergenceWarning
DivergenceWarning,
stacklevel=3,
)
# print("Left tail extrap: trend -> const")
# No oscillations
Expand Down Expand Up @@ -435,7 +437,8 @@ def extrap_loglin_oscil(a, n_ext):
warnings.warn(
"Divergent behaviour detected at the left endpoints. "
"Constant padding is used instead.",
DivergenceWarning
DivergenceWarning,
stacklevel=3,
)
# print("Left tail extrap: endpoint -> const")

Expand All @@ -449,7 +452,8 @@ def extrap_loglin_oscil(a, n_ext):
warnings.warn(
"Divergent behaviour detected at the right tail. "
"Constant padding is used instead.",
DivergenceWarning
DivergenceWarning,
stacklevel=3,
)
# print("Right tail extrap: trend -> const")
else:
Expand All @@ -472,7 +476,8 @@ def extrap_loglin_oscil(a, n_ext):
warnings.warn(
"Divergent behaviour detected at the right endpoints. "
"Constant padding is used instead.",
DivergenceWarning
DivergenceWarning,
stacklevel=3,
)
# print("Right tail extrap: endpoint -> const")

Expand Down
3 changes: 2 additions & 1 deletion src/triumvirate/threept.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def _amalgamate_parameters(paramset=None, params_sampling=None,
warnings.warn(
"The following parameter default values "
f"are unchanged: {defaults}. "
"Not all parameters are necessarily used."
"Not all parameters are necessarily used.",
stacklevel=3,
)

return paramset
Expand Down
3 changes: 2 additions & 1 deletion src/triumvirate/twopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def _amalgamate_parameters(paramset=None, params_sampling=None,
warnings.warn(
"The following parameter default values "
f"are unchanged: {defaults}. "
"Not all parameters are necessarily used."
"Not all parameters are necessarily used.",
stacklevel=3,
)

return paramset
Expand Down
9 changes: 6 additions & 3 deletions src/triumvirate/winconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ def __init__(self, multipole_Q, multipole_Z, coeff):
if coeff == 0:
warnings.warn(
"Coefficient of window convolution term is zero.",
RuntimeWarning
RuntimeWarning,
stacklevel=4,
)
self.coeff = coeff

Expand Down Expand Up @@ -1739,7 +1740,8 @@ def initialise_sampts(self, r_in, r_out=None, enforce_coverage=False):
"fully covered by the window function "
"separation sample points. "
"Inaccurate extrapolation may occur. " + msg,
category=ConvolutionRangeWarning
category=ConvolutionRangeWarning,
stacklevel=2,
)
if (
term.multipole_Z not in WinConvTerm._SPEC_INDICES
Expand All @@ -1764,7 +1766,8 @@ def initialise_sampts(self, r_in, r_out=None, enforce_coverage=False):
"fully covered by the input CF "
"separation sample points. "
"Inaccurate extrapolation may occur. " + msg,
category=ConvolutionRangeWarning
category=ConvolutionRangeWarning,
stacklevel=2,
)


Expand Down

0 comments on commit a5211d5

Please sign in to comment.