88import pandas .tslib as tslib
99import pandas .core .common as com
1010from pandas .compat import StringIO , callable
11+ from pandas .core .common import ABCIndexClass
1112import pandas .compat as compat
1213from pandas .util .decorators import deprecate_kwarg
1314
@@ -277,7 +278,7 @@ def _to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
277278 from pandas .core .series import Series
278279 from pandas .tseries .index import DatetimeIndex
279280
280- def _convert_listlike (arg , box , format ):
281+ def _convert_listlike (arg , box , format , name = None ):
281282
282283 if isinstance (arg , (list ,tuple )):
283284 arg = np .array (arg , dtype = 'O' )
@@ -286,15 +287,15 @@ def _convert_listlike(arg, box, format):
286287 if com .is_datetime64_ns_dtype (arg ):
287288 if box and not isinstance (arg , DatetimeIndex ):
288289 try :
289- return DatetimeIndex (arg , tz = 'utc' if utc else None )
290+ return DatetimeIndex (arg , tz = 'utc' if utc else None , name = name )
290291 except ValueError :
291292 pass
292293
293294 return arg
294295 elif format is None and com .is_integer_dtype (arg ) and unit == 'ns' :
295296 result = arg .astype ('datetime64[ns]' )
296297 if box :
297- return DatetimeIndex (result , tz = 'utc' if utc else None )
298+ return DatetimeIndex (result , tz = 'utc' if utc else None , name = name )
298299
299300 return result
300301
@@ -355,13 +356,13 @@ def _convert_listlike(arg, box, format):
355356 require_iso8601 = require_iso8601 )
356357
357358 if com .is_datetime64_dtype (result ) and box :
358- result = DatetimeIndex (result , tz = 'utc' if utc else None )
359+ result = DatetimeIndex (result , tz = 'utc' if utc else None , name = name )
359360 return result
360361
361362 except ValueError as e :
362363 try :
363364 values , tz = tslib .datetime_to_datetime64 (arg )
364- return DatetimeIndex ._simple_new (values , None , tz = tz )
365+ return DatetimeIndex ._simple_new (values , name = name , tz = tz )
365366 except (ValueError , TypeError ):
366367 raise e
367368
@@ -372,6 +373,8 @@ def _convert_listlike(arg, box, format):
372373 elif isinstance (arg , Series ):
373374 values = _convert_listlike (arg .values , False , format )
374375 return Series (values , index = arg .index , name = arg .name )
376+ elif isinstance (arg , ABCIndexClass ):
377+ return _convert_listlike (arg , box , format , name = arg .name )
375378 elif com .is_list_like (arg ):
376379 return _convert_listlike (arg , box , format )
377380
0 commit comments