question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

COMPAT: datetime.date comparisons with datetime64[ns]

See original GitHub issue

This should probably work

In [16]: df = pd.DataFrame({'A':[pd.Timestamp('20130101'), np.nan]})

In [17]: df
Out[17]: 
           A
0 2013-01-01
1        NaT

In [18]: pd.Timestamp('20130101').to_pydatetime()>=df.A
Out[18]: 
0     True
1    False
Name: A, dtype: bool

In [20]: pd.Timestamp('20130101').to_pydatetime().date()>=df.A
ValueError: cannot set a Timestamp with a non-timestamp

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jrebackcommented, Oct 26, 2017

These just need wrapping

In [7]: pd.Timestamp(datetime.date(2017, 10, 24)) < pd.Timestamp('2017-10-24 17:02')
Out[7]: True
0reactions
akrherzcommented, Nov 8, 2017

I think a MCVE for @liuli1735 's post is this

import pandas as pd
df = pd.DataFrame({'dates': pd.date_range('2000-01-01', '2010-12-31')})
date = df['dates'].unique()[0]
print(df.loc[df['dates'] == date])

Result with 0.20.3-py27_1 on conda-forge (linux64 python2.7)

$ python mcve.py 
       dates
0 2000-01-01

Result with 0.21.0-py27_0 on conda-forge (linux64 python2.7)

$ python mcve.py 
Traceback (most recent call last):
  File "mcve.py", line 5, in <module>
    print(df.loc[df['dates'] == date])
  File "/opt/miniconda2/lib/python2.7/site-packages/pandas/core/ops.py", line 879, in wrapper
    res = na_op(values, other)
  File "/opt/miniconda2/lib/python2.7/site-packages/pandas/core/ops.py", line 808, in na_op
    y = libindex.convert_scalar(x, _values_from_object(y))
  File "pandas/_libs/index.pyx", line 494, in pandas._libs.index.convert_scalar
  File "pandas/_libs/index.pyx", line 509, in pandas._libs.index.convert_scalar
ValueError: cannot set a Timestamp with a non-timestamp
Read more comments on GitHub >

github_iconTop Results From Across the Web

Comparison between datetime and datetime64[ns] in pandas
I'm writing a program that checks an excel file and if today's date is in the excel file's date column ...
Read more >
TypeError: Invalid comparison between dtype=datetime64[ns ...
Pandas : Python: TypeError: Invalid comparison between dtype= datetime64[ns ] and date [ Beautify Your Computer ...
Read more >
Time Series / Date functionality — pandas 0.23.0 documentation
to_datetime looks for standard designations of the datetime component in the column names, including: required: year , month , day; optional: hour , ......
Read more >
Datetimes and Timedeltas — NumPy v1.24 Manual
The most basic way to create datetimes is from strings in ISO 8601 date or datetime format. ... The datetime type works with...
Read more >
Python Datetime Vs. NumPy Datetime: 8 Differences You ...
Data Representation. Native Python and NumPy both follow different formats to store date-time attributes. The Python datetime format stores data as a group...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found