Skip to content

np array indexer modified in iloc #20852

Closed
@amanhanda

Description

@amanhanda

Code Sample, a copy-pastable example if possible

In [31]: import pandas as pd

In [32]: import numpy as np

In [33]: a = np.array([1, 2, -1])

In [34]: b = pd.DataFrame([100, 101, 102], index=[1, 2, 3], columns=['col'])

In [35]: b.iloc[a]
Out[35]:
   col
2  101
3  102
3  102

In [36]: a
Out[36]: array([1, 2, 2])

Problem description

The array a is modified after the iloc operation from array([ 1, 2, -1]) to array([1, 2, 2]). The indexer should not be modified.

Expected Output

In [39]: a
Out[39]: array([ 1,  2, -1])

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 2.7.14.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-327.36.3.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: en_US.UTF-8
LOCALE: None.None

pandas: 0.22.0
pytest: 3.5.0
pip: 9.0.3
setuptools: 39.0.1
Cython: 0.28.2
numpy: 1.14.2
scipy: 1.0.1
pyarrow: 0.9.0
xarray: 0.10.2
IPython: 5.6.0
sphinx: 1.7.2
patsy: 0.5.0
dateutil: 2.7.2
pytz: 2018.4
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.2.2
openpyxl: 2.5.2
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.2.1
bs4: 4.3.2
html5lib: 0.999
sqlalchemy: 1.2.6
pymysql: None
psycopg2: 2.7.4 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesgood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions