File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 1616"""This module defines class Structure.
1717"""
1818
19+ import collections
1920import copy
2021import numpy
2122from diffpy .Structure .lattice import Lattice
@@ -381,8 +382,10 @@ def __getitem__(self, idx):
381382 except TypeError :
382383 pass
383384 # check if there is any string label that should be resolved
384- scalarlabel = type (idx ) is str
385- hasstringlabel = scalarlabel or str in map (type , idx )
385+ scalarstringlabel = isinstance (idx , basestring )
386+ hasstringlabel = scalarstringlabel or (
387+ isinstance (idx , collections .Iterable ) and
388+ any (isinstance (ii , basestring ) for ii in idx ))
386389 # if not, use numpy indexing to resolve idx
387390 if not hasstringlabel :
388391 idx1 = idx
@@ -410,7 +413,7 @@ def _resolveindex(aid):
410413 raise IndexError ("Atom label %r is not unique." % aid )
411414 return aid1
412415 # generate new index object that has no strings
413- if scalarlabel :
416+ if scalarstringlabel :
414417 idx2 = _resolveindex (idx )
415418 # for iterables preserved the tuple object type
416419 else :
Original file line number Diff line number Diff line change @@ -261,6 +261,7 @@ def test___getitem__(self):
261261 self .assertTrue (stru [1 ] is stru ['B' ])
262262 stru [1 ].label = 'A'
263263 self .assertRaises (IndexError , stru .__getitem__ , 'A' )
264+ self .assertRaises (IndexError , stru .__getitem__ , stru [0 ])
264265 return
265266
266267
You can’t perform that action at this time.
0 commit comments