-
Notifications
You must be signed in to change notification settings - Fork 42
Closed
Description
cftime.date2num is returning a wrong result. See example below:
import cftime as cf
import pandas as pd
print('cftime version:', cf.__version__)
reftime = pd.to_datetime('2018-01-23 09:31:42.94')
t = pd.to_datetime('2018-01-23 09:27:10.950000')
# seconds since a reference time
cf_delta = cf.date2num(t.to_pydatetime(), f'seconds since {reftime}')
print('cftime date2num:', cf_delta)Output:
cftime version: 1.0.4.2
cftime date2num: -271.05The answer should be:
# using pandas timedelta calculation
pd_delta = (t - reftime).total_seconds()
print('pandas timedelta:', pd_delta)
# manual calculation
delta = (
(t.minute * 60 + t.second + t.microsecond * 1e-6) -
(reftime.minute * 60 + reftime.second + reftime.microsecond * 1e-6)
)
print('manual timedelta:', delta)Output:
pandas timedelta: -271.99
manual timedelta: -271.99Metadata
Metadata
Assignees
Labels
No labels