From 4142c98f4c2dcf1f94941cd6ae72806aee0e9c13 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 12 Jul 2022 09:09:51 -0700 Subject: [PATCH] CLN: non-nano follow-ups --- pandas/_libs/tslib.pyx | 2 +- pandas/_libs/tslibs/conversion.pyx | 4 ++++ pandas/_libs/tslibs/vectorized.pyi | 2 +- pandas/core/indexes/base.py | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index ee3964b892e2e..9c7f35d240f96 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -152,7 +152,7 @@ def format_array_from_datetime( # a format based on precision basic_format = format is None if basic_format: - reso_obj = get_resolution(values, reso=reso) + reso_obj = get_resolution(values, tz=tz, reso=reso) show_ns = reso_obj == Resolution.RESO_NS show_us = reso_obj == Resolution.RESO_US show_ms = reso_obj == Resolution.RESO_MS diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index 00e2c8b8b6be6..0dfb859a3444f 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -144,9 +144,13 @@ cpdef inline (int64_t, int) precision_from_unit(str unit): NPY_DATETIMEUNIT reso = abbrev_to_npy_unit(unit) if reso == NPY_DATETIMEUNIT.NPY_FR_Y: + # each 400 years we have 97 leap years, for an average of 97/400=.2425 + # extra days each year. We get 31556952 by writing + # 3600*24*365.2425=31556952 m = 1_000_000_000 * 31556952 p = 9 elif reso == NPY_DATETIMEUNIT.NPY_FR_M: + # 2629746 comes from dividing the "Y" case by 12. m = 1_000_000_000 * 2629746 p = 9 elif reso == NPY_DATETIMEUNIT.NPY_FR_W: diff --git a/pandas/_libs/tslibs/vectorized.pyi b/pandas/_libs/tslibs/vectorized.pyi index 7eb4695b9ca2c..d24541aede8d8 100644 --- a/pandas/_libs/tslibs/vectorized.pyi +++ b/pandas/_libs/tslibs/vectorized.pyi @@ -42,5 +42,5 @@ def ints_to_pydatetime( def tz_convert_from_utc( stamps: npt.NDArray[np.int64], tz: tzinfo | None, - reso: int = ..., + reso: int = ..., # NPY_DATETIMEUNIT ) -> npt.NDArray[np.int64]: ... diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 58b4d82bcbe5f..a212da050e1f1 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -6897,6 +6897,7 @@ def insert(self, loc: int, item) -> Index: # Use self._constructor instead of Index to retain NumericIndex GH#43921 # TODO(2.0) can use Index instead of self._constructor + # Check if doing so fixes GH#47071 return self._constructor._with_infer(new_values, name=self.name) def drop(