|
36 | 36 | from pandas._libs import lib, iNaT, NaT |
37 | 37 | from pandas._libs.tslibs.period import Period |
38 | 38 | from pandas._libs.tslibs.timedeltas import delta_to_nanoseconds |
| 39 | +from pandas._libs.tslibs.timestamps import round_ns |
39 | 40 |
|
40 | 41 | from pandas.core.indexes.base import Index, _index_shared_docs |
41 | 42 | from pandas.util._decorators import Appender, cache_readonly |
@@ -91,33 +92,34 @@ class TimelikeOps(object): |
91 | 92 |
|
92 | 93 | def _round(self, freq, rounder): |
93 | 94 |
|
94 | | - from pandas.tseries.frequencies import to_offset |
95 | | - unit = to_offset(freq).nanos |
| 95 | + # from pandas.tseries.frequencies import to_offset |
| 96 | + # unit = to_offset(freq).nanos |
96 | 97 | # round the local times |
97 | 98 | values = _ensure_datetimelike_to_i8(self) |
98 | 99 |
|
99 | | - if unit < 1000: |
100 | | - # for nano rounding, work with the last 6 digits separately |
101 | | - # due to float precision |
102 | | - buff = 1000000 |
103 | | - result = (buff * (values // buff) + unit * |
104 | | - (rounder((values % buff) * (1 / float(unit)))) |
105 | | - .astype('i8')) |
106 | | - else: |
107 | | - if unit % 1000 != 0: |
108 | | - msg = 'Precision will be lost using frequency: {}' |
109 | | - warnings.warn(msg.format(freq)) |
110 | | - |
111 | | - # GH19206 |
112 | | - # to deal with round-off when unit is large |
113 | | - if unit >= 1e9: |
114 | | - divisor = 10 ** int(np.log10(unit / 1e7)) |
115 | | - else: |
116 | | - divisor = 10 |
117 | | - |
118 | | - result = (unit * rounder((values * (divisor / float(unit))) / |
119 | | - divisor).astype('i8')) |
120 | | - |
| 100 | + # if unit < 1000: |
| 101 | + # # for nano rounding, work with the last 6 digits separately |
| 102 | + # # due to float precision |
| 103 | + # buff = 1000000 |
| 104 | + # result = (buff * (values // buff) + unit * |
| 105 | + # (rounder((values % buff) * (1 / float(unit)))) |
| 106 | + # .astype('i8')) |
| 107 | + # else: |
| 108 | + # if unit % 1000 != 0: |
| 109 | + # msg = 'Precision will be lost using frequency: {}' |
| 110 | + # warnings.warn(msg.format(freq)) |
| 111 | + # |
| 112 | + # # GH19206 |
| 113 | + # # to deal with round-off when unit is large |
| 114 | + # if unit >= 1e9: |
| 115 | + # divisor = 10 ** int(np.log10(unit / 1e7)) |
| 116 | + # else: |
| 117 | + # divisor = 10 |
| 118 | + # |
| 119 | + # result = (unit * rounder((values * (divisor / float(unit))) / |
| 120 | + # divisor).astype('i8')) |
| 121 | + |
| 122 | + result = round_ns(values, rounder, freq) |
121 | 123 | result = self._maybe_mask_results(result, fill_value=NaT) |
122 | 124 |
|
123 | 125 | attribs = self._get_attributes_dict() |
|
0 commit comments