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 #55462

Open
jbrockmendel opened this issue Oct 9, 2023 · 8 comments
Open

BUG: there is no year 0 #55462

jbrockmendel opened this issue Oct 9, 2023 · 8 comments
Assignees
Labels
Datetime Datetime data dtype Needs Discussion Requires discussion from core team before further action

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Oct 9, 2023

ts = pd.Timestamp("001-01-01")
td = pd.Timedelta(days=1).as_unit("s")

>>> ts - td
Timestamp('0-12-31 00:00:00')
>>> (ts - td).year
0

We document in a few places that we are using the Proleptic Gregorian calendar which does not have a year 0. The year before 1AD is 1BC in this calendar.

np.datetime64 objects have the same behavior (cc @sberg)

Expected Behavior

Refuse to parse year 0, create a Timestamp with year=0, subtraction skips year 0.

Or document the current behavior.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 9, 2023
@Kman303
Copy link

Kman303 commented Oct 10, 2023

I'd like to try and fix this bug, if I could get the issue assigned to me

@jbrockmendel
Copy link
Member Author

I'd advise against working on this until there is consensus on how to address the issue.

@jorisvandenbossche
Copy link
Member

FWIW, Arrow has the same behaviour as numpy:

In [9]: pc.subtract(pa.array([pd.Timestamp("001-01-01")]), pa.array([pd.Timedelta(days=1)]))
Out[9]: 
<pyarrow.lib.TimestampArray object at 0x7fd268b57e80>
[
  0000-12-31 00:00:00.000000
]

@jorisvandenbossche
Copy link
Member

Quoting the linked wiki page:

For these calendars one can distinguish two systems of numbering years BC. Bede and later historians did not enumerate any year as zero (nulla in Latin; see Year zero); therefore the year preceding AD 1 is 1 BC. In this system the year 1 BC is a leap year (likewise in the proleptic Julian calendar). Mathematically, it is more convenient to include a year 0 and represent earlier years as negative numbers for the specific purpose of facilitating the calculation of the number of years between a negative (BC) year and a positive (AD) year. This is the convention in astronomical year numbering and the international standard date system, ISO 8601. In these systems, the year 0 is a leap year.[4]

So this mentions that the "the international standard date system, ISO 8601" uses a year zero. And in the end, one could also say that what we see in the output above is an ISO8601 formatted timestamp?

@Kman303
Copy link

Kman303 commented Oct 26, 2023

take

Kman303 pushed a commit to Kman303/pandas that referenced this issue Oct 26, 2023
@Kman303 Kman303 mentioned this issue Oct 26, 2023
2 tasks
@jorisvandenbossche jorisvandenbossche added Datetime Datetime data dtype Needs Discussion Requires discussion from core team before further action and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 26, 2023
@jorisvandenbossche
Copy link
Member

@Kman303 as @jbrockmendel mentioned above, there is not yet a clear resolution about what exactly needs to be done

@jbrockmendel
Copy link
Member Author

I like Joris's current-behavior-is-fine approach.

@miccoli
Copy link
Contributor

miccoli commented Dec 26, 2023

As already commented by @jorisvandenbossche current behaviour is expected.

Numpy docs 1 clarify datetime64 semantics listing the conventions adopted, namely

  • proleptic Gregorian calendar,
  • astronomical year numbering
  • 86400 seconds per day (POSIX semantics)

It seems to me that it would be safe to simply make a reference in the pandas docs to the numpy ones.

Footnotes

  1. https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime64-conventions-and-assumptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Needs Discussion Requires discussion from core team before further action
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants