Skip to content

BUG: initialize DatetimeIndex with array of strings (#4229) #4234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ pandas 0.12
- Fixed the legend displaying in ``DataFrame.plot(kind='kde')`` (:issue:`4216`)
- Fixed bug where Index slices weren't carrying the name attribute
(:issue:`4226`)
- Fixed bug in initializing ``DatetimeIndex`` with an array of strings
in a certain time zone (:issue:`4229`)

pandas 0.11.0
=============
Expand Down
4 changes: 3 additions & 1 deletion doc/source/v0.12.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ Bug Fixes
- Fixed the legend displaying in ``DataFrame.plot(kind='kde')`` (:issue:`4216`)
- Fixed bug where Index slices weren't carrying the name attribute
(:issue:`4226`)

- Fixed bug in initializing ``DatetimeIndex`` with an array of strings
in a certain time zone (:issue:`4229`)

See the :ref:`full release notes
<release>` or issue tracker
on GitHub for a complete list.
5 changes: 3 additions & 2 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,10 @@ def __new__(cls, data=None,
return data

if issubclass(data.dtype.type, basestring):
subarr = _str_to_dt_array(data, offset, dayfirst=dayfirst,
data = _str_to_dt_array(data, offset, dayfirst=dayfirst,
yearfirst=yearfirst)
elif issubclass(data.dtype.type, np.datetime64):

if issubclass(data.dtype.type, np.datetime64):
if isinstance(data, DatetimeIndex):
if tz is None:
tz = data.tz
Expand Down
16 changes: 16 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,22 @@ def test_index_drop_dont_lose_tz(self):

self.assertTrue(ind.tz is not None)

def test_datetimeindex_tz(self):
""" Test different DatetimeIndex constructions with timezone
Follow-up of #4229
"""

arr = ['11/10/2005 08:00:00', '11/10/2005 09:00:00']

idx1 = to_datetime(arr).tz_localize('US/Eastern')
idx2 = DatetimeIndex(start="2005-11-10 08:00:00", freq='H', periods=2, tz='US/Eastern')
idx3 = DatetimeIndex(arr, tz='US/Eastern')
idx4 = DatetimeIndex(np.array(arr), tz='US/Eastern')

for other in [idx2, idx3, idx4]:
self.assert_(idx1.equals(other))


class TestTimeZones(unittest.TestCase):
_multiprocess_can_split_ = True

Expand Down