Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch guessers to catching and raising NoDataErrors #4755

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading