Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: there is no year 0 #55699

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading