diff --git a/src/pymatgen/analysis/elasticity/elastic.py b/src/pymatgen/analysis/elasticity/elastic.py index 4a236e24d3f..d67d6d87c22 100644 --- a/src/pymatgen/analysis/elasticity/elastic.py +++ b/src/pymatgen/analysis/elasticity/elastic.py @@ -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) diff --git a/src/pymatgen/entries/correction_calculator.py b/src/pymatgen/entries/correction_calculator.py index 0053b7e5d23..7b686375f07 100644 --- a/src/pymatgen/entries/correction_calculator.py +++ b/src/pymatgen/entries/correction_calculator.py @@ -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) diff --git a/src/pymatgen/transformations/advanced_transformations.py b/src/pymatgen/transformations/advanced_transformations.py index 2537241b653..225b72a6a55 100644 --- a/src/pymatgen/transformations/advanced_transformations.py +++ b/src/pymatgen/transformations/advanced_transformations.py @@ -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: diff --git a/tests/command_line/test_bader_caller.py b/tests/command_line/test_bader_caller.py index ad39f8c6b61..90ec2df89d1 100644 --- a/tests/command_line/test_bader_caller.py +++ b/tests/command_line/test_bader_caller.py @@ -1,6 +1,5 @@ from __future__ import annotations -import warnings from shutil import which import numpy as np @@ -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( diff --git a/tests/core/test_units.py b/tests/core/test_units.py index b94197b5645..7334f08f6c3 100644 --- a/tests/core/test_units.py +++ b/tests/core/test_units.py @@ -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):