def METHOD_NAME(ds):
    if "time" in ds.coords:
        try:
            # explicitly set time dtype to avoid invalid type promotion error
            ds = ds.assign_coords(time=ds.time.astype(np.datetime64))
        except TypeError:
            pass  # if cannot cast to np.datetime64, leave time axis alone
    return ds