Skip to content

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

@astrofrog

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?

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