From 6d280351fa7f8bd623dce363663a3817f8f6c8eb Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 5 May 2020 10:26:34 -0700 Subject: [PATCH 1/2] avoid hasattr checks in liboffsets --- pandas/_libs/tslibs/offsets.pyx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 3dfaa36888f62..737d4652ad70f 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -32,6 +32,7 @@ from pandas._libs.tslibs.np_datetime cimport ( npy_datetimestruct, dtstruct_to_dt64, dt64_to_dtstruct) from pandas._libs.tslibs.timezones import UTC from pandas._libs.tslibs.tzconversion cimport tz_convert_single +from pandas._libs.tslibs.c_timestamp cimport _Timestamp # --------------------------------------------------------------------- @@ -97,17 +98,18 @@ cdef to_offset(object obj): return to_offset(obj) -def as_datetime(obj): - f = getattr(obj, 'to_pydatetime', None) - if f is not None: - obj = f() +def as_datetime(obj: datetime) -> datetime: + if isinstance(obj, _Timestamp): + return obj.to_pydatetime() return obj -cpdef bint is_normalized(dt): - if (dt.hour != 0 or dt.minute != 0 or dt.second != 0 or - dt.microsecond != 0 or getattr(dt, 'nanosecond', 0) != 0): +cpdef bint is_normalized(datetime dt): + if dt.hour != 0 or dt.minute != 0 or dt.second != 0 or dt.microsecond != 0: + # Regardless of whether dt is datetime vs Timestamp return False + if isinstance(dt, _Timestamp): + return dt.nanosecond == 0 return True From fab0b03fca11dc4abaa4c97061a34a4f919b3c8f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 5 May 2020 13:27:29 -0700 Subject: [PATCH 2/2] dummy commit to force CI