Skip to content

np.array([pd.Series({1:1})]) threw KeyError in numpy 1.17.4 #18023

@MarcoGorelli

Description

@MarcoGorelli

Hi - this was reported here pandas-dev/pandas#38543 in pandas, am just posting here in case it wasn't reported to you previously.

In short, np.array([pd.Series({1:1})]) works in numpy 1.19.4 but not in numpy 1.17.4

$ mkdir tmp
$ cd tmp/
$ virtualenv venv
$ . venv/bin/activate
$ pip install numpy==1.17.4 pandas==1.1.5
$ python -c 'import numpy; import pandas; print(numpy.array([pandas.Series({1:1})]))'
Traceback (most recent call last):
  File "/home/marco/tmp/venv/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2898, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 1032, in pandas._libs.hashtable.Int64HashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 1039, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/marco/tmp/venv/lib/python3.8/site-packages/pandas/core/series.py", line 882, in __getitem__
    return self._get_value(key)
  File "/home/marco/tmp/venv/lib/python3.8/site-packages/pandas/core/series.py", line 990, in _get_value
    loc = self.index.get_loc(label)
  File "/home/marco/tmp/venv/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2900, in get_loc
    raise KeyError(key) from err
KeyError: 0

$ pip install numpy==1.19.4
$ python -c 'import numpy; import pandas; print(numpy.array([pandas.Series({1:1})]))'
[[1]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions