Skip to content

Commit 65c41bc

Browse files
committed
added doc-string
1 parent c9d9fb2 commit 65c41bc

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

pandas/_libs/tslibs/conversion.pyx

+41-24
Original file line numberDiff line numberDiff line change
@@ -393,23 +393,42 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
393393
return obj
394394

395395

396-
cdef _TSObject setup_tsobject_tz_using_offset(_TSObject obj,
397-
object tz, int tzoffset):
398-
obj.tzinfo = pytz.FixedOffset(tzoffset)
399-
obj.value = tz_convert_single(obj.value, obj.tzinfo, UTC)
396+
cdef _TSObject create_tsobject_tz_using_offset(int64_t value,
397+
object tz, int tzoffset):
398+
"""
399+
Create tsobject from numpy datetime64 using initial timezone offset
400+
401+
Parameters
402+
----------
403+
value: int64_t
404+
numpy dt64
405+
tz : tzinfo or None
406+
timezone for the timezone-aware output.
407+
tzoffset: int
408+
409+
Returns
410+
obj : _TSObject
411+
-------
412+
413+
"""
414+
cdef:
415+
_TSObject obj
416+
datetime dt
417+
418+
tzinfo = pytz.FixedOffset(tzoffset)
419+
value = tz_convert_single(value, tzinfo, UTC)
420+
obj = convert_to_tsobject(value, tzinfo, None, 0, 0)
400421
if tz is None:
401422
check_overflows(obj)
402423
return obj
403-
else:
404-
# Keep the converter same as PyDateTime's
405-
obj = convert_to_tsobject(obj.value, obj.tzinfo,
406-
None, 0, 0)
407-
dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
408-
obj.dts.hour, obj.dts.min, obj.dts.sec,
409-
obj.dts.us, obj.tzinfo)
410-
obj = convert_datetime_to_tsobject(
411-
dt, tz, nanos=obj.dts.ps // 1000)
412-
return obj
424+
425+
# Keep the converter same as PyDateTime's
426+
dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
427+
obj.dts.hour, obj.dts.min, obj.dts.sec,
428+
obj.dts.us, obj.tzinfo)
429+
obj = convert_datetime_to_tsobject(
430+
dt, tz, nanos=obj.dts.ps // 1000)
431+
return obj
413432

414433

415434
cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
@@ -440,16 +459,14 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
440459
obj : _TSObject
441460
"""
442461
cdef:
443-
_TSObject obj
462+
npy_datetimestruct dts
463+
int64_t value # numpy dt64
444464
int out_local = 0, out_tzoffset = 0
445-
datetime dt
446465
bint do_parse_datetime_string = False
447466

448467
if tz is not None:
449468
tz = maybe_get_tz(tz)
450469

451-
obj = _TSObject()
452-
453470
assert isinstance(ts, str)
454471

455472
if len(ts) == 0 or ts in nat_strings:
@@ -465,18 +482,18 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
465482
# equiv: datetime.today().replace(tzinfo=tz)
466483
else:
467484
string_to_dts_failed = _string_to_dts(
468-
ts, &obj.dts, &out_local,
485+
ts, &dts, &out_local,
469486
&out_tzoffset, False
470487
)
471488
try:
472489
if not string_to_dts_failed:
473-
check_dts_bounds(&obj.dts)
474-
obj.value = dtstruct_to_dt64(&obj.dts)
490+
check_dts_bounds(&dts)
491+
value = dtstruct_to_dt64(&dts)
475492
if out_local == 1:
476-
return setup_tsobject_tz_using_offset(obj, tz,
477-
out_tzoffset)
493+
return create_tsobject_tz_using_offset(value, tz,
494+
out_tzoffset)
478495
else:
479-
ts = obj.value
496+
ts = value
480497
if tz is not None:
481498
# shift for localize_tso
482499
ts = tz_localize_to_utc(np.array([ts], dtype='i8'), tz,

0 commit comments

Comments
 (0)