diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index cbb27bf8e9917..b0bad119d6a46 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -788,7 +788,16 @@ cpdef ndarray[int64_t] normalize_i8_timestamps(const int64_t[:] stamps, tzinfo t npy_datetimestruct dts int64_t delta, local_val - if is_tzlocal(tz): + if tz is None or is_utc(tz): + with nogil: + for i in range(n): + if stamps[i] == NPY_NAT: + result[i] = NPY_NAT + continue + local_val = stamps[i] + dt64_to_dtstruct(local_val, &dts) + result[i] = _normalized_stamp(&dts) + elif is_tzlocal(tz): for i in range(n): if stamps[i] == NPY_NAT: result[i] = NPY_NAT diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index a7c4b44cf95f8..fad87f9f910cb 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1451,13 +1451,8 @@ default 'raise' ndarray[int64_t] normalized tzinfo own_tz = self.tzinfo # could be None - if own_tz is None or is_utc(own_tz): - DAY_NS = ccalendar.DAY_NANOS - normalized_value = self.value - (self.value % DAY_NS) - return Timestamp(normalized_value).tz_localize(own_tz) - normalized = normalize_i8_timestamps( - np.array([self.value], dtype='i8'), tz=own_tz) + np.array([self.value], dtype="i8"), tz=own_tz) return Timestamp(normalized[0]).tz_localize(own_tz) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 4e31477571a5f..bade1c031d556 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -9,15 +9,14 @@ from pandas._libs.tslibs import ( NaT, Timestamp, - ccalendar, conversion, fields, + frequencies as libfrequencies, iNaT, resolution as libresolution, timezones, tzconversion, ) -import pandas._libs.tslibs.frequencies as libfrequencies from pandas.errors import PerformanceWarning from pandas.core.dtypes.common import ( @@ -1036,14 +1035,7 @@ def normalize(self): '2014-08-01 00:00:00+05:30'], dtype='datetime64[ns, Asia/Calcutta]', freq=None) """ - if self.tz is None or timezones.is_utc(self.tz): - not_null = ~self.isna() - DAY_NS = ccalendar.DAY_SECONDS * 1_000_000_000 - new_values = self.asi8.copy() - adjustment = new_values[not_null] % DAY_NS - new_values[not_null] = new_values[not_null] - adjustment - else: - new_values = conversion.normalize_i8_timestamps(self.asi8, self.tz) + new_values = conversion.normalize_i8_timestamps(self.asi8, self.tz) return type(self)(new_values)._with_freq("infer").tz_localize(self.tz) def to_period(self, freq=None):