Skip to content

Commit

Permalink
issue pandas-dev#55462 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
u7481676 committed Oct 26, 2023
1 parent e0d6051 commit 541c3b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 541c3b3

Please sign in to comment.