MCPcopy
hub / github.com/pandas-dev/pandas / _with_freq

Method _with_freq

pandas/core/arrays/datetimelike.py:2448–2475  ·  view source on GitHub ↗

Helper to get a view on the same data, with a new freq. Parameters ---------- freq : DateOffset, None, or "infer" Returns ------- Same type as self

(self, freq)

Source from the content-addressed store, hash-verified

2446 self._freq = None
2447
2448 def _with_freq(self, freq) -> Self:
2449 """
2450 Helper to get a view on the same data, with a new freq.
2451
2452 Parameters
2453 ----------
2454 freq : DateOffset, None, or "infer"
2455
2456 Returns
2457 -------
2458 Same type as self
2459 """
2460 # GH#29843
2461 if freq is None:
2462 # Always valid
2463 pass
2464 elif len(self) == 0 and isinstance(freq, BaseOffset):
2465 # Always valid. In the TimedeltaArray case, we require a Tick offset
2466 if self.dtype.kind == "m" and not isinstance(freq, (Tick, Day)):
2467 raise TypeError("TimedeltaArray/Index freq must be a Tick")
2468 else:
2469 # As an internal method, we can ensure this assertion always holds
2470 assert freq == "infer"
2471 freq = to_offset(self.inferred_freq)
2472
2473 arr = self.view()
2474 arr._freq = freq
2475 return arr
2476
2477 # --------------------------------------------------------------
2478 # ExtensionArray Interface

Calls 1

viewMethod · 0.45