Skip to content

Commit e5eb840

Browse files
edabortkoyama010pre-commit-ci[bot]user27182
authored
Treat warnings as errors in tests (pyvista#7009)
* Remove depreciation warning ignore and make filter warnings as errors * Fix core tests * Fix camera tests * Fix some plotting tests * Add return_scalar to array_wrap for lut * Remove kwargs Path * Fix typing * Ignore pytest config warning for doc images tests * Fix warnings filter * Fix title offset deprecation * Add ignore warning for plotting tests * Ignore trame warning * Closing gif files * Fix typing * Fix cube axes actor test * Ignore matplotlib legend warning * Add conditional filter warnings for vtk 9.1 and numpy bool deprecation * Fix ignore regex * Fix vtk deprecation * Always print warnings for image regression * Fix last tests * Fix tests * Move warning ignore to configure since emitted during collection * Fix warning syntax * Ignore upstream matplotlib warning * Ignore already catched warning * Change warning type * Enlarge warning * Ignore warning from matplotlib * Change warning filter location for plotting * Add special ignore for 9.1 * Fix segfault for vtk < 9.1 * Change warning location * Fix warning in the docs * Fix docstring * Move image regression filter to pyproject * Add flaky test filter to always * Fix warning filter regex * Update pyvista/plotting/plotter.py Co-authored-by: Tetsuo Koyama <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestion from code review Co-authored-by: user27182 <[email protected]> * Apply suggestion from code review --------- Co-authored-by: Tetsuo Koyama <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: user27182 <[email protected]>
1 parent ee6a417 commit e5eb840

24 files changed

+224
-78
lines changed

pyproject.toml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ test = [
8484
'pytest-pyvista==0.1.8',
8585
'pytest-xdist<3.7.0',
8686
'pytest<8.4.0',
87+
'pytest_cases<3.8.6',
8788
'pytest_mock<3.15.0',
8889
'pyvista[pinned]',
8990
'scipy<1.14.2',
@@ -198,15 +199,19 @@ omit = [
198199

199200
[tool.pytest.ini_options]
200201
doctest_optionflags = 'NUMBER ELLIPSIS'
202+
203+
# Keep spaces between filter warnings since order matters (see https://docs.pytest.org/en/stable/how-to/capture-warnings.html#controlling-warnings)
201204
filterwarnings = [
202-
'error::pyvista.PyVistaDeprecationWarning',
203-
'ignore:.*Given trait value dtype "float64":UserWarning', # bogus numpy ABI warning (see numpy/#432)
204-
'ignore:.*The NumPy module was reloaded*:UserWarning', # bogus numpy ABI warning (see numpy/#432)
205-
'ignore:.*numpy.dtype size changed.*:RuntimeWarning', # bogus numpy ABI warning (see numpy/#432)
206-
'ignore:.*numpy.ufunc size changed.*:RuntimeWarning', # bogus numpy ABI warning (see numpy/#432)
207-
'ignore::DeprecationWarning',
208-
'ignore::FutureWarning',
209-
'ignore::PendingDeprecationWarning',
205+
'error',
206+
207+
'ignore:.*Given trait value dtype "float64":UserWarning', # bogus numpy ABI warning (see numpy/#432)
208+
'ignore:.*The NumPy module was reloaded*:UserWarning', # bogus numpy ABI warning (see numpy/#432)
209+
'ignore:.*numpy.dtype size changed.*:RuntimeWarning', # bogus numpy ABI warning (see numpy/#432)
210+
'ignore:.*numpy.ufunc size changed.*:RuntimeWarning', # bogus numpy ABI warning (see numpy/#432)
211+
'ignore:Passing .{1}N.{1} to ListedColormap is deprecated since:DeprecationWarning', # https://github.com/matplotlib/cmocean/pull/114
212+
'ignore:pyvista test generated image dir.* does not yet exist. Creating dir.:UserWarning',
213+
214+
'always:.*Exceeded image regression warning of .* with an image error of .*:UserWarning',
210215
]
211216
image_cache_dir = 'tests/plotting/image_cache'
212217
junit_family = 'legacy'

pyvista/core/_validation/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ def validate_dimensionality(
12311231
dimensionality_as_array = np.char.replace(dimensionality_as_array, 'D', '')
12321232

12331233
try:
1234-
dimensionality_as_array = dimensionality_as_array.astype(np.integer)
1234+
dimensionality_as_array = dimensionality_as_array.astype(np.int64)
12351235
except ValueError:
12361236
raise ValueError(
12371237
f'`{dimensionality}` is not a valid dimensionality.'

pyvista/core/filters/image_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,7 +2632,7 @@ def label_connectivity(
26322632
26332633
Label only the regions that include seed points, by seed order.
26342634
2635-
>>> points = [(2, 1, 0), (0, 0, 1)]
2635+
>>> points = [(2.0, 1.0, 0.0), (0.0, 0.0, 1.0)]
26362636
>>> connected, labels, sizes = segmented_grid.label_connectivity(
26372637
... scalar_range='foreground',
26382638
... extraction_mode='seeded',

pyvista/core/pointset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,9 @@ def dimensions(self): # numpydoc ignore=RT01
24882488
(20, 10, 4)
24892489
24902490
"""
2491-
return tuple(self.GetDimensions())
2491+
dims = [0, 0, 0]
2492+
self.GetDimensions(dims)
2493+
return tuple(dims)
24922494

24932495
@dimensions.setter
24942496
def dimensions(self, dims) -> None:

pyvista/core/utilities/fileio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def _try_imageio_imread(filename: str | Path) -> imageio.core.util.Array:
12411241
12421242
"""
12431243
try:
1244-
from imageio import imread
1244+
from imageio.v2 import imread
12451245
except ModuleNotFoundError: # pragma: no cover
12461246
raise ModuleNotFoundError(
12471247
'Problem reading the image with VTK. Install imageio to try to read the '

pyvista/core/utilities/reader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,8 @@ def Update(self) -> None:
26222622
if 'frame0' in self._data_object.point_data:
26232623
self._data_object.point_data.active_scalars_name = 'frame0'
26242624

2625+
img.close()
2626+
26252627

26262628
class GIFReader(BaseReader):
26272629
"""GIFReader for .gif files.

pyvista/core/utilities/transform.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ def apply(
15621562
15631563
Apply a transformation to a points array.
15641564
1565-
>>> points = np.array([[1, 2, 3], [4, 5, 6]])
1565+
>>> points = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
15661566
>>> transformed_points = transform.apply(points)
15671567
>>> transformed_points
15681568
array([[ 2., 4., 6.],
@@ -1574,14 +1574,14 @@ def apply(
15741574
>>> transformed_dataset = transform.apply(dataset)
15751575
>>> transformed_dataset.points
15761576
pyvista_ndarray([[ 2., 4., 6.],
1577-
[ 8., 10., 12.]], dtype=float32)
1577+
[ 8., 10., 12.]])
15781578
15791579
Apply the inverse.
15801580
15811581
>>> inverted_dataset = transform.apply(dataset, inverse=True)
15821582
>>> inverted_dataset.points
15831583
pyvista_ndarray([[0.5, 1. , 1.5],
1584-
[2. , 2.5, 3. ]], dtype=float32)
1584+
[2. , 2.5, 3. ]])
15851585
15861586
"""
15871587
inplace = not copy

pyvista/examples/downloads.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# provide helpful message if pooch path is inaccessible
9494
if not Path(USER_DATA_PATH).is_dir(): # pragma: no cover
9595
try:
96-
Path(USER_DATA_PATH, exist_ok=True).mkdir()
96+
Path(USER_DATA_PATH).mkdir(exist_ok=True)
9797
if not os.access(USER_DATA_PATH, os.W_OK):
9898
raise OSError
9999
except (PermissionError, OSError):

pyvista/plotting/axes_assembly.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,8 @@ def __init__(self):
19611961
self.SetUseBounds(False)
19621962

19631963
# Format title positioning
1964-
self.SetTitleOffset(0)
1964+
offset = (0,) if pv.vtk_version_info < (9, 3) else (0, 0)
1965+
self.SetTitleOffset(*offset)
19651966
self.SetLabelOffset(0)
19661967

19671968
# For 2D mode only

pyvista/plotting/cube_axes_actor.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
from __future__ import annotations
44

5+
from collections.abc import MutableSequence
56
from typing import TYPE_CHECKING
67
from typing import cast
8+
import warnings
79

810
import numpy as np
911

@@ -289,12 +291,34 @@ def label_offset(self, offset: float):
289291
self.SetLabelOffset(offset)
290292

291293
@property
292-
def title_offset(self) -> float: # numpydoc ignore=RT01
294+
def title_offset(self) -> float | tuple[float, float]: # numpydoc ignore=RT01
293295
"""Return or set the distance between title and labels."""
296+
if pyvista.vtk_version_info >= (9, 3):
297+
offx, offy = (_vtk.reference(0.0), _vtk.reference(0.0))
298+
self.GetTitleOffset(offx, offy) # type: ignore[call-overload]
299+
return offx, offy # type: ignore[return-value]
300+
294301
return self.GetTitleOffset()
295302

296303
@title_offset.setter
297-
def title_offset(self, offset: float):
304+
def title_offset(self, offset: float | MutableSequence[float]):
305+
vtk_geq_9_3 = pyvista.vtk_version_info >= (9, 3)
306+
307+
if vtk_geq_9_3:
308+
if isinstance(offset, float):
309+
msg = f'Setting title_offset with a float is deprecated from vtk >= 9.3. Accepts now a sequence of (x,y) offsets. Setting the x offset to {(x:=0.0)}'
310+
warnings.warn(msg, UserWarning)
311+
self.SetTitleOffset([x, offset])
312+
else:
313+
self.SetTitleOffset(offset)
314+
return
315+
316+
if isinstance(offset, MutableSequence):
317+
msg = f'Setting title_offset with a sequence is only supported from vtk >= 9.3. Considering only the second value (ie. y-offset) of {(y:=offset[1])}'
318+
warnings.warn(msg, UserWarning)
319+
self.SetTitleOffset(y)
320+
return
321+
298322
self.SetTitleOffset(offset)
299323

300324
@property

0 commit comments

Comments
 (0)