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

Conversation

jorisvandenbossche
Copy link
Member

Possibly a fix for #4229.

The rationale is that an array of strings should be handled in the same way as a list of strings (after applying np.asarray(list)), and I supposed that the list was handling the timezone correctly.

More in detail:

Because in the case of an array subarr is set as a DatetimeIndex (instead of as .values attribute of it => array of datetime64), the array is not localized to UTC (https://github.com/pydata/pandas/blob/master/pandas/tseries/index.py#L249) but assumed to be UTC. So, in fact, the tz keyword is ignored.

Something else: it is not completely clear what the tz keyword is supposed to do (it is not documented in the DatetimeIndex docstring). But I assumed it is to say that the given values to DatetimeIndex are in that timezone (and so the behaviour with a list is correct). However, it is also a little bit strange that eg to_datetime has not such of a keyword then.

PS: the PR is not ready (I want to add some tests, release notes, and there is too much whitespace in the commit), but I just wanted to submit it already to see if this makes sense.

@jreback
Copy link
Contributor

jreback commented Jul 13, 2013

change looks good
FYI usually I write the test first to make sure that a) test breaks as expected and b) code change fixes the problem

@jorisvandenbossche
Copy link
Member Author

@jreback I know that is the better order to do things, but I used the issue as a test

Regarding to adding the test, it seems like it could go in either test_timeseries.py (together with all other tests on DatetimeIndex construction tests) or test_timezones.py (together with all different tests dealing with timezones). Any preference to where I put it?

@jreback
Copy link
Contributor

jreback commented Jul 13, 2013

your choice (just put the issue number as a comment)

I try to group the tests with like tests - emphasis on try :)

@jorisvandenbossche
Copy link
Member Author

@jreback OK, I added test + release note.

@cpcloud
Copy link
Member

cpcloud commented Jul 14, 2013

@jorisvandenbossche can u rebase? thanks

@jorisvandenbossche
Copy link
Member Author

@cpcloud Done I think

jreback added a commit that referenced this pull request Jul 14, 2013
…st-array

BUG: initialize DatetimeIndex with array of strings (#4229)
@jreback jreback merged commit 35312e4 into pandas-dev:master Jul 14, 2013
@jorisvandenbossche jorisvandenbossche deleted the bug-datetimeindex-list-array branch July 14, 2013 19:22
@jreback
Copy link
Contributor

jreback commented Jul 14, 2013

thanks @jorisvandenbossche

@rockg
Copy link
Contributor

rockg commented Jul 14, 2013

Thank you very much @jorisvandenbossche and @jreback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants