MCPcopy Index your code
hub / github.com/pydata/xarray / Tick

Class Tick

xarray/coding/cftime_offsets.py:200–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

198
199
200class Tick(BaseCFTimeOffset):
201 # analogous https://github.com/pandas-dev/pandas/blob/ccb25ab1d24c4fb9691270706a59c8d319750870/pandas/_libs/tslibs/offsets.pyx#L806
202
203 def _next_higher_resolution(self) -> Tick:
204 self_type = type(self)
205 if self_type is Day:
206 return Hour(self.n * 24)
207 if self_type is Hour:
208 return Minute(self.n * 60)
209 if self_type is Minute:
210 return Second(self.n * 60)
211 if self_type is Second:
212 return Millisecond(self.n * 1000)
213 if self_type is Millisecond:
214 return Microsecond(self.n * 1000)
215 raise ValueError("Could not convert to integer offset at any resolution")
216
217 def __mul__(self, other: int | float) -> Tick:
218 if not isinstance(other, int | float):
219 return NotImplemented
220 if isinstance(other, float):
221 n = other * self.n
222 # If the new `n` is an integer, we can represent it using the
223 # same BaseCFTimeOffset subclass as self, otherwise we need to move up
224 # to a higher-resolution subclass
225 if np.isclose(n % 1, 0):
226 return type(self)(int(n))
227
228 new_self = self._next_higher_resolution()
229 return new_self * other
230 return type(self)(n=other * self.n)
231
232 def as_timedelta(self) -> timedelta:
233 """All Tick subclasses must implement an as_timedelta method."""
234 raise NotImplementedError
235
236
237def _get_day_of_month(other, day_option: DayOption) -> int:

Calls

no outgoing calls

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…