-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: Deprecate casting of index of dates to DatetimeIndex #23598
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
Comments
We do hit this when concating two series with DTIs with different timezones (at this point we're an object-dtype Index with different tzs). But that raises anyway. It seems like tz-naive + tz-aware hits this, and actually goes through In [5]: a = pd.date_range('2000', periods=1, tz='US/Eastern')
In [6]: b = pd.date_range('2000', periods=1)
In [7]: pd.concat([pd.Series(1, a), pd.Series(2, b)])
> /Users/taugspurger/sandbox/pandas/pandas/core/series.py(355)_set_axis()
-> try:
(Pdb) c
Out[7]:
2000-01-01 00:00:00-05:00 1
2000-01-01 00:00:00 2
dtype: int64 But, presumably that's another opportunity for improving perf? We can fix this earlier in the |
Ignore that last bit about tz-aware and tz-naive. That returns an object-dtype index. |
Ohhhhhhh the dtype of the index depends on the order of arguments passed to concat. In [2]: a = pd.date_range('2000', periods=1, tz='US/Eastern')
In [3]: b = pd.date_range('2000', periods=1)
In [4]: pd.concat([pd.Series(1, a), pd.Series(2, b)]).index
> /Users/taugspurger/sandbox/pandas/pandas/core/series.py(355)_set_axis()
-> try:
(Pdb) c
Out[4]: Index([2000-01-01 00:00:00-05:00, 2000-01-01 00:00:00], dtype='object')
In [5]: pd.concat([pd.Series(1, b), pd.Series(2, a)]).index
> /Users/taugspurger/sandbox/pandas/pandas/core/series.py(355)_set_axis()
-> try:
(Pdb) c
Out[5]: DatetimeIndex(['1999-12-31 19:00:00-05:00', '2000-01-01 00:00:00-05:00'], dtype='datetime64[ns, US/Eastern]', freq=None) #23598 is related here (that's for union, this uses append) |
In the original issue, I agree that we keep preserve the object dtype in the series constructor. |
I think this is the main reason for Index.is_all_dates, so this would also allow #27744 |
This was the root cause of #23591. Why are we doing that?
Note that this doesn't affect the case of
index=[pd.Timestamp(...), pd.Timestamp(...)]
, as that would have previously been converted to a DatetimeIndex. It seems be only when you have an Index of datetimes.I'm going through our test cases that hit this now.
The text was updated successfully, but these errors were encountered: