-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: int origin treated as nanoseconds since epoch time #54788
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
Comments
Sort of related (but happy to open a second issue if preferred), but Timestamp-able origins cause rounding differences: In [4]: origin = datetime.datetime(2023, 1, 1)
...
In [14]: pandas.to_datetime(pandas_df["float_col"], unit=unit)
Out[14]:
0 1970-01-01 00:00:00.000000091
1 1970-01-01 00:00:00.000000083
2 1970-01-01 00:00:00.000000025
3 1970-01-01 00:00:00.000000029
4 1970-01-01 00:00:00.000000018
5 1970-01-01 00:00:00.000000023
6 1970-01-01 00:00:00.000000034
7 1970-01-01 00:00:00.000000059
8 1970-01-01 00:00:00.000000036
9 1970-01-01 00:00:00.000000078
Name: float_col, dtype: datetime64[ns]
In [15]: pandas.to_datetime(pandas_df["float_col"], unit=unit, origin=origin)
Out[15]:
0 2023-01-01
1 2023-01-01
2 2023-01-01
3 2023-01-01
4 2023-01-01
5 2023-01-01
6 2023-01-01
7 2023-01-01
8 2023-01-01
9 2023-01-01
Name: float_col, dtype: datetime64[ns] also happens with Timestamp objects: In [22]: origin = pandas.Timestamp("01/01/2023")
In [23]: pandas.to_datetime(pandas_df["float_col"], unit=unit, origin=origin)
Out[23]:
0 2023-01-01
1 2023-01-01
2 2023-01-01
3 2023-01-01
4 2023-01-01
5 2023-01-01
6 2023-01-01
7 2023-01-01
8 2023-01-01
9 2023-01-01
Name: float_col, dtype: datetime64[ns]
In [24]: pandas.to_datetime(pandas_df["float_col"], unit=unit)
Out[24]:
0 1970-01-01 00:00:00.000000091
1 1970-01-01 00:00:00.000000083
2 1970-01-01 00:00:00.000000025
3 1970-01-01 00:00:00.000000029
4 1970-01-01 00:00:00.000000018
5 1970-01-01 00:00:00.000000023
6 1970-01-01 00:00:00.000000034
7 1970-01-01 00:00:00.000000059
8 1970-01-01 00:00:00.000000036
9 1970-01-01 00:00:00.000000078
Name: float_col, dtype: datetime64[ns]
In [25]: origin = pandas.Timestamp("01/01/2023 00:00:00.000000000")
In [26]: pandas.to_datetime(pandas_df["float_col"], unit=unit, origin=origin)
Out[26]:
0 2023-01-01
1 2023-01-01
2 2023-01-01
3 2023-01-01
4 2023-01-01
5 2023-01-01
6 2023-01-01
7 2023-01-01
8 2023-01-01
9 2023-01-01
Name: float_col, dtype: datetime64[ns]
In [27]: pandas.to_datetime(pandas_df["float_col"], unit=unit)
Out[27]:
0 1970-01-01 00:00:00.000000091
1 1970-01-01 00:00:00.000000083
2 1970-01-01 00:00:00.000000025
3 1970-01-01 00:00:00.000000029
4 1970-01-01 00:00:00.000000018
5 1970-01-01 00:00:00.000000023
6 1970-01-01 00:00:00.000000034
7 1970-01-01 00:00:00.000000059
8 1970-01-01 00:00:00.000000036
9 1970-01-01 00:00:00.000000078
Name: float_col, dtype: datetime64[ns] |
1 task
Hi! I’m Shivani Kasaudhan, a beginner in open source. I’d love to work on this issue as my first contribution to Pandas. Could you please assign it to me? 😊 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Pandas version checks
Reproducible Example
Issue Description
The documentation for pandas v2.0.3 state that an int or float origin will be treated as milliseconds and added to the epoch time, but seems like its being treated as nanoseconds? Not sure if this is a bug, or a typo in the documentation!
Expected Behavior
The resulting timestamp for
pd.to_datetime(0, origin=1)
should be equivalent topd.to_datetime(1, unit="ms")
.Installed Versions
INSTALLED VERSIONS
commit : 0f43794
python : 3.8.17.final.0
python-bits : 64
OS : Darwin
OS-release : 21.3.0
Version : Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.3
numpy : 1.24.4
pytz : 2023.3
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : None
pytest : 7.4.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.12.2
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2023.6.0
gcsfs : None
matplotlib : 3.7.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 10.0.1
pyreadstat : None
pyxlsb : None
s3fs : 0.4.2
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: