Skip to content

PERF: regression fixup for timestamp.TimestampConstruction.time_parse_iso8601_tz benchmark #26334

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

Merged
merged 1 commit into from
May 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,15 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
return obj


cdef _TSObject create_tsobject_tz_using_offset(int64_t value,
cdef _TSObject create_tsobject_tz_using_offset(npy_datetimestruct dts,
int tzoffset, object tz=None):
"""
Convert a numpy datetime64 `value`, along with initial timezone offset
Convert a datetimestruct `dts`, along with initial timezone offset
`tzoffset` to a _TSObject (with timezone object `tz` - optional).

Parameters
----------
value: int64_t
numpy dt64
dts: npy_datetimestruct
tzoffset: int
tz : tzinfo or None
timezone for the timezone-aware output.
Expand All @@ -411,12 +410,14 @@ cdef _TSObject create_tsobject_tz_using_offset(int64_t value,
obj : _TSObject
"""
cdef:
_TSObject obj
_TSObject obj = _TSObject()
int64_t value # numpy dt64
datetime dt

tzinfo = pytz.FixedOffset(tzoffset)
value = tz_convert_single(value, tzinfo, UTC)
obj = convert_to_tsobject(value, tzinfo, None, 0, 0)
value = dtstruct_to_dt64(&dts)
obj.dts = dts
obj.tzinfo = pytz.FixedOffset(tzoffset)
obj.value = tz_convert_single(value, obj.tzinfo, UTC)
if tz is None:
check_overflows(obj)
return obj
Expand Down Expand Up @@ -459,7 +460,6 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
"""
cdef:
npy_datetimestruct dts
int64_t value # numpy dt64
int out_local = 0, out_tzoffset = 0
bint do_parse_datetime_string = False

Expand Down Expand Up @@ -487,12 +487,11 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
try:
if not string_to_dts_failed:
check_dts_bounds(&dts)
value = dtstruct_to_dt64(&dts)
if out_local == 1:
return create_tsobject_tz_using_offset(value,
return create_tsobject_tz_using_offset(dts,
out_tzoffset, tz)
else:
ts = value
ts = dtstruct_to_dt64(&dts)
if tz is not None:
# shift for localize_tso
ts = tz_localize_to_utc(np.array([ts], dtype='i8'), tz,
Expand Down