Round dates using a specified method.
(self, freq, method)
| 708 | return infer_freq(self) |
| 709 | |
| 710 | def _round_via_method(self, freq, method): |
| 711 | """Round dates using a specified method.""" |
| 712 | from xarray.coding.cftime_offsets import CFTIME_TICKS, Day, to_offset |
| 713 | |
| 714 | if not self._data.size: |
| 715 | return CFTimeIndex(np.array(self)) |
| 716 | |
| 717 | offset = to_offset(freq) |
| 718 | if isinstance(offset, Day): |
| 719 | # Following pandas, "In the 'round' context, Day unambiguously |
| 720 | # means 24h, not calendar-day" |
| 721 | offset_as_timedelta = timedelta(days=offset.n) |
| 722 | elif isinstance(offset, CFTIME_TICKS): |
| 723 | offset_as_timedelta = offset.as_timedelta() |
| 724 | else: |
| 725 | raise ValueError(f"{offset} is a non-fixed frequency") |
| 726 | |
| 727 | unit = _total_microseconds(offset_as_timedelta) |
| 728 | values = self.asi8 |
| 729 | rounded = method(values, unit) |
| 730 | return _cftimeindex_from_i8(rounded, self.date_type, self.name) |
| 731 | |
| 732 | def floor(self, freq): |
| 733 | """Round dates down to fixed frequency. |
no test coverage detected