[NumPy-Tickets] [NumPy] #2010: dtype() construction fails when metadata = None

NumPy Trac numpy-tickets@scipy....
Wed Jan 4 01:22:00 CST 2012

#2010: dtype() construction fails when metadata = None
 Reporter:  tilkau  |       Owner:  somebody   
     Type:  defect  |      Status:  new        
 Priority:  normal  |   Milestone:  Unscheduled
Component:  Other   |     Version:  devel      
 Keywords:  dtype   |  
 >>> np.dtype('H', metadata={'foo':1})

 >>> np.dtype('H', metadata=None)
 TypeError: argument 4 must be dict, not None

 IMO metadata=None makes sense -- it means "don't update the metadata".
 Note that this would produce a different result than passing {} -- that
 results in 'mydtype.metadata' returning 'dict_proxy({})' rather than None.

 I'm writing a higher-level dtype+support-system constructor, and
 currently, due to this bug, I'm using everywhere this wrapper function
 instead of np.dtype:

 def dtype(dt, metadata=None, **kwargs):
     """DType wrapper that avoids crashery when metadata=None"""
     if metadata:
         return np.dtype (dt,metadata = metadata, **kwargs)
     return np.dtype (dt,**kwargs)

 The offending line seems to be around line 237 of

Ticket URL: <http://projects.scipy.org/numpy/ticket/2010>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list