Code Sample, a copy-pastable example if possible
from io import StringIO
df = pd.read_csv(StringIO('''Date,A\n8/23/2017,a\n8/22/2017,b\n8/24/2017,c'''), parse_dates=['Date'])
print(df)
print(type(pd.datetime(2017, 8, 22).date()))
print(type(df['Date'][1]))
df_sub = df[df['Date'] == pd.datetime(2017, 8, 22).date()]
Error returned
Traceback (most recent call last):
File "<pyshell#72>", line 1, in <module>
df_sub = df[df['Date'] == pd.datetime(2017, 8, 22).date()]
File "C:\Python35\lib\site-packages\pandas\core\ops.py", line 877, in wrapper
res = na_op(values, other)
File "C:\Python35\lib\site-packages\pandas\core\ops.py", line 806, 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
Problem description
I just upgraded to pandas version '0.21.0rc1'. The df_sub
line above used to work in a prior version. Should a Timestamp
and a datetime.date
be comparable like it used to in a previous version? Not a huge issue for me but my intent is to just report it in-case it requires attention.
Expected Output
Date A
1 2017-08-22 b
Helpful Links
May be a similar or related issue: https://github.com/pandas-dev/pandas/issues/17965
convert_scalar
location: https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/index.pyx#L494
Output of pd.show_versions()
Comment From: jreback
closing as duplicate of #17965
Comment From: liuli1735
`temp = [] dates = data['TradingDay'].unique() for date in dates: print(date) raw_data = data.loc[data['TradingDay'] == date].copy()
ValueError: cannot set a Timestamp with a non-timestamp`
I get the same error, i just upgrade my Anaconda yesterday.