I have the following two arrays of datetimes:
datesA:
datesA
array([datetime.datetime(2000, 1, 4, 0, 0),
datetime.datetime(2000, 1, 5, 0, 0),
datetime.datetime(2000, 1, 6, 0, 0),
datetime.datetime(2000, 1, 7, 0, 0),
datetime.datetime(2000, 1, 8, 0, 0),
datetime.datetime(2000, 1, 9, 0, 0),
datetime.datetime(2000, 1, 10, 0, 0),
datetime.datetime(2000, 1, 11, 0, 0),
datetime.datetime(2000, 1, 12, 0, 0)], dtype=object)
And datesB:
datesB
array([datetime.datetime(2000, 1, 4, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 5, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 6, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 7, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 10, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 11, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 12, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 13, 0, 0, tzinfo=<UTC>),
datetime.datetime(2000, 1, 14, 0, 0, tzinfo=<UTC>)], dtype=object)
I want to find the dates in datesA that are NOT in datesB. Using ~isin()
like below returns True for all rows instead of just the rows not in datesB:
datesA_not_in_datesB = ~np.isin(datesA,datesB)
datesA_not_in_datesB.reshape(-1,1)
array([[ True],
[ True],
[ True],
[ True],
[ True],
[ True],
[ True],
[ True],
[ True]])
datesA rows 4 and 5 ( datetime.datetime(2000, 1, 8, 0, 0) and datetime.datetime(2000, 1, 9, 0, 0) ) are the only records that are not in datesB and that should return True.
I've found this issue of isin()
not working for datetimes being reported in those posts:
The fix someone suggests in the posts above is:
datesA_not_in_datesB = ~np.isin(datesA.astype('datetime64[ns]'),datesB.astype('datetime64[ns]'))
C:\Users\Username\anaconda3\lib\site-packages\ipykernel_launcher.py:1: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
"""Entry point for launching an IPython kernel.
datesA_not_in_datesB.reshape(-1,1)
array([[False],
[False],
[False],
[False],
[ True],
[ True],
[False],
[False],
[False]])
That works except I get a warning message:
DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future """Entry point for launching an IPython kernel.
I have tried a few things to remove the timezone .replace(tzinfo=None)
info from datesB to make isnan work without having to use .astype('datetime64[ns]')
and find a solution without a DeprecationWarning but to no avail.
Would someone be able to advice on how to get the same result as
datesA_not_in_datesB = ~np.isin(datesA.astype('datetime64[ns]'),datesB.astype('datetime64[ns]'))
but in a way that doesn't result in a DeprecationWarning?
Thank you very much for your time and help with this.