Description
Code Sample, a copy-pastable example if possible
I had a test fail in CI and the output looks like this:
______________________ TestTimestamp.test_class_ops_pytz _______________________
[gw1] linux -- Python 3.6.6 /home/travis/miniconda3/envs/pandas-dev/bin/python
self = <pandas.tests.scalar.timestamp.test_timestamp.TestTimestamp object at 0x7fb560287320>
def test_class_ops_pytz(self):
def compare(x, y):
assert int(Timestamp(x).value / 1e9) == int(Timestamp(y).value / 1e9)
compare(Timestamp.now(), datetime.now())
compare(Timestamp.now("UTC"), datetime.now(timezone("UTC")))
compare(Timestamp.utcnow(), datetime.utcnow())
> compare(Timestamp.today(), datetime.today())
pandas/tests/scalar/timestamp/test_timestamp.py:759:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = Timestamp('2020-01-21 03:19:15.998086')
y = datetime.datetime(2020, 1, 21, 3, 19, 16, 5328)
def compare(x, y):
> assert int(Timestamp(x).value / 1e9) == int(Timestamp(y).value / 1e9)
E AssertionError: assert 1579576755 == 1579576756
E + where 1579576755 = int((1579576755998086000 / 1000000000.0))
E + where 1579576755998086000 = Timestamp('2020-01-21 03:19:15.998086').value
E + where Timestamp('2020-01-21 03:19:15.998086') = Timestamp(Timestamp('2020-01-21 03:19:15.998086'))
E + and 1579576756 = int((1579576756005328000 / 1000000000.0))
E + where 1579576756005328000 = Timestamp('2020-01-21 03:19:16.005328').value
E + where Timestamp('2020-01-21 03:19:16.005328') = Timestamp(datetime.datetime(2020, 1, 21, 3, 19, 16, 5328))
Problem description
So due to "bad luck", the call to Timestamp.today()
was just before the next second that hit when datetime.now()
was called, making the comparison fail. I think the comparison should be:
int((Timestamp(x).value - Timestamp(y).value)/1.0e9) == 0
which would handle this round off error better.
Expected Output
No failure
Output of pd.show_versions()
pd.show_versions()
C:\Anaconda3\envs\pandas-dev\lib\site-packages\fastparquet\dataframe.py:5: Futur
eWarning: pandas.core.index is deprecated and will be removed in a future versio
n. The public classes are available in the top-level namespace.
from pandas.core.index import CategoricalIndex, RangeIndex, Index, MultiIndex
INSTALLED VERSIONS
commit : 8e4dfff
python : 3.7.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 13, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.0rc0+156.g8e4dfff71
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.1
pip : 19.3.1
setuptools : 42.0.2.post20191201
Cython : 0.29.14
pytest : 5.3.2
hypothesis : 4.57.1
sphinx : 2.3.1
blosc : None
feather : None
xlsxwriter : 1.2.7
lxml.etree : 4.4.2
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.10.1
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.1
fastparquet : 0.3.2
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.1.2
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.1
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pytest : 5.3.2
pyxlsb : None
s3fs : 0.4.0
scipy : 1.3.1
sqlalchemy : 1.3.12
tables : 3.6.1
tabulate : 0.8.6
xarray : 0.14.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.2.7
numba : 0.46.0