-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: tz info lost by set_index and reindex #7092
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
Conversation
fill_value=unique_vals._na_value)) | ||
values.name = self.names[num] | ||
filled = com.take_1d(unique_vals.values, labels, fill_value=unique_vals._na_value) | ||
if isinstance(unique_vals, DatetimeIndex): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can simply do:
values = Index(filled, freq=getattr(unique_vals,'freq',None), tz=getattr(unique_vals,'tz',None, name = self.names[num])
instead of the if/elsif (and don't need to import)
Index will infer the type will is more pythonic here (and the additional args will not be passed on)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. PeriodIndex
can work but DatetimeIndex
doesn't. Because values are once converted to ndarray
, Index
performs tz conversion once again and results in incorrect output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm
worth creating a _simple_new for Index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it will be an option. Otherwise make DatetimeIndex
to support np.datetime64
timezone...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no don't use the tz of np.datetime64 totally broken
OK, added |
gr8! thanks |
BUG: tz info lost by set_index and reindex
Closes #6631. Closes #5878. Regarding #3950, original problem can be fixed by this, but
groupby
problem isn't.Also, this includes the fix for
MultiIndex.get_level_values
doesn't retaintz
andfreq
, as the method is used inset_index
.