pandas: Error Indexing DafaFrame with a 0-d array
>>> 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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 29 (26 by maintainers)
Commits related to this issue
- fix Error Indexing DafaFrame with a 0-d array closes #21946 Change-Id: I79cb68527820adddd3a8e3f4a71c12ee677eec60 — committed to illegalnumbers/pandas by illegalnumbers 6 years ago
- fix Error Indexing DafaFrame with a 0-d array closes #21946 — committed to illegalnumbers/pandas by illegalnumbers 6 years ago
- fix Error Indexing DafaFrame with a 0-d array closes #21946 — committed to illegalnumbers/pandas by illegalnumbers 6 years ago
- fix Error Indexing DafaFrame with a 0-d array closes #21946 — committed to illegalnumbers/pandas by illegalnumbers 6 years ago
- add a test to check zero index array do not error refs GH-21946 — committed to illegalnumbers/pandas by illegalnumbers 5 years ago
- add a test to check zero index array do not error closes #21946 — committed to illegalnumbers/pandas by illegalnumbers 5 years ago
- add a test to check zero index array do not error closes #21946 — committed to illegalnumbers/pandas by illegalnumbers 5 years ago
@tamuhey issues are closed when the corresponding PR is actually merged