Skip to content

Commit

Permalink
clean up warning filters
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 30, 2024
1 parent 255876a commit c24f50a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/pymatgen/analysis/elasticity/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,7 @@ def from_pseudoinverse(cls, strains, stresses) -> Self:
"questionable results from vasp data, use with caution."
)
stresses = np.array([Stress(stress).voigt for stress in stresses])
with warnings.catch_warnings():
strains = np.array([Strain(strain).voigt for strain in strains])
strains = np.array([Strain(strain).voigt for strain in strains])

voigt_fit = np.transpose(np.dot(np.linalg.pinv(strains), stresses))
return cls.from_voigt(voigt_fit)
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/entries/correction_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def compute_corrections(self, exp_entries: list, calc_entries: dict) -> dict:

with warnings.catch_warnings():
# numpy raises warning if the entire array is nan values
warnings.simplefilter("ignore", category=RuntimeWarning)
warnings.filterwarnings("ignore", "Mean of empty slice", RuntimeWarning)
mean_uncert = np.nanmean(sigma)

sigma = np.where(np.isnan(sigma), mean_uncert, sigma)
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/transformations/advanced_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def find_codopant(
for sym in symbols:
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore")
warnings.filterwarnings("ignore", r"No (default )?ionic radius for .+", UserWarning)
sp = Species(sym, oxidation_state)
radius = sp.ionic_radius
if radius is not None:
Expand Down
4 changes: 0 additions & 4 deletions tests/command_line/test_bader_caller.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import warnings
from shutil import which

import numpy as np
Expand All @@ -17,9 +16,6 @@

@pytest.mark.skipif(not which("bader"), reason="bader executable not present")
class TestBaderAnalysis(PymatgenTest):
def setUp(self):
warnings.catch_warnings()

def test_init(self):
# test with reference file
analysis = BaderAnalysis(
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_deprecated_memory(self):

with warnings.catch_warnings():
for unit in ("KB", "MB", "GB", "TB"):
warnings.filterwarnings("error", message=f"Unit {unit} is deprecated", category=DeprecationWarning)
warnings.filterwarnings("error", f"Unit {unit} is deprecated", DeprecationWarning)
Memory(1, unit)

def test_unitized(self):
Expand Down

0 comments on commit c24f50a

Please sign in to comment.