Repository: pandas-dev/pandas

Issue:
passing Index or Series to iloc fails with old numpy
#### Code Sample, a copy-pastable example if possible

```python
>>> s = pd.Series([1,2])    
>>> s.iloc[pd.Series([0])] = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexing.py", line 198, in __setitem__
    self._setitem_with_indexer(indexer, value)
  File "pandas/core/indexing.py", line 619, in _setitem_with_indexer
    value=value)
  File "pandas/core/internals.py", line 3313, in setitem
    return self.apply('setitem', **kwargs)
  File "pandas/core/internals.py", line 3201, in apply
    applied = getattr(b, f)(**kwargs)
  File "pandas/core/internals.py", line 864, in setitem
    values[indexer] = value
IndexError: unsupported iterator index
>>> np.version.version
'1.7.0'
```
#### Problem description

This is a consequence of #6168 , which is fixed in more recent numpy versions (but 1.7.0 is still a supported version).

Not 100% sure this is worth fixing (i.e. how interested we are in keeping compatibility with numpy 1.8.0), but the fix is trivial, so I'll just push a PR and let you judge.

#### Expected Output

Just no error.

#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-3-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: it_IT.UTF-8
LOCALE: None.None

pandas: 0+unknown
pytest: 3.2.0
pip: None
setuptools: 36.2.7
Cython: None
numpy: 1.7.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 1.5
pytz: 2012c
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
>>> 


</details>



Discussion:

Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- a/pandas/core/internals.py
+++ b/pandas/core/internals.py
@@ -861,6 +861,9 @@ def _is_empty_indexer(indexer):
 
         # set
         else:
+            if _np_version_under1p9:
+                # Work around GH 6168 to support old numpy
+                indexer = getattr(indexer, 'values', indexer)
             values[indexer] = value
 
         # coerce and try to infer the dtypes of the result


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
@@ -282,6 +282,19 @@ def test_iloc_setitem_list(self):
             index=["A", "B", "C"], columns=["A", "B", "C"])
         tm.assert_frame_equal(df, expected)
 
+    def test_iloc_setitem_pandas_object(self):
+        # GH 17193, affecting old numpy (1.7 and 1.8)
+        s_orig = Series([0, 1, 2, 3])
+        expected = Series([0, -1, -2, 3])
+
+        s = s_orig.copy()
+        s.iloc[Series([1, 2])] = [-1, -2]
+        tm.assert_series_equal(s, expected)
+
+        s = s_orig.copy()
+        s.iloc[pd.Index([1, 2])] = [-1, -2]
+        tm.assert_series_equal(s, expected)
+
     def test_iloc_setitem_dups(self):
 
         # GH 6766