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 or as expected/designed?: Generating and calculation with timestamps out of bound? #52091

Open
2 of 3 tasks
kaibir opened this issue Mar 20, 2023 · 1 comment
Open
2 of 3 tasks
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution

Comments

@kaibir
Copy link

kaibir commented Mar 20, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import pytest

t=pd.Timestamp("010120")
print(t.unit)
print(t.min, type(t.min))
print(t.max, type(t.max))

t2=pd.Timestamp(2020,1,1)
print(t2.unit)
print(t2.min, type(t2.min))
print(t2.max, type(t2.max))


with pytest.raises(ValueError):
    pd.Timestamp(10000,1,1)

Issue Description

While preparing our code for Pandas 2, we noticed the following:

1. Different ways of Timestamp creation ends up in a different timestamp unit

pd.Timestamp("010120") -> Timestamp('2020-01-01 00:00:00') with unit = 's'
pd.Timestamp(2020, 1, 1) -> Timestamp('2020-01-01 00:00:00') with `unit = 'us'

Moreover I could create Timestamps, which I cannot reproduce with using pd.Timestamp.

Let us take the first timestamp from above:

t = pd.Timestamp("010120")
tmax = t.max

We get tmax = Timestamp('292277026596-12-04 15:30:07') where it is at least not possible to create a Timestamp with a year greater than 9999.

t_impossible = pd.Timestamp(10000,1,1)

lead to

ValueError                                Traceback (most recent call last)
Cell In[29], line 1
----> 1 pd.Timestamp(10000,1,1)

File ~/venv/myvenv/lib/python3.10/site-packages/pandas/_libs/tslibs/timestamps.pyx:1645, in pandas._libs.tslibs.timestamps.Timestamp.__new__()

ValueError: year 10000 is out of range

I even cannot count on a timestamp that is outside the max values (pd.Timestamp.max = Timestamp('2262-04-11 23:47:16.854775807') and pd.Timestamp.min = Timestamp('1677-09-21 00:12:43.145224193'))

To what extent is the behaviour intentional or erroneous?

With pandas 1.5.3 it was not possible to create timestamps greater than pd.Timestamp.max due to its ns-representation.

Expected Behavior

I don't know if it is even a bug, but I would expect, that I can create timestamp (e.g. year > 10000) and that I can calculate with timestamps (e.g. 2300-01-01 + 100 days) [ not in every unit, but if the unit allows it, why not?

Installed Versions

INSTALLED VERSIONS

python : 3.10.2.final.0
python-bits : 64
OS : Darwin
OS-release : 22.1.0
Version : Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.UTF-8

pandas : 2.0.0rc1
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.6.3
pip : 22.3.1
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : 2.9.5
jinja2 : 3.1.2
IPython : 8.7.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.11.0
gcsfs : 2022.11.0
matplotlib : 3.6.2
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : 1.4.45
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

@kaibir kaibir added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 20, 2023
@kaibir kaibir changed the title BUG?: Generating timestamps and calculation? BUG or as expected/designed?: Generating timestamps and calculation? Mar 20, 2023
@MarcoGorelli MarcoGorelli added Non-Nano datetime64/timedelta64 with non-nanosecond resolution and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 20, 2023
@MarcoGorelli
Copy link
Member

Hey @kaibir ,

thanks for the report, this looks like a bug

@kaibir kaibir changed the title BUG or as expected/designed?: Generating timestamps and calculation? BUG or as expected/designed?: Generating and calculation with timestamps out of bound? Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants