You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// When handling collections, we delegate to implementation APIs (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here:
64
67
v=value;
65
-
dt=dtype(value)||'generic';
66
68
}else{
67
69
// When provided a "scalar", we need to check whether the value can be safely cast to the target array data type:
// As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during assignment:
// Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point...
90
-
if(!isMostlySafeCast(dt,ctx.dtype)){
91
-
thrownewTypeError(format('invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].',dt,ctx.dtype));
95
+
if(!isMostlySafeCast(vdt,tdt)){
96
+
thrownewTypeError(format('invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].',vdt,tdt));
92
97
}
93
98
if(idx.type==='bool'){
94
-
where(idx.data,v,target,target,1,0);
99
+
try{
100
+
place(target,idx.data,v,'strict_broadcast');
101
+
}catch(err){
102
+
thrownewerr.constructor(errMessage(err.message));
103
+
}
95
104
returntrue;
96
105
}
97
106
if(idx.type==='mask'){
98
-
where(idx.data,target,v,target,1,0);
107
+
try{
108
+
where(idx.data,target,v,target,1,0);// note: intentionally deviate from boolean array indexing here and interpret the mask as applying to both the target and values array, thus requiring that the assigned value array be broadcast compatible with the target array and NOT just the selected elements as in boolean array indexing
109
+
}catch(err){
110
+
thrownewerr.constructor(errMessage(err.message));
111
+
}
99
112
returntrue;
100
113
}
101
114
thrownewError(format('invalid operation. Unrecognized array index type. Value: `%s`.',idx.type));
// As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during slice assignment:
0 commit comments