question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

the error message for accidentally irregular arrays is confusing

See original GitHub issue

Someone using my code reported this error message, and I would have been able to track down the problem more quickly if the message had been more informative, maybe like ValueError: setting an irregularly shaped array with a non-object dtype instead of ValueError: setting an array element with a sequence.

>>> import numpy as np
>>> np.array([[0, 1], [2]]).dtype
dtype('O')
>>> np.array([[0, 1], [2]], dtype=int).dtype
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:34 (31 by maintainers)

github_iconTop GitHub Comments

1reaction
sebergcommented, Aug 22, 2020

The remaining corner case(s) are now also deprecated in master, so closing. The original case currently gives:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

which is probably not great, but much better than no information. Ideas for improvements welcome.

1reaction
njsmithcommented, Feb 10, 2015

@agriffing: I think we have a pretty good pile of evidence that there’s a problem here now 😃. Any interest in having a go at a making a solution?

On Mon, Feb 9, 2015 at 8:38 AM, argriffing notifications@github.com wrote:

I also think we should seriously consider implementing #5353 https://github.com/numpy/numpy/issues/5353 (don’t create object arrays unless dtype=object is explicitly specified) and making it so np.ndarray only treats list objects specially, with tuples and other sequence types being treats as array elements instead.

A similar question again on the mailing list http://mail.scipy.org/pipermail/numpy-discussion/2015-February/072240.html, regarding over-coercion of arrays of tuples into high dimensional arrays.

— Reply to this email directly or view it on GitHub https://github.com/numpy/numpy/issues/5303#issuecomment-73541097.

Nathaniel J. Smith – http://vorpus.org

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent numpy from creating a multidimensional array
Also https://github.com/numpy/numpy/issues/5303 the error message for accidentally irregular arrays is confusing .
Read more >
Data Structures: Objects and Arrays - Eloquent JavaScript
The irregular occurrences of the transformation make him suspect that they might be triggered by something. For a while, he believed that it...
Read more >
Rules for changing array formulas - Microsoft Support
To change or edit an array formula, you need to follow some rules, especially if you have multi-cell formulas. This article spells out...
Read more >
Top 10 Most Common C++ Mistakes That Developers Make
From a logical point of view the code seems completely fine. However, adding the second element to the vector may result in reallocation...
Read more >
Undefined behavior in C and C++ programs - Project Nayuki
Reading an uninitialized local variable is a compile-time error, which halts the binary code from being generated. · When an array is created...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found