Skip to content

TypeError: Cannot change data-type for object array #5762

Closed

Description

@astrofrog

If I try and read in the array contained in this npy file:

https://gist.github.com/astrofrog/8c2d188005f31e0bba36/raw/3065c8fa220a6eaccbff20565d0d520c07e5e7e6/test.npy

then try and print out the array, so:

import numpy as np
array = np.load('test.npy')
print(array)

I get:

Traceback (most recent call last):
  File "test2.py", line 5, in <module>
    print(array)
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/numeric.py", line 1767, in array_str
    return array2string(a, max_line_width, precision, suppress_small, ' ', "", str)
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/arrayprint.py", line 459, in array2string
    separator, prefix, formatter=formatter)
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/arrayprint.py", line 329, in _array2string
    _summaryEdgeItems, summary_insert)[:-1]
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/arrayprint.py", line 526, in _formatArray
    s += _formatArray(a[-i], format_function, rank-1, max_line_len,
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/records.py", line 481, in __getitem__
    return obj.view(dtype=(self.dtype.type, obj.dtype.descr))
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/records.py", line 540, in view
    return ndarray.view(self, dtype)
  File "/Volumes/Raptor/miniconda3/envs/dev/lib/python3.4/site-packages/numpy/core/records.py", line 457, in __setattr__
    raise exctype(value)
TypeError: Cannot change data-type for object array.

This is with the latest developer version of Numpy (3c5409e) and Python 3.4 on MacOS X.

The dtype can be printed, as can individual columns, but the array as a whole can't. This doesn't occur in the latest stable release so may be a regression?

Activity

  1. added this to the milestone on Apr 11, 2015
  2. ahaldane commented on Apr 27, 2015

    @ahaldane
    Member

    As discussed in #5523, this would be fixed by #5548.

  3. added 10 commits that reference this issue on Jun 4, 2015
    907c541
    b7fece9
    4e3841c
    8171464
    34bdab2
    00a31fe
    432ddcd
    f3903e3
    958bf63
    e2cd6fa
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