Skip to content

Assiging to structured array rows with list/array fails (Trac #1758) #2353

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1758 on 2011-03-07 by @rgommers, assigned to unknown.

Assigning to a structured array with a tuple works, with a list results in an error. Would be good if this could be made to work (this is an enhancement request). With an array gives no warning or exception, but results in garbage. This is a bug.

See also http://thread.gmane.org/gmane.comp.python.numeric.general/30793/focus=30793

>>> arr = np.zeros((5,), dtype=[('var1','f8'),('var2','f8')])
>>> arr['var1'] = np.arange(5)
>>> arr
array([(0.0, 0.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0), (4.0, 0.0)], 
      dtype=[('var1', '<f8'), ('var2', '<f8')])
>>> arr[0] = (10,20)
>>> arr
array([(10.0, 20.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0), (4.0, 0.0)], 
      dtype=[('var1', '<f8'), ('var2', '<f8')])
>>> arr[0] = np.array([10,20])
>>> arr
array([(4.2439915824246103e-313, 0.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0),
       (4.0, 0.0)], 
      dtype=[('var1', '<f8'), ('var2', '<f8')])

If this is fixed, please update doc/structured_arrays.py (section "Filling structured arrays").

Activity

  1. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @rgommers wrote on 2011-03-09

    For the array assignment part, it does work when no casting has to be done. From Skipper on-list:

    This is a casting issue. Your array is an integer array. You can
    assign with an array.
    
    arr = np.zeros((5,), dtype=[('var1','f8'),('var2','f8')])
    arr[0] = np.array([10.0,20])
    arr[0]
    (10.0, 20.0)
    

    Still a bug, since casting elements of a tuple works fine.

  2. charris commented on Feb 20, 2014

    @charris
    Member

    Still fails 1.9-devel.

  3. added 3 commits that reference this issue on Jun 17, 2016
    2ef0103
  4. added a commit that references this issue on Oct 23, 2017
    ae582a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions