I need to store some dates which are beyond the year-2262-limit. Since I only need dates and no times I thought I could get away with using datetime.date, which did work fine until I realised that later in the code there is some forced coercion of data types and I am unable to get around that. Example:
import pandas as pd
import datetime
data = pd.DataFrame({"col1": ["2022-12-31", "9999-12-31"]})
data["col2"] = data["col1"].apply(lambda x: datetime.date.fromisoformat(x))
# .... company code ....
# forced coercion
data.astype(dtype={"col1": str, "col2": datetime.date})
Among others, I have tried to supply the following types for the coercion of col2, to no avail.
datetime.date-> dtype '<class 'datetime.date'>' not understoodnp.datetime64-> Out of bounds nanosecond timestamp: 9999-12-31 00:00:00
I have also tried to convert with data["col2"].dt.to_pydatetime(), which yields a "Can only use .dt accessor with datetimelike values" error.
I suppose what baffles me the most is that the astype() documentation says that one can supply any numpy or Python data type, and my understanding is that datetime.date is a Python data type. So why wouldn't astype() know it?