@@ -391,18 +391,20 @@ def __setitem__(self, args, val):
391
391
392
392
# Generally we try to avoid converting the arrays on the Python
393
393
# side. However, for compound literals this is unavoidable.
394
- if self .dtype .kind == "O" or (
395
- self .dtype .kind == 'V' and \
396
- (not isinstance (val , numpy .ndarray ) or val .dtype .kind != 'V' ) ):
394
+ if self .dtype .kind == "O" or \
395
+ (self .dtype .kind == 'V' and \
396
+ (not isinstance (val , numpy .ndarray ) or val .dtype .kind != 'V' ) and \
397
+ (self .dtype .subdtype == None )):
397
398
val = numpy .asarray (val , dtype = self .dtype , order = 'C' )
398
399
else :
399
400
val = numpy .asarray (val , order = 'C' )
400
401
401
402
# Check for array dtype compatibility and convert
402
403
if self .dtype .subdtype is not None :
403
404
shp = self .dtype .subdtype [1 ]
404
- if val .shape [- len (shp ):] != shp :
405
- raise TypeError ("Can't broadcast to array dimension %s" % (shp ,))
405
+ valshp = val .shape [- len (shp ):]
406
+ if valshp != shp : # Last dimension has to match
407
+ raise TypeError ("When writing to array types, last N dimensions have to match (got %s, but should be %s)" % (valshp , shp ,))
406
408
mtype = h5t .py_create (numpy .dtype ((val .dtype , shp )))
407
409
mshape = val .shape [0 :len (val .shape )- len (shp )]
408
410
else :
@@ -418,7 +420,7 @@ def __setitem__(self, args, val):
418
420
# Broadcast scalars if necessary.
419
421
if (mshape == () and selection .mshape != ()):
420
422
if self .dtype .subdtype is not None :
421
- raise NotImplementedError ("Scalar broadcasting is not supported for array dtypes" )
423
+ raise TypeError ("Scalar broadcasting is not supported for array dtypes" )
422
424
val2 = numpy .empty (selection .mshape [- 1 ], dtype = val .dtype )
423
425
val2 [...] = val
424
426
val = val2
0 commit comments