Skip to content

Commit b7200a2

Browse files
committed
BUG: fix segfault of fold (pandas-dev#33931) - WIP
1 parent 6e04264 commit b7200a2

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

pandas/_libs/tslibs/c_timestamp.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cdef class _Timestamp(datetime):
99
int64_t value, nanosecond
1010
object freq
1111
list _date_attributes
12+
bint fold
1213
cpdef bint _get_start_end_field(self, str field)
1314
cpdef _get_date_name_field(self, object field, object locale)
1415
cdef int64_t _maybe_convert_value_to_local(self)

pandas/_libs/tslibs/c_timestamp.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ cdef class _Timestamp(datetime):
196196

197197
return datetime(self.year, self.month, self.day,
198198
self.hour, self.minute, self.second,
199-
self.microsecond, self.tzinfo)
199+
self.microsecond, self.tzinfo, fold=self.fold)
200200

201201
cpdef to_datetime64(self):
202202
"""

pandas/_libs/tslibs/timestamps.pyx

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ cdef inline object create_timestamp_from_ts(int64_t value,
4646
cdef _Timestamp ts_base
4747
ts_base = _Timestamp.__new__(Timestamp, dts.year, dts.month,
4848
dts.day, dts.hour, dts.min,
49-
dts.sec, dts.us, tz, fold=fold)
49+
dts.sec, dts.us, tz)
50+
ts_base.fold = fold
5051
ts_base.value = value
5152
ts_base.freq = freq
5253
ts_base.nanosecond = dts.ps // 1000
@@ -434,7 +435,7 @@ class Timestamp(_Timestamp):
434435
month is None and day is None and hour is None and
435436
minute is None and second is None and
436437
microsecond is None and nanosecond is None and
437-
tzinfo is None):
438+
tzinfo is None and fold is None):
438439
return ts_input
439440
elif isinstance(ts_input, str):
440441
# User passed a date string to parse.

pandas/tests/indexes/datetimes/test_constructors.py

+1
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ def test_timestamp_constructor_retain_fold(tz, fold):
10111011
result = ts.fold
10121012
expected = fold
10131013
assert result == expected
1014+
assert ts.to_pydatetime().fold == expected
10141015

10151016

10161017
@pytest.mark.parametrize("tz", ["dateutil/Europe/London"])

0 commit comments

Comments
 (0)