Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacklevel to warnings #309

Merged
merged 4 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions discretize/_extensions/tree_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ cdef class _TreeMesh:
>>> import discretize
>>> import matplotlib.pyplot as plt
>>> import matplotlib.patches as patches
>>> tree_mesh = discretize.TreeMesh([32, 32, 32])
>>> tree_mesh.max_level
>>> mesh = discretize.TreeMesh([32, 32, 32])
>>> mesh.max_level
5

Next we define the bottom points of the prism, its heights, and the level we
Expand Down
1 change: 1 addition & 0 deletions discretize/base/base_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def save(self, file_name="mesh.json", verbose=False, **kwargs):
"The filename keyword argument has been deprecated, please use file_name. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
f = os.path.abspath(file_name) # make sure we are working with abs path
with open(f, "w") as outfile:
Expand Down
15 changes: 15 additions & 0 deletions discretize/base/base_regular_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def axis_u(self):
"The axis_u property is deprecated, please access as self.orientation[0]. "
"This will be removed in discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
return self.orientation[0]

Expand All @@ -539,6 +540,7 @@ def axis_u(self, value):
"directly set the self.orientation property. This will be removed in "
"discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
self.orientation[0] = value

Expand All @@ -554,6 +556,7 @@ def axis_v(self):
"The axis_v property is deprecated, please access as self.orientation[1]. "
"This will be removed in discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
return self.orientation[1]

Expand All @@ -564,6 +567,7 @@ def axis_v(self, value):
"directly set the self.orientation property. This will be removed in "
"discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
value = value / np.linalg.norm(value)
self.orientation[1] = value
Expand All @@ -580,6 +584,7 @@ def axis_w(self):
"The axis_w property is deprecated, please access as self.orientation[2]. "
"This will be removed in discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
return self.orientation[2]

