-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: remove always-UTC arg from tz_convert, tz_convert_single #35154
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 18 commits
30c4348
02517fc
830c4bd
6bc6570
7f7350b
92cada7
6e9afd7
617ab79
9b39dbf
7a9d5cc
55be9e9
b389653
c4309b6
e1507dd
8b06a50
5fc5bc6
e25e292
865344f
6c17135
4110fb3
c197d03
1855e7f
b928b54
4305c90
37a5796
4757798
6399998
99e29af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,93 +366,69 @@ cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz, bint* fold=NU | |
return _tz_convert_tzlocal_utc(utc_val, tz, to_utc=False, fold=fold) | ||
|
||
|
||
cpdef int64_t tz_convert_single(int64_t val, tzinfo tz1, tzinfo tz2): | ||
cpdef int64_t tz_convert_single(int64_t val, tzinfo tz): | ||
""" | ||
Convert the val (in i8) from timezone1 to timezone2 | ||
Convert the val (in i8) from UTC to tz | ||
|
||
This is a single timezone version of tz_convert | ||
|
||
Parameters | ||
---------- | ||
val : int64 | ||
tz1 : tzinfo | ||
tz2 : tzinfo | ||
tz : tzinfo | ||
|
||
Returns | ||
------- | ||
converted: int64 | ||
""" | ||
cdef: | ||
int64_t arr[1] | ||
bint to_utc = is_utc(tz2) | ||
tzinfo tz | ||
|
||
# See GH#17734 We should always be converting either from UTC or to UTC | ||
assert is_utc(tz1) or to_utc | ||
|
||
if val == NPY_NAT: | ||
return val | ||
|
||
if to_utc: | ||
tz = tz1 | ||
else: | ||
tz = tz2 | ||
|
||
if is_utc(tz): | ||
return val | ||
elif is_tzlocal(tz): | ||
return _tz_convert_tzlocal_utc(val, tz, to_utc=to_utc) | ||
return _tz_convert_tzlocal_utc(val, tz, to_utc=False) | ||
else: | ||
arr[0] = val | ||
return _tz_convert_dst(arr, tz, to_utc=to_utc)[0] | ||
return _tz_convert_dst(arr, tz)[0] | ||
|
||
|
||
def tz_convert(int64_t[:] vals, tzinfo tz1, tzinfo tz2): | ||
def tz_convert(int64_t[:] vals, tzinfo tz): | ||
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. Could we rename this 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. sure i guess |
||
""" | ||
Convert the values (in i8) from timezone1 to timezone2 | ||
Convert the values (in i8) from UTC to tz | ||
|
||
Parameters | ||
---------- | ||
vals : int64 ndarray | ||
tz1 : tzinfo | ||
tz2 : tzinfo | ||
tz : tzinfo | ||
|
||
Returns | ||
------- | ||
int64 ndarray of converted | ||
""" | ||
cdef: | ||
int64_t[:] converted | ||
bint to_utc = is_utc(tz2) | ||
tzinfo tz | ||
|
||
# See GH#17734 We should always be converting from UTC; otherwise | ||
# should use tz_localize_to_utc. | ||
assert is_utc(tz1) | ||
|
||
if len(vals) == 0: | ||
return np.array([], dtype=np.int64) | ||
|
||
if to_utc: | ||
tz = tz1 | ||
else: | ||
tz = tz2 | ||
|
||
converted = _tz_convert_one_way(vals, tz, to_utc=to_utc) | ||
converted = _tz_convert_one_way(vals, tz) | ||
return np.array(converted, dtype=np.int64) | ||
|
||
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc): | ||
cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz): | ||
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. let's rename this too 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. updated+green |
||
""" | ||
Convert the given values (in i8) either to UTC or from UTC. | ||
|
||
Parameters | ||
---------- | ||
vals : int64 ndarray | ||
tz1 : tzinfo | ||
to_utc : bool | ||
tz : tzinfo | ||
|
||
Returns | ||
------- | ||
|
@@ -472,9 +448,9 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc): | |
if val == NPY_NAT: | ||
converted[i] = NPY_NAT | ||
else: | ||
converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc) | ||
converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc=False) | ||
else: | ||
converted = _tz_convert_dst(vals, tz, to_utc) | ||
converted = _tz_convert_dst(vals, tz) | ||
|
||
return converted | ||
|
||
|
@@ -565,9 +541,7 @@ cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=True, | |
|
||
@cython.boundscheck(False) | ||
@cython.wraparound(False) | ||
cdef int64_t[:] _tz_convert_dst( | ||
const int64_t[:] values, tzinfo tz, bint to_utc=True, | ||
): | ||
cdef int64_t[:] _tz_convert_dst(const int64_t[:] values, tzinfo tz): | ||
""" | ||
tz_convert for non-UTC non-tzlocal cases where we have to check | ||
DST transitions pointwise. | ||
|
@@ -576,8 +550,6 @@ cdef int64_t[:] _tz_convert_dst( | |
---------- | ||
values : ndarray[int64_t] | ||
tz : tzinfo | ||
to_utc : bool | ||
True if converting _to_ UTC, False if converting _from_ utc | ||
|
||
Returns | ||
------- | ||
|
@@ -607,10 +579,7 @@ cdef int64_t[:] _tz_convert_dst( | |
if v == NPY_NAT: | ||
result[i] = v | ||
else: | ||
if to_utc: | ||
result[i] = v - delta | ||
else: | ||
result[i] = v + delta | ||
result[i] = v + delta | ||
|
||
else: | ||
# Previously, this search was done pointwise to try and benefit | ||
|
@@ -629,9 +598,6 @@ cdef int64_t[:] _tz_convert_dst( | |
# it elsewhere? | ||
raise ValueError("First time before start of DST info") | ||
|
||
if to_utc: | ||
result[i] = v - deltas[pos[i]] | ||
else: | ||
result[i] = v + deltas[pos[i]] | ||
result[i] = v + deltas[pos[i]] | ||
|
||
return result |
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.
is this still required?
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.
updated