I am using python 3.10.6. I have this function which takes a netcdf file and assigns dmin and dmax the minimum and maximum dates of the time index from that file's data. Whenever the dmin is below 1970 (i.e. 1969 and below), I get the following error:
xmin = datetime.utcfromtimestamp((dmin - sec0) / sec1).date() OSError:
[Errno 22] Invalid argument
Here is my code:
def get_minmax_date(data):
dmin = data['time'].values.min()
dmax = data['time'].values.max()
sec0 = np.datetime64(0, 's')
sec1 = np.timedelta64(1, 's')
xmin = datetime.utcfromtimestamp((dmin - sec0) / sec1).date()
xmax = datetime.utcfromtimestamp((dmax - sec0) / sec1).date() + timedelta(days=1)
return xmin, xmax
I know it's a bug in the datetime library but Is there any workaround?