You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]]
The text was updated successfully, but these errors were encountered:
Effectively changed in gh-14995 (although the 1.20 code is completely different). There is a test ensuring that object.__getitem__ is never called when that object also defined __array__. So this is effectively tested (which seemed like the reason for opening this issue).
Of course more tests are always good, so more could be added around this behaviour change probably!
Anyway, going to close this, it doesn't seem like something to put on the TODO list explicitly. The new NumPy always prioritizes __array__, etc. which is a change. Pre 1.19.x had a strange mix of things where there was one place where it did not use the __array__ protocol.
Or am I missing that you actually prefer the old behaviour?!
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.4The text was updated successfully, but these errors were encountered: