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.

tolist() should have a consistent output type

See original GitHub issue

As 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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
yasuinikocommented, May 15, 2020

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?

0reactions
sebergcommented, May 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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