tolist() should have a consistent output type
See original GitHub issueAs mentioned in #11413, the tolist()
method does not always return a list. The naming of tolist()
implies that the output will be a list, which can cause issues as in the example below.
If the recursive part of tolist()
was rewritten with a helper function, then tolist()
could have type-consistent behaviour regardless of the number of dimensions of the input array.
Reproducing code example:
import numpy as np
array_1D_or_2D = np.arange(3)
for x in array_1D_or_2D:
len(x.tolist())
Error message:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: object of type 'int' has no len()
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
numpy.array(10).tolist() will return a number #11413 - GitHub
numpy.array(10).tolist() will return a number #11413 ... tolist() should have a consistent output type #16243.
Read more >linq - Do you ToList()? - Stack Overflow
ToList always evaluates the sequence immediately - not just in LINQ to SQL. If you want that, that's fine - but it's not...
Read more >tolist - Functions - Configuration Language | Terraform
The tolist function converts a value to a list. ... the resulting list will have an undefined order that will be consistent within...
Read more >ee.Reducer.toList - Earth Engine - Google Developers
Creates a reducer that collects its inputs into a list, optionally grouped into tuples. Usage, Returns. ee.Reducer.toList(tupleSize, numOptional) ...
Read more >Collecting Stream Elements into a List in Java - Baeldung
In this tutorial, we'll look at different methods to get a List from a Stream. ... First, let's create a List using Collectors:toList():...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, it is documented. Thank you. I believe the behaviour itself should be changed. Does this need to be marked as a feature request instead?
Thanks @yasuiniko and Eric, I am going to close the issue. Its a bit of a misnomer, but its tricky/noisy to change a name this and to be honest I would not have a much better name anyway.