Skip to content

Commit ce242f2

Browse files
committed
added doc-string
1 parent 43cc10b commit ce242f2

File tree

1 file changed

+41
-24
lines changed

1 file changed

+41
-24
lines changed

pandas/_libs/tslibs/conversion.pyx

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -392,23 +392,42 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz,
392392
return obj
393393

394394

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

413432

414433
cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
@@ -439,16 +458,14 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
439458
obj : _TSObject
440459
"""
441460
cdef:
442-
_TSObject obj
461+
npy_datetimestruct dts
462+
int64_t value # numpy dt64
443463
int out_local = 0, out_tzoffset = 0
444-
datetime dt
445464
bint do_parse_datetime_string = False
446465

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

450-
obj = _TSObject()
451-
452469
assert isinstance(ts, str)
453470

454471
if len(ts) == 0 or ts in nat_strings:
@@ -464,18 +481,18 @@ cdef _TSObject convert_str_to_tsobject(object ts, object tz, object unit,
464481
# equiv: datetime.today().replace(tzinfo=tz)
465482
else:
466483
string_to_dts_failed = _string_to_dts(
467-
ts, &obj.dts, &out_local,
484+
ts, &dts, &out_local,
468485
&out_tzoffset, False
469486
)
470487
try:
471488
if not string_to_dts_failed:
472-
check_dts_bounds(&obj.dts)
473-
obj.value = dtstruct_to_dt64(&obj.dts)
489+
check_dts_bounds(&dts)
490+
value = dtstruct_to_dt64(&dts)
474491
if out_local == 1:
475-
return setup_tsobject_tz_using_offset(obj, tz,
476-
out_tzoffset)
492+
return create_tsobject_tz_using_offset(value, tz,
493+
out_tzoffset)
477494
else:
478-
ts = obj.value
495+
ts = value
479496
if tz is not None:
480497
# shift for localize_tso
481498
ts = tz_localize_to_utc(np.array([ts], dtype='i8'), tz,

0 commit comments

Comments
 (0)