[Numpy-discussion] Bytes vs. Unicode in Python3

Francesc Alted faltet@pytables....
Sun Dec 6 04:47:23 CST 2009


A Saturday 05 December 2009 11:16:55 Dag Sverre Seljebotn escrigué:
> > Mmh, the only case that I'm aware about dtype *mutability* is changing
> > the names of compound types:
> >
> > In [19]: t = np.dtype("i4,f4")
> >
> > In [20]: t
> > Out[20]: dtype([('f0', '<i4'), ('f1', '<f4')])
> >
> > In [21]: hash(t)
> > Out[21]: -9041335829180134223
> >
> > In [22]: t.names = ('one', 'other')
> >
> > In [23]: t
> > Out[23]: dtype([('one', '<i4'), ('other', '<f4')])
> >
> > In [24]: hash(t)
> > Out[24]: 8637734220020415106
> >
> > Perhaps this should be marked as a bug?  I'm not sure about that, because
> > the above seems quite useful.
> 
> Well, I for one don't like this, but that's just an opinion. I think it
> is unwise to leave object which supports hash() mutable, because it's
> too easy to make hard to find bugs (sticking a dtype as a key in a dict
> is rather useful in many situations). There's a certain tradition in
> Python for leaving types immutable if possible, and dtype certainly
> feels like it.

Yes, I think you are right and force dtype to be immutable would be the best.  
As a bonus, an immutable dtype would render this ticket:

http://projects.scipy.org/numpy/ticket/1127

without effect.

-- 
Francesc Alted


More information about the NumPy-Discussion mailing list