-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Summing nanoseconds time delta to timestamp #43764
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
To clarify a bit more, you can create a pandas Timedelta with nanoseconds specified; td = pd.Timedelta(nanoseconds=1)
print(td.seconds, td.microseconds, td.nanoseconds)
# 0 0 1 You can also specify a certain number of microseconds by providing the microseconds as fractional seconds: td = pd.Timedelta(seconds=1e-6)
print(td.seconds, td.microseconds, td.nanoseconds)
# 0 1 0 However what does not work is specifying nanoseconds like this: td = pd.Timedelta(seconds=1e-9)
print(td.seconds, td.microseconds, td.nanoseconds)
# 0 0 0 So the point here to me is: everything that pandas Timedelta inherited from Python's timedelta works as expected. But when it comes to the additional feature, the nanoseconds attribute, a correct conversion from some inputs seems to be missing.
|
First off I'm guessing you want Could take a PR either a) raising if a non-integer is passed to Timedelta (depends on how much that check affects perf) or b) documenting this requirement |
this is a duplicate issue |
@jbrockmendel fixed the typo.
This is not consistent with:
|
@jreback would not surprise me - but I couldn't find an exact dupe by searching the issues (also not knowing where exactly the described behavior originates from). If you have one in mind, please share. potentially related: |
Take |
@mroeschke @jbrockmendel @jreback would it be ok if I solve this issue together with #40946 in one PR? |
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 master branch of pandas.
Reproducible Example
Issue Description
Adding
Timedelta
s that have nanoseconds defined as a float do not work properly for timedelta values in the [1-999] range.This report is a result of this SO question
Expected Behavior
all([pd.Timestamp(1000 + x) == (pd.Timedelta(seconds=x*1e-9) + pd.Timestamp(1000)) for x in range(1000)])
should beTrue
Or any equivalent not using the explicit default nanoseconds unit or the
nanoseconds
keyword as in:pd.Timedelta(1)
orpd.Timedelta(nanoseconds=1)
Installed Versions
INSTALLED VERSIONS
commit : c7f7443
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.1
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.2
setuptools : 49.6.0.post20210108
Cython : None
pytest : 6.2.4
hypothesis : None
sphinx : 4.0.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.24.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.1
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: