Repository: pandas-dev/pandas

Issue:
np array indexer modified in iloc
#### Code Sample, a copy-pastable example if possible

```python
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
```python
In [39]: a
Out[39]: array([ 1,  2, -1])

```
#### Output of ``pd.show_versions()``

<details>

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

</details>



Discussion:
It's probably here: https://github.com/pandas-dev/pandas/blob/563a6ad108a79b0192a25d51d743812a18e21b15/pandas/core/indexing.py#L2419

that function should probably just copy the indexer.
Hi. I would like to take this up. Can you please help me out with this since it's my first issue.
@manasbedmutha98 Sorry,  I have already started working on this. 
Is this issue closed? I am still seeing the same behavior in 0.24.0
see the Open tag

and 0.24.0 is till under development

pull requests accepted 

Resolving patch:
diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py
--- a/pandas/core/indexing.py
+++ b/pandas/core/indexing.py
@@ -2596,6 +2596,7 @@ def maybe_convert_indices(indices, n):
 
     mask = indices < 0
     if mask.any():
+        indices = indices.copy()
         indices[mask] += n
 
     mask = (indices >= n) | (indices < 0)


Test patch:
diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py
--- a/pandas/tests/indexing/test_iloc.py
+++ b/pandas/tests/indexing/test_iloc.py
@@ -126,6 +126,21 @@ def test_iloc_getitem_neg_int(self):
                           typs=['labels', 'mixed', 'ts', 'floats', 'empty'],
                           fails=IndexError)
 
+    def test_iloc_array_not_mutating_negative_indices(self):
+
+        # GH 21867
+        array_with_neg_numbers = np.array([1, 2, -1])
+        array_copy = array_with_neg_numbers.copy()
+        df = pd.DataFrame({
+            'A': [100, 101, 102],
+            'B': [103, 104, 105],
+            'C': [106, 107, 108]},
+            index=[1, 2, 3])
+        df.iloc[array_with_neg_numbers]
+        tm.assert_numpy_array_equal(array_with_neg_numbers, array_copy)
+        df.iloc[:, array_with_neg_numbers]
+        tm.assert_numpy_array_equal(array_with_neg_numbers, array_copy)
+
     def test_iloc_getitem_list_int(self):
 
         # list of ints