Closed
Description
Code Sample, a copy-pastable example if possible
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:
In [22]: from pandas.core import series
In [23]: series.is_list_like(str)
Out[23]: True
The implementation of is_list_like:
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:
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
ser2.index
Out[20]: Index(['2', '3', '4', '5', '6'], dtype='object', name='IntIndex')
ser2.name
Output of pd.show_versions()
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