18
18
#include "ctors.h"
19
19
#include "usertypes.h"
20
20
#include "_datetime.h"
21
+ #include "na_singleton.h"
21
22
22
23
#include "numpyos.h"
23
24
@@ -142,6 +143,12 @@ static int
142
143
if (PyArray_IsScalar (op , @kind @)) {
143
144
temp = ((Py @kind @ScalarObject * )op )-> obval ;
144
145
}
146
+ else if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
147
+ PyErr_SetString (PyExc_ValueError ,
148
+ "Cannot assign NA to an array which "
149
+ "does not support NAs" );
150
+ return -1 ;
151
+ }
145
152
else {
146
153
temp = (@type @)@func2 @(op );
147
154
}
@@ -204,7 +211,16 @@ static int
204
211
c @type @ temp ;
205
212
int rsize ;
206
213
207
- if (!(PyArray_IsScalar (op , @kind @))) {
214
+ if (PyArray_IsScalar (op , @kind @)){
215
+ temp = ((Py @kind @ScalarObject * )op )-> obval ;
216
+ }
217
+ else if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
218
+ PyErr_SetString (PyExc_ValueError ,
219
+ "Cannot assign NA to an array which "
220
+ "does not support NAs" );
221
+ return -1 ;
222
+ }
223
+ else {
208
224
if (PyArray_Check (op ) && (PyArray_NDIM ((PyArrayObject * )op ) == 0 )) {
209
225
op2 = PyArray_DESCR ((PyArrayObject * )op )-> f -> getitem (
210
226
PyArray_BYTES ((PyArrayObject * )op ),
@@ -227,9 +243,7 @@ static int
227
243
temp .real = (@type @) oop .real ;
228
244
temp .imag = (@type @) oop .imag ;
229
245
}
230
- else {
231
- temp = ((Py @kind @ScalarObject * )op )-> obval ;
232
- }
246
+
233
247
memcpy (ov , & temp , PyArray_DESCR (ap )-> elsize );
234
248
if (!PyArray_ISNOTSWAPPED (ap )) {
235
249
byte_swap_vector (ov , 2 , sizeof (@type @));
@@ -259,6 +273,12 @@ LONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) {
259
273
if (PyArray_IsScalar (op , LongDouble )) {
260
274
temp = ((PyLongDoubleScalarObject * )op )-> obval ;
261
275
}
276
+ else if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
277
+ PyErr_SetString (PyExc_ValueError ,
278
+ "Cannot assign NA to an array which "
279
+ "does not support NAs" );
280
+ return -1 ;
281
+ }
262
282
else {
263
283
temp = (longdouble ) MyPyFloat_AsDouble (op );
264
284
}
@@ -353,6 +373,12 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap)
353
373
"setting an array element with a sequence" );
354
374
return -1 ;
355
375
}
376
+ if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
377
+ PyErr_SetString (PyExc_ValueError ,
378
+ "Cannot assign NA to an array which "
379
+ "does not support NAs" );
380
+ return -1 ;
381
+ }
356
382
/* Sequence_Size might have returned an error */
357
383
if (PyErr_Occurred ()) {
358
384
PyErr_Clear ();
@@ -457,6 +483,12 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap)
457
483
"cannot set an array element with a sequence" );
458
484
return -1 ;
459
485
}
486
+ if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
487
+ PyErr_SetString (PyExc_ValueError ,
488
+ "Cannot assign NA to an array which "
489
+ "does not support NAs" );
490
+ return -1 ;
491
+ }
460
492
#if defined(NPY_PY3K )
461
493
if (PyUnicode_Check (op )) {
462
494
/* Assume ASCII codec -- function similarly as Python 2 */
@@ -752,6 +784,13 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap)
752
784
return res ;
753
785
}
754
786
787
+ if (NpyNA_Check (op ) || NpyNA_IsZeroDimArrayNA (op )) {
788
+ PyErr_SetString (PyExc_ValueError ,
789
+ "Cannot assign NA to an array which "
790
+ "does not support NAs" );
791
+ return -1 ;
792
+ }
793
+
755
794
/* Default is to use buffer interface to set item */
756
795
{
757
796
const void * buffer ;
0 commit comments