Skip to content

Commit

Permalink
Remove deprecations from pointset (pyvista#4439)
Browse files Browse the repository at this point in the history
* remove CallableBool

* remove number_of_faces

* remove internal use of CallableBool
  • Loading branch information
MatthewFlamm authored May 22, 2023
1 parent ae6a914 commit b112597
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 63 deletions.
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@
(r'py:.*', '.*ColorLike'),
(r'py:.*', '.*lookup_table_ndarray'),
(r'py:.*', 'ActiveArrayInfo'),
(r'py:.*', 'CallableBool'),
(r'py:.*', 'FieldAssociation'),
(r'py:.*', 'VTK'),
(r'py:.*', 'colors.Colormap'),
Expand Down
65 changes: 6 additions & 59 deletions pyvista/core/pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pathlib
from textwrap import dedent
from typing import Sequence, Tuple, Union
import warnings

import numpy as np

Expand All @@ -20,7 +19,6 @@
from .celltype import CellType
from .dataset import DataSet
from .errors import (
DeprecationError,
PointSetCellOperationError,
PointSetDimensionReductionError,
PointSetNotSupported,
Expand Down Expand Up @@ -849,24 +847,12 @@ def strips(self, strips):
def is_all_triangles(self):
"""Return if all the faces of the :class:`pyvista.PolyData` are triangles.
.. versionchanged:: 0.32.0
``is_all_triangles`` is now a property. Calling this value
will warn the user that this should not be called.
Additionally, the ``is`` operator will not work the return
value of this property since it is not a ``bool``
Returns
-------
CallableBool
bool
``True`` if all the faces of the :class:`pyvista.PolyData`
are triangles and does not contain any vertices or lines.
Notes
-----
The return value is not a ``bool`` for compatibility
reasons, though this behavior will change in a future
release. Future versions will simply return a ``bool``.
Examples
--------
Show a mesh from :func:`pyvista.Plane` is not composed of all
Expand All @@ -875,60 +861,26 @@ def is_all_triangles(self):
>>> import pyvista
>>> plane = pyvista.Plane()
>>> plane.is_all_triangles
False <CallableBool>
False
Show that the mesh from :func:`pyvista.Sphere` contains only
triangles.
>>> sphere = pyvista.Sphere()
>>> sphere.is_all_triangles
True <CallableBool>
True
"""

class CallableBool(int): # pragma: no cover
"""Boolean that can be called.
Programmer note: We must subclass int and not bool
https://stackoverflow.com/questions/2172189/why-i-cant-extend-bool-in-python
Implemented for backwards compatibility as
``is_all_triangles`` was changed to be a property in
``0.32.0``.
"""

def __new__(cls, value):
"""Use new instead of __init__.
See:
https://jfine-python-classes.readthedocs.io/en/latest/subclass-int.html#emulating-bool-using-new
"""
return int.__new__(cls, bool(value))

def __call__(self):
"""Return a ``bool`` of self."""
warnings.warn(
'``is_all_triangles`` is now property as of 0.32.0 and does not need ()',
DeprecationWarning,
)
return bool(self)

def __repr__(self):
"""Return the string of bool."""
return f'{bool(self)} <CallableBool>'

# Need to make sure there are only face cells and no lines/verts
if not self.n_faces or self.n_lines or self.n_verts:
return CallableBool(False)
return False

# early return if not all triangular
if self._connectivity_array.size % 3:
return CallableBool(False)
return False

# next, check if there are three points per face
return CallableBool((np.diff(self._offset_array) == 3).all())
return (np.diff(self._offset_array) == 3).all()

def __sub__(self, cutting_mesh):
"""Compute boolean difference of two meshes."""
Expand Down Expand Up @@ -1016,11 +968,6 @@ def n_faces(self) -> int:
"""
return self.n_cells

@property
def number_of_faces(self): # pragma: no cover
"""Return the number of cells."""
raise DeprecationError('``number_of_faces`` has been deprecated. Please use ``n_faces``')

def save(self, filename, binary=True, texture=None, recompute_normals=True):
"""Write a surface mesh to disk.
Expand Down
2 changes: 1 addition & 1 deletion pyvista/jupyter/pv_pythreejs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def to_surf_mesh(
if add_attr is None:
add_attr = {}
# convert to an all-triangular surface
if surf.is_all_triangles():
if surf.is_all_triangles:
trimesh = surf
else:
trimesh = surf.triangulate()
Expand Down
2 changes: 0 additions & 2 deletions tests/test_polydata.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,8 +888,6 @@ def test_is_all_triangles():
assert not mesh.is_all_triangles
mesh = mesh.triangulate()
assert mesh.is_all_triangles
# for backwards compatibility, check if we can call this
assert mesh.is_all_triangles()


def test_extrude():
Expand Down

0 comments on commit b112597

Please sign in to comment.