@@ -1237,7 +1237,7 @@ cdef class _Timestamp(ABCTimestamp):
1237
1237
1238
1238
# -----------------------------------------------------------------
1239
1239
# Transformation Methods
1240
-
1240
+
1241
1241
def normalize(self) -> "Timestamp":
1242
1242
"""
1243
1243
Normalize Timestamp to midnight, preserving tz information.
@@ -1264,14 +1264,27 @@ cdef class _Timestamp(ABCTimestamp):
1264
1264
Timestamp(' 2020-03-14 00:00:00' )
1265
1265
"""
1266
1266
cdef:
1267
- local_val = self._maybe_convert_value_to_local()
1268
- int64_t normalized
1269
- int64_t ppd = periods_per_day(self._creso)
1270
- _Timestamp ts
1271
-
1272
- normalized = normalize_i8_stamp(local_val, ppd)
1273
- ts = type(self)._from_value_and_reso(normalized, reso=self._creso, tz=None)
1274
- return ts.tz_localize(self.tzinfo)
1267
+ local_val = self._maybe_convert_value_to_local()
1268
+ int64_t normalized
1269
+ int64_t ppd = periods_per_day(self._creso)
1270
+ _Timestamp ts
1271
+
1272
+ # Check for potential overflow before normalization
1273
+ if local_val < INT64_MIN or local_val > INT64_MAX:
1274
+ raise OutOfBoundsDatetime(
1275
+ f"Cannot normalize Timestamp {self} without overflow"
1276
+ )
1277
+
1278
+ normalized = normalize_i8_stamp(local_val, ppd)
1279
+
1280
+ # Additional overflow check after normalization
1281
+ if normalized < INT64_MIN or normalized > INT64_MAX:
1282
+ raise OutOfBoundsDatetime(
1283
+ f"Normalization of {self} would cause an overflow"
1284
+ )
1285
+
1286
+ ts = type(self)._from_value_and_reso(normalized, reso=self._creso, tz=None)
1287
+ return ts.tz_localize(self.tzinfo)
1275
1288
1276
1289
# -----------------------------------------------------------------
1277
1290
# Pickle Methods
0 commit comments