I've been playing around with datetime in Python, and found out something rather confusing.
For both datetime.datetime and pandas.datetime, I use datetime.timedelta for time calculation:
testing = pd.date_range("2022-02-02","2022-03-02")
testing[0] + timedelta(days = 1)
-> works fine.
However, it seems that such method does not work on numpy.datetime64.
(the code is a bit idiotic. It's solely for understanding the concept)
testing = pd.date_range("2022-02-02","2022-03-02")
pd.Series(testing).unique()[0] + timedelta(days = 1)
-> throws an error.
Questions are:
- Why does
pd.Series(testing).unique()[0]returnsnumpy.datetime64, instead of ordinaryTimestamp? - Why exactly is the code throwing me an error?
- Seems
datetime.datetimeandpandas.datetimeare compatible, butnumpy.datetimeisn't. Why?