Skip to content

Cannot select atoms with StringSelection from empty AtomGroup #2765

@lilyminium

Description

@lilyminium

Expected behavior

empty_atomgroup.select_atoms('name anything') returns an empty AtomGroup.

Actual behavior

A TypeError is raised.

Code to reproduce the behavior

In [1]: import MDAnalysis as mda

In [2]: from MDAnalysis.tests.datafiles import PSF

In [3]: mda.__version__
Out[3]: '2.0.0-dev0'

In [4]: u = mda.Universe(PSF)

In [5]: ag = u.select_atoms('resname blahblah')

In [6]: len(ag)
Out[6]: 0

In [7]: ag.select_atoms('name O')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-c43a12bdaf29> in <module>
----> 1 ag.select_atoms('name O')

~/pydev/mdanalysis/package/MDAnalysis/core/groups.py in select_atoms(self, sel, *othersel, **selgroups)
   2861             # Apply the first selection and sum to it
   2862             atomgrp = sum([sel.apply(self) for sel in selections[1:]],
-> 2863                           selections[0].apply(self))
   2864         return atomgrp
   2865

~/pydev/mdanalysis/package/MDAnalysis/core/selection.py in apply(self, group)
    517         for val in self.values:
    518             values = getattr(group, self.field)
--> 519             mask |= [fnmatch.fnmatch(x, val) for x in values]
    520         return group[mask].unique
    521

TypeError: ufunc 'bitwise_or' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)") 2.0.0-dev0
  • Which version of Python (python -V)? 3.7
  • Which operating system? MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions