def snap(self, freq='<STR_LIT:S>'):
<EOL>freq = to_offset(freq)<EOL>snapped = np.empty(len(self), dtype=_NS_DTYPE)<EOL>for i, v in enumerate(self):<EOL><INDENT>s = v<EOL>if not freq.onOffset(s):<EOL><INDENT>t0 = freq.rollback(s)<EOL>t1 = freq.rollforward(s)<EOL>if abs(s - t0) < abs(t1 - s):<EOL><INDENT>s = t0<EOL><DEDENT>else:<EOL><INDENT>s = t1<EOL><DEDENT><DEDENT>snapped[i] = s<EOL><DEDENT>return DatetimeIndex._simple_new(snapped, name=self.name, tz=self.tz,<EOL>freq=freq)<EOL>
Snap time stamps to nearest occurring frequency