Python operator.setitem() Examples
The following are 30
code examples of operator.setitem().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
operator
, or try the search function
.
Example #1
Source File: test_cftp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def setUp(self): """ Patch the L{ls} module's time function so the results of L{lsLine} are deterministic. """ self.now = 123456789 def fakeTime(): return self.now self.patch(ls, 'time', fakeTime) # Make sure that the timezone ends up the same after these tests as # it was before. if 'TZ' in os.environ: self.addCleanup(operator.setitem, os.environ, 'TZ', os.environ['TZ']) self.addCleanup(time.tzset) else: def cleanup(): # os.environ.pop is broken! Don't use it! Ever! Or die! try: del os.environ['TZ'] except KeyError: pass time.tzset() self.addCleanup(cleanup)
Example #2
Source File: setitem.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_setitem_mask_aligned(self, data, as_callable, setter): ser = pd.Series(data) mask = np.zeros(len(data), dtype=bool) mask[:2] = True if as_callable: mask2 = lambda x: mask else: mask2 = mask if setter: # loc target = getattr(ser, setter) else: # Series.__setitem__ target = ser operator.setitem(target, mask2, data[5:7]) ser[mask2] = data[5:7] assert ser[0] == data[5] assert ser[1] == data[6]
Example #3
Source File: setitem.py From vnpy_crypto with MIT License | 6 votes |
def test_setitem_mask_aligned(self, data, as_callable, setter): ser = pd.Series(data) mask = np.zeros(len(data), dtype=bool) mask[:2] = True if as_callable: mask2 = lambda x: mask else: mask2 = mask if setter: # loc target = getattr(ser, setter) else: # Series.__setitem__ target = ser operator.setitem(target, mask2, data[5:7]) ser[mask2] = data[5:7] assert ser[0] == data[5] assert ser[1] == data[6]
Example #4
Source File: reflection_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testTopLevelExtensionsForRepeatedMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeatedgroup_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) group = extendee_proto.Extensions[extension].add() group.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension][0].a) group.a = 42 self.assertEqual(42, extendee_proto.Extensions[extension][0].a) group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(group_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #5
Source File: reflection_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension self.assertTrue(not extendee_proto.HasExtension(extension)) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. self.assertTrue(not extendee_proto.HasExtension(extension)) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) self.assertTrue(extendee_proto.HasExtension(extension)) # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) self.assertTrue(not extendee_proto.HasExtension(extension)) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #6
Source File: reflection_test.py From botchallenge with MIT License | 6 votes |
def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension self.assertTrue(not extendee_proto.HasExtension(extension)) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. self.assertTrue(not extendee_proto.HasExtension(extension)) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) self.assertTrue(extendee_proto.HasExtension(extension)) # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) self.assertTrue(not extendee_proto.HasExtension(extension)) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #7
Source File: reflection_test.py From botchallenge with MIT License | 6 votes |
def testTopLevelExtensionsForRepeatedMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeatedgroup_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) group = extendee_proto.Extensions[extension].add() group.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension][0].a) group.a = 42 self.assertEqual(42, extendee_proto.Extensions[extension][0].a) group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(group_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #8
Source File: reflection_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension self.assertTrue(not extendee_proto.HasExtension(extension)) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. self.assertTrue(not extendee_proto.HasExtension(extension)) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) self.assertTrue(extendee_proto.HasExtension(extension)) # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) self.assertTrue(not extendee_proto.HasExtension(extension)) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #9
Source File: reflection_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testTopLevelExtensionsForRepeatedMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeatedgroup_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) group = extendee_proto.Extensions[extension].add() group.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension][0].a) group.a = 42 self.assertEqual(42, extendee_proto.Extensions[extension][0].a) group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(group_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #10
Source File: reflection_test.py From lambda-packs with MIT License | 6 votes |
def testTopLevelExtensionsForRepeatedMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeatedgroup_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) group = extendee_proto.Extensions[extension].add() group.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension][0].a) group.a = 42 self.assertEqual(42, extendee_proto.Extensions[extension][0].a) group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(group_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #11
Source File: reflection_test.py From lambda-packs with MIT License | 6 votes |
def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension self.assertTrue(not extendee_proto.HasExtension(extension)) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. self.assertTrue(not extendee_proto.HasExtension(extension)) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) self.assertTrue(extendee_proto.HasExtension(extension)) # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) self.assertTrue(not extendee_proto.HasExtension(extension)) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #12
Source File: reflection_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testTopLevelExtensionsForOptionalMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.optional_foreign_message_extension self.assertTrue(not extendee_proto.HasExtension(extension)) self.assertEqual(0, extendee_proto.Extensions[extension].c) # As with normal (non-extension) fields, merely reading from the # thing shouldn't set the "has" bit. self.assertTrue(not extendee_proto.HasExtension(extension)) extendee_proto.Extensions[extension].c = 23 self.assertEqual(23, extendee_proto.Extensions[extension].c) self.assertTrue(extendee_proto.HasExtension(extension)) # Save a reference here. foreign_message = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertTrue(foreign_message is not extendee_proto.Extensions[extension]) # Setting a field on foreign_message now shouldn't set # any "has" bits on extendee_proto. foreign_message.c = 42 self.assertEqual(42, foreign_message.c) self.assertTrue(foreign_message.HasField('c')) self.assertTrue(not extendee_proto.HasExtension(extension)) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #13
Source File: setitem.py From recruit with Apache License 2.0 | 6 votes |
def test_setitem_mask_aligned(self, data, as_callable, setter): ser = pd.Series(data) mask = np.zeros(len(data), dtype=bool) mask[:2] = True if as_callable: mask2 = lambda x: mask else: mask2 = mask if setter: # loc target = getattr(ser, setter) else: # Series.__setitem__ target = ser operator.setitem(target, mask2, data[5:7]) ser[mask2] = data[5:7] assert ser[0] == data[5] assert ser[1] == data[6]
Example #14
Source File: reflection_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testTopLevelExtensionsForRepeatedMessage(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeatedgroup_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) group = extendee_proto.Extensions[extension].add() group.a = 23 self.assertEqual(23, extendee_proto.Extensions[extension][0].a) group.a = 42 self.assertEqual(42, extendee_proto.Extensions[extension][0].a) group_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(group_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #15
Source File: test_cftp.py From learn_python3_spider with MIT License | 6 votes |
def setUp(self): """ Patch the L{ls} module's time function so the results of L{lsLine} are deterministic. """ self.now = 123456789 def fakeTime(): return self.now self.patch(ls, 'time', fakeTime) # Make sure that the timezone ends up the same after these tests as # it was before. if 'TZ' in os.environ: self.addCleanup(operator.setitem, os.environ, 'TZ', os.environ['TZ']) self.addCleanup(time.tzset) else: def cleanup(): # os.environ.pop is broken! Don't use it! Ever! Or die! try: del os.environ['TZ'] except KeyError: pass time.tzset() self.addCleanup(cleanup)
Example #16
Source File: test_core.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_coercion_int(self): a_i = np.zeros((), int) assert_raises(MaskError, operator.setitem, a_i, (), np.ma.masked) assert_raises(MaskError, int, np.ma.masked)
Example #17
Source File: reflection_test.py From botchallenge with MIT License | 5 votes |
def testTopLevelExtensionsForRepeatedScalar(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeated_string_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) extendee_proto.Extensions[extension].append('foo') self.assertEqual(['foo'], extendee_proto.Extensions[extension]) string_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(string_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #18
Source File: stack_context.py From honeything with GNU General Public License v3.0 | 5 votes |
def __enter__(self): self.old_contexts = _state.contexts _state.contexts = (self.old_contexts + ((ExceptionStackContext, self.exception_handler, self.active_cell),)) return lambda: operator.setitem(self.active_cell, 0, False)
Example #19
Source File: stack_context.py From honeything with GNU General Public License v3.0 | 5 votes |
def __enter__(self): self.old_contexts = _state.contexts # _state.contexts is a tuple of (class, arg, active_cell) tuples _state.contexts = (self.old_contexts + ((StackContext, self.context_factory, self.active_cell),)) try: self.context = self.context_factory() self.context.__enter__() except Exception: _state.contexts = self.old_contexts raise return lambda: operator.setitem(self.active_cell, 0, False)
Example #20
Source File: reflection_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testTopLevelExtensionsForRepeatedScalar(self): extendee_proto = unittest_pb2.TestAllExtensions() extension = unittest_pb2.repeated_string_extension self.assertEqual(0, len(extendee_proto.Extensions[extension])) extendee_proto.Extensions[extension].append('foo') self.assertEqual(['foo'], extendee_proto.Extensions[extension]) string_list = extendee_proto.Extensions[extension] extendee_proto.ClearExtension(extension) self.assertEqual(0, len(extendee_proto.Extensions[extension])) self.assertTrue(string_list is not extendee_proto.Extensions[extension]) # Shouldn't be allowed to do Extensions[extension] = 'a' self.assertRaises(TypeError, operator.setitem, extendee_proto.Extensions, extension, 'a')
Example #21
Source File: test_slicing.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_char_ptr(self): s = b"abcdefghijklmnopqrstuvwxyz" dll = CDLL(_ctypes_test.__file__) dll.my_strdup.restype = POINTER(c_char) dll.my_free.restype = None res = dll.my_strdup(s) self.assertEqual(res[:len(s)], s) self.assertEqual(res[:3], s[:3]) self.assertEqual(res[:len(s):], s) self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) self.assertEqual(res[0:-1:-1], s[0::-1]) import operator self.assertRaises(ValueError, operator.getitem, res, slice(None, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(0, None, None)) self.assertRaises(ValueError, operator.getitem, res, slice(None, 5, -1)) self.assertRaises(ValueError, operator.getitem, res, slice(-5, None, None)) self.assertRaises(TypeError, operator.setitem, res, slice(0, 5), "abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) res = dll.my_strdup(s) self.assertEqual(res[:len(s)], list(range(ord("a"), ord("z")+1))) self.assertEqual(res[:len(s):], list(range(ord("a"), ord("z")+1))) dll.my_free(res)
Example #22
Source File: test_slicing.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*range(1100, 1200)) b = list(range(1100, 1200)) a[32:47] = list(range(32, 47)) self.assertEqual(a[32:47], list(range(32, 47))) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], list(range(132, 147))) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], list(range(246, 231, -1))) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #23
Source File: test_slicing.py From Imogen with MIT License | 5 votes |
def test_setslice_cint(self): a = (c_int * 100)(*range(1100, 1200)) b = list(range(1100, 1200)) a[32:47] = list(range(32, 47)) self.assertEqual(a[32:47], list(range(32, 47))) a[32:47] = range(132, 147) self.assertEqual(a[32:47:], list(range(132, 147))) a[46:31:-1] = range(232, 247) self.assertEqual(a[32:47:1], list(range(246, 231, -1))) a[32:47] = range(1132, 1147) self.assertEqual(a[:], b) a[32:47:7] = range(3) b[32:47:7] = range(3) self.assertEqual(a[:], b) a[33::-3] = range(12) b[33::-3] = range(12) self.assertEqual(a[:], b) from operator import setitem # TypeError: int expected instead of str instance self.assertRaises(TypeError, setitem, a, slice(0, 5), "abcde") # TypeError: int expected instead of str instance self.assertRaises(TypeError, setitem, a, slice(0, 5), ["a", "b", "c", "d", "e"]) # TypeError: int expected instead of float instance self.assertRaises(TypeError, setitem, a, slice(0, 5), [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
Example #24
Source File: setitem.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_setitem_scalar(self, data, setter): arr = pd.Series(data) setter = getattr(arr, setter) operator.setitem(setter, 0, data[1]) assert arr[0] == data[1]
Example #25
Source File: ssh.py From flocker with Apache License 2.0 | 5 votes |
def __init__(self, key_file): """ Start an `ssh-agent` and add its socket path and pid to the global environment so that SSH sub-processes can use it for authentication. :param FilePath key_file: An SSH private key file which can be used when authenticating with SSH servers. """ self._cleanups = [] output = check_output([b"ssh-agent", b"-c"]).splitlines() # setenv SSH_AUTH_SOCK /tmp/ssh-5EfGti8RPQbQ/agent.6390; # setenv SSH_AGENT_PID 6391; # echo Agent pid 6391; sock = output[0].split()[2][:-1] pid = output[1].split()[2][:-1] self._pid = int(pid) def patchdict(k, v): if k in os.environ: self._cleanups.append( lambda old=os.environ[k]: setitem(os.environ, k, old)) else: self._cleanups.append(lambda: delitem(os.environ, k)) os.environ[k] = v patchdict(b"SSH_AUTH_SOCK", sock) patchdict(b"SSH_AGENT_PID", pid) with open(os.devnull, "w") as discard: # See https://clusterhq.atlassian.net/browse/FLOC-192 check_call( [b"ssh-add", key_file.path], stdout=discard, stderr=discard)
Example #26
Source File: test_core.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_coercion_float(self): a_f = np.zeros((), float) assert_warns(UserWarning, operator.setitem, a_f, (), np.ma.masked) assert_(np.isnan(a_f[()]))
Example #27
Source File: test_core.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_immutable(self): orig = np.ma.masked assert_raises(np.ma.core.MaskError, operator.setitem, orig, (), 1) assert_raises(ValueError,operator.setitem, orig.data, (), 1) assert_raises(ValueError, operator.setitem, orig.mask, (), False) view = np.ma.masked.view(np.ma.MaskedArray) assert_raises(ValueError, operator.setitem, view, (), 1) assert_raises(ValueError, operator.setitem, view.data, (), 1) assert_raises(ValueError, operator.setitem, view.mask, (), False)
Example #28
Source File: test_core.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_coercion_float(self): a_f = np.zeros((), float) assert_warns(UserWarning, operator.setitem, a_f, (), np.ma.masked) assert_(np.isnan(a_f[()]))
Example #29
Source File: test_core.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_coercion_int(self): a_i = np.zeros((), int) assert_raises(MaskError, operator.setitem, a_i, (), np.ma.masked) assert_raises(MaskError, int, np.ma.masked)
Example #30
Source File: test_core.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_immutable(self): orig = np.ma.masked assert_raises(np.ma.core.MaskError, operator.setitem, orig, (), 1) assert_raises(ValueError,operator.setitem, orig.data, (), 1) assert_raises(ValueError, operator.setitem, orig.mask, (), False) view = np.ma.masked.view(np.ma.MaskedArray) assert_raises(ValueError, operator.setitem, view, (), 1) assert_raises(ValueError, operator.setitem, view.data, (), 1) assert_raises(ValueError, operator.setitem, view.mask, (), False)