From 541c3b3ee819bc64a7d1bc4fb45c4696dce8ce2b Mon Sep 17 00:00:00 2001 From: Kai Crosby Date: Thu, 26 Oct 2023 14:45:35 +1100 Subject: [PATCH] issue #55462 fix --- pandas/_libs/tslibs/timestamps.pyx | 5 ++++- pandas/core/tools/datetimes.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 66b1cec63e9e9..fb40630a56cf2 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -315,7 +315,10 @@ cdef class _Timestamp(ABCTimestamp): def __hash__(_Timestamp self): if self.nanosecond: return hash(self._value) - if not (1 <= self.year <= 9999): + if (self.year == 0): + year = -1 + return hash(self._value) + if not (-9999 <= self.year <= 9999): # out of bounds for pydatetime return hash(self._value) if self.fold: diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index e23bf6269893d..654cb8a162dcc 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -1098,6 +1098,9 @@ def to_datetime( result: Timestamp | NaTType | Series | Index if isinstance(arg, Timestamp): + if arg.year <= 0: + year_ = abs(arg.year-1) + return Timestamp(year=year_,month=arg.month,day=arg.day) result = arg if utc: if arg.tz is not None: