-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
API/BUG: Enforce "normalized" pytz timezones for DatetimeIndex #20510
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
Changes from 1 commit
b878540
0b0fb83
8316501
0bb1b13
4d6f0d1
4a202b0
29560c4
87cacf8
e8990fc
b1f2724
c1241f9
9833f01
43fab89
f1a5ca7
bba5da5
8b397d4
464a91b
c1db598
bf1ec9e
81ccb21
12f697b
867ef19
360c295
67a29d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -649,6 +649,7 @@ def _simple_new(cls, values, name=None, freq=None, tz=None, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result.name = name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result.offset = freq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result._tz = timezones.maybe_get_tz(tz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result._tz = timezones.tz_standardize(result._tz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result._reset_identity() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -678,10 +679,16 @@ def _values(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self.values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@cache_readonly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def tz(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# GH 18595 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i believe we now have this in setter / getter versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, the only caching decorator I could find was implemented here: pandas/pandas/_libs/properties.pyx Lines 9 to 44 in c7af4ae
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return timezones.tz_standardize(self._tz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return self._tz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@tz.setter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def tz(self, value): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# GH 3746: Prevent localizing or converting the index by setting tz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise AttributeError("Cannot directly set timezone. Use tz_localize() " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"or tz_convert() as appropriate") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def tzinfo(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -753,7 +760,7 @@ def _cached_range(cls, start=None, end=None, periods=None, offset=None, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cachedRange = DatetimeIndex._simple_new(arr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cachedRange.offset = offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cachedRange._tz = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cachedRange = cachedRange.tz_localize(None) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cachedRange.name = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
drc[offset] = cachedRange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -830,7 +837,7 @@ def __setstate__(self, state): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.name = own_state[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.offset = own_state[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._tz = own_state[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._tz = timezones.tz_standardize(own_state[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# provide numpy < 1.7 compat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if nd_state[2] == 'M8[us]': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1174,7 +1181,7 @@ def union(self, other): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result = Index.union(this, other) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if isinstance(result, DatetimeIndex): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result._tz = this.tz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result._tz = timezones.tz_standardize(this.tz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (result.freq is None and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(this.freq is not None or other.freq is not None)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
result.offset = to_offset(result.inferred_freq) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -1222,7 +1229,7 @@ def union_many(self, others): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tz = this.tz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this = Index.union(this, other) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if isinstance(this, DatetimeIndex): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this._tz = tz | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this._tz = timezones.tz_standardize(tz) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if this.freq is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
this.offset = to_offset(this.inferred_freq) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
same here