Code Sample, a copy-pastable example if possible
# Your code here
import pandas as pd
import numpy as np
# create a dateframe with a column "duration", which contains timedelta of 5 minutes
p=pd.DataFrame({"duration":[np.timedelta64(5, "m")]})
# compare this column with timedelta of 4 minutes
p.duration<np.timedelta64(4, "m")
#this should result in a series of one bool which is false.
Problem description
When you try to compare a column of np.timedelta64 with a single np.timedelta64, version 0.22.0 throws
ValueError: cannot set a Timedelta with a non-timedelta
This worked in previous version 0.20.3 and returned the correct series of bools
Expected Output
This is the output as of version 0.20.3
0 False Name: duration, dtype: bool
Output of pd.show_versions()
Comment From: jreback
this is as expected. a np.timedelta64
is unit less so the comparison doesn't make sense. you can use np.timedelta64(1, 'ns')
or whatever unit, or more idiomatic a pd.Timedelta
Comment From: DavidTolan
@jreback If you look at the code I am comparing the data in the column which is np.timedelta64(5, "m") with np.timedelta64(4, "m") this is NOT unit less. Again, this worked in 0.20.3 the comparison is meaningful 4 minutes is less than 5 minutes.
Comment From: jreback
I c. actually this is not working on 0.22, but is in master (0.23.0 coming soon). this has had extensive refactoring.
Comment From: DavidTolan
Cool. I had a quick look at the source code & decided it was not a 10 second fix 🤔