Skip to content

Commit eb66ca1

Browse files
committed
NF - support __contains__ for recoder
1 parent cd7be20 commit eb66ca1

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

nibabel/tests/test_analyze.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,6 @@ def test_unsupported():
449449
data,
450450
affine)
451451

452+
453+
454+

nibabel/tests/test_recoder.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
99
''' Tests recoder class '''
1010

11-
from nose.tools import assert_equal, assert_raises
11+
from nose.tools import assert_equal, assert_raises, assert_true, assert_false
1212

1313
from ..volumeutils import Recoder
1414

@@ -71,7 +71,7 @@ def test_sugar():
7171
yield assert_equal, rc.code, rc.field1
7272
rc = Recoder(codes, fields=('code1', 'label'))
7373
yield assert_equal, rc.code1, rc.field1
74-
# Direct key access identical to key access for first named
74+
# Direct key access identical to key access for first named
7575
yield assert_equal, rc[1], rc.field1[1]
7676
yield assert_equal, rc['two'], rc.field1['two']
7777
# keys gets all keys
@@ -80,3 +80,7 @@ def test_sugar():
8080
yield assert_equal, rc.value_set(), set((1, 2))
8181
# or named column if given
8282
yield assert_equal, rc.value_set('label'), set(('one', 'two'))
83+
# "in" works for values in and outside the set
84+
yield assert_true, 'one' in rc
85+
yield assert_false, 'three' in rc
86+

nibabel/volumeutils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ def __getitem__(self, key):
150150
'''
151151
return self.field1[key]
152152

153+
def __contains__(self, key):
154+
""" True if field1 in recoder contains `key`
155+
"""
156+
return key in self.field1
157+
153158
def keys(self):
154159
''' Return all available code and alias values
155160

0 commit comments

Comments
 (0)