BUG: initialize DatetimeIndex with array of strings (#4229) #4234
+24
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
data
subarr
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, thetz
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 egto_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.