Skip to content

Commit 46ba51f

Browse files
BUG: initialize DatetimeIndex with array of strings (#4229)
1 parent a5f4a67 commit 46ba51f

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

doc/source/release.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ pandas 0.12
338338
- Fixed the legend displaying in ``DataFrame.plot(kind='kde')`` (:issue:`4216`)
339339
- Fixed bug where Index slices weren't carrying the name attribute
340340
(:issue:`4226`)
341+
- Fixed bug in initializing ``DatetimeIndex`` with an array of strings
342+
in a certain time zone (:issue:`4229`)
341343

342344
pandas 0.11.0
343345
=============

doc/source/v0.12.0.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ Bug Fixes
471471
- Fixed the legend displaying in ``DataFrame.plot(kind='kde')`` (:issue:`4216`)
472472
- Fixed bug where Index slices weren't carrying the name attribute
473473
(:issue:`4226`)
474-
474+
- Fixed bug in initializing ``DatetimeIndex`` with an array of strings
475+
in a certain time zone (:issue:`4229`)
476+
475477
See the :ref:`full release notes
476478
<release>` or issue tracker
477479
on GitHub for a complete list.

pandas/tseries/index.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ def __new__(cls, data=None,
208208
return data
209209

210210
if issubclass(data.dtype.type, basestring):
211-
subarr = _str_to_dt_array(data, offset, dayfirst=dayfirst,
211+
data = _str_to_dt_array(data, offset, dayfirst=dayfirst,
212212
yearfirst=yearfirst)
213-
elif issubclass(data.dtype.type, np.datetime64):
213+
214+
if issubclass(data.dtype.type, np.datetime64):
214215
if isinstance(data, DatetimeIndex):
215216
if tz is None:
216217
tz = data.tz

pandas/tseries/tests/test_timezones.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,22 @@ def test_index_drop_dont_lose_tz(self):
631631

632632
self.assertTrue(ind.tz is not None)
633633

634+
def test_datetimeindex_tz(self):
635+
""" Test different DatetimeIndex constructions with timezone
636+
Follow-up of #4229
637+
"""
638+
639+
arr = ['11/10/2005 08:00:00', '11/10/2005 09:00:00']
640+
641+
idx1 = to_datetime(arr).tz_localize('US/Eastern')
642+
idx2 = DatetimeIndex(start="2005-11-10 08:00:00", freq='H', periods=2, tz='US/Eastern')
643+
idx3 = DatetimeIndex(arr, tz='US/Eastern')
644+
idx4 = DatetimeIndex(np.array(arr), tz='US/Eastern')
645+
646+
for other in [idx2, idx3, idx4]:
647+
self.assert_(idx1.equals(other))
648+
649+
634650
class TestTimeZones(unittest.TestCase):
635651
_multiprocess_can_split_ = True
636652

0 commit comments

Comments
 (0)