if len(vals) == 1:
    dt = DT.datetime.strptime(val, '%Y-%m-%d %H%M%S')
else:
    nofrag, frag = vals
length = len(frag)
if length > 6:
    frag = frag[:5]
length = len(frag)
while length < 6:
    frag = frag + '0'
length += 1
nofrag_dt = DT.datetime.strptime(nofrag, '%Y-%m-%d %H%M%S')
dt = nofrag_dt.replace(microsecond=int(frag))
return dt
Python: Converting nanoseconds into DateTime64 format