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

Method _round

pandas/core/arrays/datetimelike.py:2096–2116  ·  view source on GitHub ↗
(self, freq, mode, ambiguous, nonexistent)

Source from the content-addressed store, hash-verified

2094 return super().__array_ufunc__(ufunc, method, *inputs, **kwargs)
2095
2096 def _round(self, freq, mode, ambiguous, nonexistent):
2097 # round the local times
2098 if isinstance(self.dtype, DatetimeTZDtype):
2099 # operate on naive timestamps, then convert back to aware
2100 self = cast("DatetimeArray", self)
2101 naive = self.tz_localize(None)
2102 result = naive._round(freq, mode, ambiguous, nonexistent)
2103 return result.tz_localize(
2104 self.tz, ambiguous=ambiguous, nonexistent=nonexistent
2105 )
2106
2107 values = self.view("i8")
2108 values = cast(np.ndarray, values)
2109 nanos = get_unit_for_round(freq, self._creso)
2110 if nanos == 0:
2111 # GH 52761
2112 return self.copy()
2113 result_i8 = round_nsint64(values, mode, nanos)
2114 result = self._maybe_mask_results(result_i8, fill_value=iNaT)
2115 result = result.view(self._ndarray.dtype)
2116 return self._simple_new(result, dtype=self.dtype)
2117
2118 def round(
2119 self,

Callers 3

roundMethod · 0.95
floorMethod · 0.95
ceilMethod · 0.95

Calls 5

copyMethod · 0.95
_maybe_mask_resultsMethod · 0.80
tz_localizeMethod · 0.45
viewMethod · 0.45
_simple_newMethod · 0.45

Tested by

no test coverage detected