Expand All @@ -590,6 +595,7 @@ def axis_w(self, value):
"directly set the self.orientation property. This will be removed in "
"discretize 1.0.0.",
FutureWarning,
stacklevel=2,
)
value = value / np.linalg.norm(value)
self.orientation[2] = value
Expand Down Expand Up @@ -872,20 +878,23 @@ def reshape(
"The xType keyword argument has been deprecated, please use x_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
x_type = kwargs["xType"]
if "outType" in kwargs:
warnings.warn(
"The outType keyword argument has been deprecated, please use out_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
out_type = kwargs["outType"]
if "format" in kwargs:
warnings.warn(
"The format keyword argument has been deprecated, please use return_format. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
return_format = kwargs["format"]

Expand Down Expand Up @@ -1039,6 +1048,7 @@ def nCx(self):
warnings.warn(
"nCx has been deprecated, please access as mesh.shape_cells[0]",
FutureWarning,
stacklevel=2,
)
return self.shape_cells[0]

Expand All @@ -1058,6 +1068,7 @@ def nCy(self):
warnings.warn(
"nCy has been deprecated, please access as mesh.shape_cells[1]",
FutureWarning,
stacklevel=2,
)
if self.dim < 2:
return None
Expand All @@ -1079,6 +1090,7 @@ def nCz(self):
warnings.warn(
"nCz has been deprecated, please access as mesh.shape_cells[2]",
FutureWarning,
stacklevel=2,
)
if self.dim < 3:
return None
Expand All @@ -1099,6 +1111,7 @@ def nNx(self):
warnings.warn(
"nNx has been deprecated, please access as mesh.shape_nodes[0]",
FutureWarning,
stacklevel=2,
)
return self.shape_nodes[0]

Expand All @@ -1118,6 +1131,7 @@ def nNy(self):
warnings.warn(
"nNy has been deprecated, please access as mesh.shape_nodes[1]",
FutureWarning,
stacklevel=2,
)
if self.dim < 2:
return None
Expand All @@ -1139,6 +1153,7 @@ def nNz(self):
warnings.warn(
"nNz has been deprecated, please access as mesh.shape_nodes[2]",
FutureWarning,
stacklevel=2,
)
if self.dim < 3:
return None
Expand Down
16 changes: 13 additions & 3 deletions discretize/base/base_tensor_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ def is_inside(self, pts, location_type="nodes", **kwargs):
"The locType keyword argument has been deprecated, please use location_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type = kwargs["locType"]
pts = as_array_n_by_dim(pts, self.dim)
Expand Down Expand Up @@ -783,13 +784,15 @@ def get_interpolation_matrix( # NOQA D102
"The locType keyword argument has been deprecated, please use location_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type = kwargs["locType"]
if "zerosOutside" in kwargs:
warnings.warn(
"The zerosOutside keyword argument has been deprecated, please use zeros_outside. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
zeros_outside = kwargs["zerosOutside"]
return self._getInterpolationMat(loc, location_type, zeros_outside)
Expand Down Expand Up @@ -993,6 +996,7 @@ def innerProductDeriv(v=None):
" You should be supplying a vector. "
"Use: sdiag(u)*dMdprop",
FutureWarning,
stacklevel=2,
)
return dMdprop
return sdiag(v) * dMdprop
Expand All @@ -1015,7 +1019,9 @@ def hx(self):
please use `mesh.h[0]`.
"""
warnings.warn(
"hx has been deprecated, please access as mesh.h[0]", FutureWarning
"hx has been deprecated, please access as mesh.h[0]",
FutureWarning,
stacklevel=2,
)
return self.h[0]

Expand All @@ -1032,7 +1038,9 @@ def hy(self):
please use `mesh.h[1]`.
"""
warnings.warn(
"hy has been deprecated, please access as mesh.h[1]", FutureWarning
"hy has been deprecated, please access as mesh.h[1]",
FutureWarning,
stacklevel=2,
)
return None if self.dim < 2 else self.h[1]

Expand All @@ -1049,7 +1057,9 @@ def hz(self):
please use `mesh.h[2]`.
"""
warnings.warn(
"hz has been deprecated, please access as mesh.h[2]", FutureWarning
"hz has been deprecated, please access as mesh.h[2]",
FutureWarning,
stacklevel=2,
)
return None if self.dim < 3 else self.h[2]

Expand Down
5 changes: 5 additions & 0 deletions discretize/cylindrical_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1680,13 +1680,15 @@ def get_interpolation_matrix(
"The locType keyword argument has been deprecated, please use location_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type = kwargs["locType"]
if "zerosOutside" in kwargs:
warnings.warn(
"The zerosOutside keyword argument has been deprecated, please use zeros_outside. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
zeros_outside = kwargs["zerosOutside"]

Expand Down Expand Up @@ -1879,6 +1881,7 @@ def cartesian_grid(self, location_type="cell_centers", theta_shift=None, **kwarg
"The locType keyword argument has been deprecated, please use location_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type = kwargs["locType"]
try:
Expand Down Expand Up @@ -1923,13 +1926,15 @@ def get_interpolation_matrix_cartesian_mesh(
"The locType keyword argument has been deprecated, please use location_type. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type = kwargs["locType"]
if "locTypeTo" in kwargs:
warnings.warn(
"The locTypeTo keyword argument has been deprecated, please use location_type_to. "
"This will be removed in discretize 1.0.0",
FutureWarning,
stacklevel=2,
)
location_type_to = kwargs["locTypeTo"]

Expand Down
2 changes: 2 additions & 0 deletions discretize/mixins/mesh_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def readUBC(TensorMesh, file_name, directory=""):
"TensorMesh.readUBC has been deprecated and will be removed in"
"discretize 1.0.0. please use TensorMesh.read_UBC",
FutureWarning,
stacklevel=2,
)
return TensorMesh.read_UBC(file_name, directory)

Expand Down Expand Up @@ -615,6 +616,7 @@ def readUBC(TreeMesh, file_name, directory=""):
"TensorMesh.readUBC has been deprecated and will be removed in"
"discretize 1.0.0. please use TensorMesh.read_UBC",
FutureWarning,
stacklevel=2,
)
return TreeMesh.read_UBC(file_name, directory)

Expand Down
Loading