Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make the dtype object immutable and not coerce other types when compared (hashable requirements) (Trac #1127) #1725

@thouis

Description

@thouis

Original ticket http://projects.scipy.org/numpy/ticket/1127 on 2009-06-05 by @FrancescAlted, assigned to unknown.

The dtype object seems to be shared after a copy of a structured array is done. This is inconvenient when you change properties in one of arrays and these are propagated to the other.

The next snippet exposes the problem:

In [21]: dt = np.dtype('f4,f8')

In [22]: ra = np.empty(1, dt)

In [23]: ra.dtype
Out[23]: dtype([('f0', '<f4'), ('f1', '<f8')])

In [24]: rb = ra[:]

In [25]: ra.dtype.names = ('float', 'double')

In [26]: ra.dtype
Out[26]: dtype([('float', '<f4'), ('double', '<f8')])

In [27]: rb.dtype
Out[27]: dtype([('float', '<f4'), ('double', '<f8')])  # not the original!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions