Skip to content

Commit

Permalink
switch to nodataerror
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyminium committed Oct 20, 2024
1 parent 101008b commit 52adce9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 7 additions & 6 deletions package/MDAnalysis/guesser/default_guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@

import re

from ..exceptions import NoDataError
from ..lib import distances
from . import tables

Expand Down Expand Up @@ -218,15 +219,15 @@ def guess_masses(self, atom_types=None, indices_to_guess=None):
if atom_types is None:
try:
atom_types = self._universe.atoms.elements
except AttributeError:
except NoDataError:
try:
atom_types = self._universe.atoms.types
except AttributeError:
except NoDataError:
try:
atom_types = self.guess_types(
atom_types=self._universe.atoms.names)
except ValueError:
raise ValueError(
except NoDataError:
raise NoDataError(
"there is no reference attributes"
" (elements, types, or names)"
" in this universe to guess mass from")
Expand Down Expand Up @@ -291,8 +292,8 @@ def guess_types(self, atom_types=None, indices_to_guess=None):
if atom_types is None:
try:
atom_types = self._universe.atoms.names
except AttributeError:
raise ValueError(
except NoDataError:
raise NoDataError(
"there is no reference attributes in this universe"
"to guess types from")

Expand Down
9 changes: 5 additions & 4 deletions testsuite/MDAnalysisTests/guesser/test_default_guesser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

from numpy.testing import assert_equal, assert_allclose
import numpy as np
from MDAnalysis.core.topologyattrs import Angles, Atomtypes, Atomnames, Masses
from MDAnalysis.core.topologyattrs import Angles, Atomtypes, Atomnames
from MDAnalysis.exceptions import NoDataError
from MDAnalysis.guesser.default_guesser import DefaultGuesser
from MDAnalysis.core.topology import Topology
from MDAnalysisTests import make_Universe
Expand Down Expand Up @@ -82,7 +83,7 @@ def test_guess_atom_mass(self, default_guesser):

def test_guess_masses_with_no_reference_elements(self):
u = mda.Universe.empty(3)
with pytest.raises(ValueError,
with pytest.raises(NoDataError,
match=('there is no reference attributes ')):
u.guess_TopologyAttrs('default', ['masses'])

Expand Down Expand Up @@ -119,7 +120,7 @@ def test_guess_elements_from_no_data(self):
top = Topology(5)
msg = "there is no reference attributes in this universe"
"to guess types from"
with pytest.raises(ValueError, match=(msg)):
with pytest.raises(NoDataError, match=(msg)):
mda.Universe(top, to_guess=['types'])

@pytest.mark.parametrize('name, element', (
Expand Down Expand Up @@ -148,7 +149,7 @@ def test_guess_charge(default_guesser):
def test_guess_bonds_Error():
u = make_Universe(trajectory=True)
msg = "This Universe does not contain name information"
with pytest.raises(ValueError, match=msg):
with pytest.raises(NoDataError, match=msg):
u.guess_TopologyAttrs(to_guess=['bonds'])


Expand Down

0 comments on commit 52adce9

Please sign in to comment.