Repository: pandas-dev/pandas

Issue:
Series#rename(str) change the name of Series.
#### Code Sample, a copy-pastable example if possible

```python
import pandas as pd

ser = pd.Series(range(1, 6), index=pd.Index(range(2, 7), name='IntIndex'))

ser2 = ser.rename(str)

ser2.index
Out[5]: RangeIndex(start=2, stop=7, step=1, name='IntIndex')

ser2.name
Out[6]: str

```
#### Problem description
I deep into the code and find that pandas.core.series#is_list_like return True for str:
```python
In [22]: from pandas.core import series

In [23]: series.is_list_like(str)
Out[23]: True
```

The implementation of is_list_like:
```python
def is_list_like(obj):
    """
    Check if the object is list-like.
    """

    return (hasattr(obj, '__iter__') and
            not isinstance(obj, string_and_binary_types))
```

may should change to:
```python
def is_list_like(obj):
    """
    Check if the object is list-like.
    """

    return (hasattr(obj , '__iter__') and
            not isinstance(obj, string_and_binary_types) and not isinstance(obj, type))
```

#### Expected Output
```python
ser2.index
Out[20]: Index(['2', '3', '4', '5', '6'], dtype='object', name='IntIndex')

ser2.name 
```
#### Output of ``pd.show_versions()``

<details>

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.26
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
</details>



Discussion:
pls read the doc-string. you are renaming to a *callable* which is valid but weird. you generally need to use a string.

```
In [10]: ser = pd.Series(range(1, 6), index=pd.Index(range(2, 7), name='IntIndex'))

In [11]: ser
Out[11]: 
IntIndex
2    1
3    2
4    3
5    4
6    5
dtype: int64

In [12]: ser.rename('foo')
Out[12]: 
IntIndex
2    1
3    2
4    3
5    4
6    5
Name: foo, dtype: int64
```
@jreback 
However, I want to rename the index rather than the name of series. 
I just use `ser.rename(str)` instead of `ser.rename(lambda i: str(i))` for short.
My expected output is Series with Index:
` Index(['2', '3', '4', '5', '6'], dtype='object', name='IntIndex')`
``ser.index.name = 'foo'``

this is clearly documented and does not interact with the index.
I think this is a bug. `str`, is a callable, so it should be altering the labels, not the name. FYI @Eastsun we're trying to clean up this API before 0.21, but for now this should work.
@Eastsun changing the check in `is_list_like` to check `isinstance(obj, Iterable)...`, works in this case. `Iterable` from the `collections` module. Would you mind seeing making that change breaks anything else, and submitting a PR with a fix + a test case?

Resolving patch:
diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py
--- a/pandas/core/dtypes/inference.py
+++ b/pandas/core/dtypes/inference.py
@@ -3,6 +3,7 @@
 import collections
 import re
 import numpy as np
+from collections import Iterable
 from numbers import Number
 from pandas.compat import (PY2, string_types, text_type,
                            string_and_binary_types)
@@ -262,7 +263,7 @@ def is_list_like(obj):
     False
     """
 
-    return (hasattr(obj, '__iter__') and
+    return (isinstance(obj, Iterable) and
             not isinstance(obj, string_and_binary_types))
 
 


Test patch:
diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py
--- a/pandas/tests/dtypes/test_inference.py
+++ b/pandas/tests/dtypes/test_inference.py
@@ -58,7 +58,7 @@ def __getitem__(self):
 def test_is_list_like():
     passes = ([], [1], (1, ), (1, 2), {'a': 1}, set([1, 'a']), Series([1]),
               Series([]), Series(['a']).str)
-    fails = (1, '2', object())
+    fails = (1, '2', object(), str)
 
     for p in passes:
         assert inference.is_list_like(p)
diff --git a/pandas/tests/series/test_indexing.py b/pandas/tests/series/test_indexing.py
--- a/pandas/tests/series/test_indexing.py
+++ b/pandas/tests/series/test_indexing.py
@@ -2188,6 +2188,16 @@ def test_reindex_fill_value(self):
         expected = Series([False, True, False], index=[1, 2, 3])
         assert_series_equal(result, expected)
 
+    def test_rename(self):
+
+        # GH 17407
+        s = Series(range(1, 6), index=pd.Index(range(2, 7), name='IntIndex'))
+        result = s.rename(str)
+        expected = s.rename(lambda i: str(i))
+        assert_series_equal(result, expected)
+
+        assert result.name == expected.name
+
     def test_select(self):
         n = len(self.ts)
         result = self.ts.select(lambda x: x >= self.ts.index[n // 2])