-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG ?: method .at[idx, "XXX"] generates InvalidIndexError in 1.4.0 or 1.4.1 but not in 1.3.5 #46036
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi, thanks for your report. I am sorry, but we can't really help you, if you can not provide a reproducible example. |
I understand, I am not even sure if my issue is due to a bug or if I need to adapt my code somehow. I probably can not make a reproducible short snippet because my understanding of Pandas is not expert. If you are interested I could give you a bunch of command lines that will reproduce the issue, but it will not just be a python snippet and it will download and execute our tool. |
This is hard to judge without knowing the data. Based on the content of a DataFrame the expected behavior might be different. Feel free to ping if you are able to create an example. Otherwise maybe stackoverflow might help as you suggested |
We are having the same issue. Here is a reproducible example:
The code throws an error because the The example completes without an error in 1.3.5 but throws the error in 1.4.1. Here's the traceback
Update: Looking at Line 3906 in 6033ed4
|
I have this problem, too. Indices from .index will trigger the same error when using df.at[indices,...]. After rolling back from 1.4.2 to 1.3.5, the problem disappeared. |
Can you give as a reproducible example? |
import pandas as pd df = pd.read_csv(full_table_file, sep='\t', header=None, index_col=0) ###Identify the domains related to the following search terms for search_term in case_insensitive_search_terms: for search_term in case_sensitive_search_terms: python 3.8 you will also need the table file https://www.icloud.com/iclouddrive/02cY4kezLwkVj5mV620oXpj0g#cddid |
@adamzev at is only meant for single values, so no guarantees on multiple values. @Enterprise-J: We need a minimal and reproducible example, see https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports |
From what I understand for pandas version 1.4.0 and up: the .at method will fail to update an index list of a single value and throw an InvalidIndexError. Switching to the .loc method for index list of size 1 or more should work. See answer from Mark Greenwood at https://stackoverflow.com/questions/71293357/upgrading-to-pandas-version-1-4-0-or-1-4-1-causes-a-call-to-the-method-atidx/71545633?noredirect=1#comment126506658_71545633 |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Upgrading to pandas version 1.4.0 or 1.4.1 causes a call to the method
.at[idx, "XXX"]
to generate an InvalidIndexError :Traceback (most recent call last):
File "XXX.py", line XXX, in XXX
data.at[idx, "False_positives"] = "-"
File "lib/python3.9/site-packages/pandas/core/indexing.py", line 2274, in setitem
return super().setitem(key, value)
File "/python3.9/site-packages/pandas/core/indexing.py", line 2229, in setitem
self.obj._set_value(*key, value=value, takeable=self._takeable)
File "/python3.9/site-packages/pandas/core/frame.py", line 3869, in _set_value
loc = self.index.get_loc(index)
File "/python3.9/site-packages/pandas/core/indexes/range.py", line 388, in get_loc
self._check_indexing_error(key)
File "/python3.9/site-packages/pandas/core/indexes/base.py", line 5637, in _check_indexing_error
raise InvalidIndexError(key)
pandas.errors.InvalidIndexError: Int64Index([0], dtype='int64')
This error does not occur with pandas version 1.3.5. Can you help figure this out ?
Expected Behavior
No exception should be raised.
Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.9.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-27-generic
Version : #29~20.04.1-Ubuntu SMP Fri Jan 14 00:32:30 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.1
numpy : 1.22.2
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.3
setuptools : 59.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: