Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: df.insert can't accept int64 value #53193

Closed
3 tasks done
auderson opened this issue May 12, 2023 · 0 comments · Fixed by #53194
Closed
3 tasks done

BUG: df.insert can't accept int64 value #53193

auderson opened this issue May 12, 2023 · 0 comments · Fixed by #53194
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@auderson
Copy link
Contributor

auderson commented May 12, 2023

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

import pandas as pd

df = pd.DataFrame({"a":[1,2]})
loc_a = df.columns.get_indexer(["a"])[0]
df.insert(loc_a, "b", 0)

Issue Description

the above code will output:

Traceback (most recent call last):
  File "/home/auderson/mambaforge/envs/py3.10/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3508, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-11-6dcccd9b83bc>", line 1, in <module>
    df.insert(loc_a, "b", 0)
  File "/home/auderson/mambaforge/envs/py3.10/lib/python3.10/site-packages/pandas/core/frame.py", line 4784, in insert
    raise TypeError("loc must be int")
TypeError: loc must be int

Expected Behavior

insert column correctly

Installed Versions

/home/auderson/mambaforge/envs/py3.10/lib/python3.10/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils.
warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS

commit : 37ea63d
python : 3.10.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-71-generic
Version : #78-Ubuntu SMP Tue Apr 18 09:00:29 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.1
numpy : 1.23.5
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.7.2
pip : 23.1.2
Cython : 0.29.34
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 1.0.3
psycopg2 : 2.9.3
jinja2 : None
IPython : 8.13.1
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : 0.57.0
numexpr : 2.8.4
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : 1.4.46
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@auderson auderson added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 12, 2023
@rhshadrach rhshadrach added Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants