Skip to content

Commit

Permalink
Return bool instead of np.bool_ (materialsproject#4074)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn authored Sep 24, 2024
1 parent ea7c339 commit e9ea813
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def is_in_plane(self, pp, dist_tolerance) -> bool:
Returns:
bool: True if pp is in the plane.
"""
return np.abs(np.dot(self.normal_vector, pp) + self._coefficients[3]) <= dist_tolerance
return bool(np.abs(np.dot(self.normal_vector, pp) + self._coefficients[3]) <= dist_tolerance)

def is_same_plane_as(self, plane) -> bool:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/analysis/structure_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def fit(
if match1 is None or match2 is None:
return False

return max(match1[0], match2[0]) <= self.stol
return bool(max(match1[0], match2[0]) <= self.stol)

def get_rms_dist(self, struct1, struct2):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def is_valid(self, tol: float = DISTANCE_TOLERANCE) -> bool:
if len(self) == 1:
return True
all_dists = self.distance_matrix[np.triu_indices(len(self), 1)]
return np.min(all_dists) > tol
return bool(np.min(all_dists) > tol)

@abstractmethod
def to(self, filename: str = "", fmt: FileFormats = "") -> str | None:
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/core/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def is_symmetric(self, symprec: float = 0.1) -> bool:
# to surface (b) along the [hkl]-axis, surfaces are symmetric. Or because the
# two surfaces of our slabs are always parallel to the (hkl) plane,
# any operation where there's an (hkl) mirror plane has surface symmetry
return (
return bool(
spg_analyzer.is_laue()
or any(op.translation_vector[2] != 0 for op in symm_ops)
or any(np.all(op.rotation_matrix[2] == np.array([0, 0, -1])) for op in symm_ops)
Expand All @@ -318,7 +318,7 @@ def is_polar(self, tol_dipole_per_unit_area: float = 1e-3) -> bool:
considered polar.
"""
dip_per_unit_area = self.dipole / self.surface_area
return np.linalg.norm(dip_per_unit_area) > tol_dipole_per_unit_area
return bool(np.linalg.norm(dip_per_unit_area) > tol_dipole_per_unit_area)

def get_surface_sites(self, tag: bool = False) -> dict[str, list]:
"""Get the surface sites and their indices in a dictionary.
Expand Down
4 changes: 2 additions & 2 deletions src/pymatgen/core/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def is_fit_to_structure(self, structure: Structure, tol: float = 1e-2) -> bool:
structure (Structure): structure to be fit to
tol (float): tolerance for symmetry testing
"""
return (self - self.fit_to_structure(structure) < tol).all()
return bool((self - self.fit_to_structure(structure) < tol).all())

@property
def voigt(self) -> NDArray:
Expand Down Expand Up @@ -968,7 +968,7 @@ def is_rotation(
det = np.abs(np.linalg.det(self))
if include_improper:
det = np.abs(det)
return (np.abs(self.inv - self.trans) < tol).all() and (np.abs(det - 1.0) < tol)
return bool((np.abs(self.inv - self.trans) < tol).all() and (np.abs(det - 1.0) < tol))

def refine_rotation(self) -> Self:
"""Helper method for refining rotation matrix by ensuring
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/phonon/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def has_imaginary_freq(self, tol: float = 0.01) -> bool:
Args:
tol: Tolerance for determining if a frequency is imaginary. Defaults to 0.01.
"""
return self.min_freq()[1] + tol < 0
return bool(self.min_freq()[1] + tol < 0)

def has_imaginary_gamma_freq(self, tol: float = 0.01) -> bool:
"""Check if there are imaginary modes at the gamma point and all close points.
Expand Down

0 comments on commit e9ea813

Please sign in to comment.