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.

Error Indexing DafaFrame with a 0-d array

See original GitHub issue
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'])
>>> ar = np.array(0)
>>> df.iloc[ar]
Traceback (most recent call last):
  ...
  ...
  File "/home/float2/Documents/Python/Pandas/pandas/pandas/core/indexes/base.py", line 529, in _shallow_copy_with_infer
    if not len(values) and 'dtype' not in kwargs:
TypeError: object of type 'numpy.int64' has no len()

A 0-d array passes this check cause it is an Iterable. But later, when len() is called on, TypeError is raised. It would be nice to implement PEP 357 to prevent this error. The matter has been raised at PyTorch project. #9237

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:29 (26 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Jan 29, 2019

@tamuhey issues are closed when the corresponding PR is actually merged

0reactions
jrebackcommented, Mar 24, 2019

this is a duplicate of #24919 and closed by #24924

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uniform way of using array indexing for 0D & 1D numpy arrays
The problem here is that value is of type numpy. ndarray , but since it's a 0-d array, numpy. cos returns a numpy....
Read more >
Accessing Data Along Multiple Dimensions in an Array
Introduce the indexing and slicing scheme for accessing a multi-dimensional array's contents. We will encounter arrays of varying dimensionalities: # A 0-D ......
Read more >
Version 0.18.1 (May 3, 2016) — pandas 1.4.3 documentation
Bug in SparseArray[] indexing with tuples are not handled properly (GH12966) ... in DataFrame.to_json when attempting to serialise 0d array (GH11299).
Read more >
NumPy Creating Arrays - W3Schools
We can create a NumPy ndarray object by using the array() function. ... 0-D arrays, or Scalars, are the elements in an array....
Read more >
Only size-1 arrays can be converted to Python scalars
This error occurs most often when you attempt to use np.int() to convert a NumPy array of float values to an array of...
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