From 03f8c033009865e8393422441b3cc62376caa036 Mon Sep 17 00:00:00 2001 From: Matt Roeschke Date: Sat, 22 Dec 2018 21:16:35 -0800 Subject: [PATCH] CLN: tslibs imports and unused variables --- pandas/_libs/tslib.pyx | 1 - pandas/_libs/tslibs/ccalendar.pyx | 4 ---- pandas/_libs/tslibs/conversion.pyx | 14 ++------------ pandas/_libs/tslibs/fields.pyx | 18 ++++++------------ pandas/_libs/tslibs/offsets.pyx | 1 - pandas/_libs/tslibs/parsing.pyx | 2 -- pandas/_libs/tslibs/period.pyx | 2 +- pandas/_libs/tslibs/resolution.pyx | 2 -- pandas/_libs/tslibs/strptime.pyx | 4 +--- pandas/_libs/tslibs/timedeltas.pyx | 1 - pandas/_libs/tslibs/timezones.pyx | 4 ---- 11 files changed, 10 insertions(+), 43 deletions(-) diff --git a/pandas/_libs/tslib.pyx b/pandas/_libs/tslib.pyx index efabc5ad0b1ba..3f2b49d141e18 100644 --- a/pandas/_libs/tslib.pyx +++ b/pandas/_libs/tslib.pyx @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import cython -from cython import Py_ssize_t from cpython.datetime cimport (PyDateTime_Check, PyDate_Check, PyDateTime_CheckExact, diff --git a/pandas/_libs/tslibs/ccalendar.pyx b/pandas/_libs/tslibs/ccalendar.pyx index 587213049af85..91e7d83012bad 100644 --- a/pandas/_libs/tslibs/ccalendar.pyx +++ b/pandas/_libs/tslibs/ccalendar.pyx @@ -5,7 +5,6 @@ Cython implementations of functions resembling the stdlib calendar module """ import cython -from cython import Py_ssize_t from numpy cimport int64_t, int32_t @@ -151,12 +150,9 @@ cpdef int32_t get_week_of_year(int year, int month, int day) nogil: Assumes the inputs describe a valid date. """ cdef: - bint isleap int32_t doy, dow int woy - isleap = is_leapyear(year) - doy = get_day_of_year(year, month, day) dow = dayofweek(year, month, day) diff --git a/pandas/_libs/tslibs/conversion.pyx b/pandas/_libs/tslibs/conversion.pyx index e6e7884f05b20..81f2aeae68136 100644 --- a/pandas/_libs/tslibs/conversion.pyx +++ b/pandas/_libs/tslibs/conversion.pyx @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- import cython -from cython import Py_ssize_t import numpy as np cimport numpy as cnp @@ -1133,7 +1132,7 @@ def normalize_date(dt: object) -> datetime: @cython.wraparound(False) @cython.boundscheck(False) -def normalize_i8_timestamps(int64_t[:] stamps, object tz=None): +def normalize_i8_timestamps(int64_t[:] stamps, object tz): """ Normalize each of the (nanosecond) timezone aware timestamps in the given array by rounding down to the beginning of the day (i.e. midnight). @@ -1152,7 +1151,6 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz=None): Py_ssize_t n = len(stamps) int64_t[:] result = np.empty(n, dtype=np.int64) - tz = maybe_get_tz(tz) result = _normalize_local(stamps, tz) return result.base # .base to access underlying np.ndarray @@ -1185,15 +1183,7 @@ cdef int64_t[:] _normalize_local(int64_t[:] stamps, tzinfo tz): npy_datetimestruct dts int64_t delta, local_val - if is_utc(tz): - with nogil: - for i in range(n): - if stamps[i] == NPY_NAT: - result[i] = NPY_NAT - continue - dt64_to_dtstruct(stamps[i], &dts) - result[i] = _normalized_stamp(&dts) - elif is_tzlocal(tz): + if is_tzlocal(tz): for i in range(n): if stamps[i] == NPY_NAT: result[i] = NPY_NAT diff --git a/pandas/_libs/tslibs/fields.pyx b/pandas/_libs/tslibs/fields.pyx index 72157c2fcb2f3..df2a189097b78 100644 --- a/pandas/_libs/tslibs/fields.pyx +++ b/pandas/_libs/tslibs/fields.pyx @@ -37,7 +37,7 @@ def get_time_micros(ndarray[int64_t] dtindex): ndarray[int64_t] micros micros = np.mod(dtindex, DAY_SECONDS * 1000000000, dtype=np.int64) - micros //= 1000LL + micros //= 1000 return micros @@ -48,12 +48,10 @@ def build_field_sarray(int64_t[:] dtindex): Datetime as int64 representation to a structured array of fields """ cdef: - Py_ssize_t i, count = 0 + Py_ssize_t i, count = len(dtindex) npy_datetimestruct dts ndarray[int32_t] years, months, days, hours, minutes, seconds, mus - count = len(dtindex) - sa_dtype = [('Y', 'i4'), # year ('M', 'i4'), # month ('D', 'i4'), # day @@ -93,12 +91,11 @@ def get_date_name_field(int64_t[:] dtindex, object field, object locale=None): name based on requested field (e.g. weekday_name) """ cdef: - Py_ssize_t i, count = 0 + Py_ssize_t i, count = len(dtindex) ndarray[object] out, names npy_datetimestruct dts int dow - count = len(dtindex) out = np.empty(count, dtype=object) if field == 'day_name' or field == 'weekday_name': @@ -147,7 +144,7 @@ def get_start_end_field(int64_t[:] dtindex, object field, """ cdef: Py_ssize_t i - int count = 0 + int count = len(dtindex) bint is_business = 0 int end_month = 12 int start_month = 1 @@ -162,7 +159,6 @@ def get_start_end_field(int64_t[:] dtindex, object field, [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]], dtype=np.int32) - count = len(dtindex) out = np.zeros(count, dtype='int8') if freqstr: @@ -388,11 +384,10 @@ def get_date_field(ndarray[int64_t] dtindex, object field): field and return an array of these values. """ cdef: - Py_ssize_t i, count = 0 + Py_ssize_t i, count = len(dtindex) ndarray[int32_t] out npy_datetimestruct dts - count = len(dtindex) out = np.empty(count, dtype='i4') if field == 'Y': @@ -551,11 +546,10 @@ def get_timedelta_field(int64_t[:] tdindex, object field): field and return an array of these values. """ cdef: - Py_ssize_t i, count = 0 + Py_ssize_t i, count = len(tdindex) ndarray[int32_t] out pandas_timedeltastruct tds - count = len(tdindex) out = np.empty(count, dtype='i4') if field == 'days': diff --git a/pandas/_libs/tslibs/offsets.pyx b/pandas/_libs/tslibs/offsets.pyx index 7685ddd76d4b6..0720f5094fa51 100644 --- a/pandas/_libs/tslibs/offsets.pyx +++ b/pandas/_libs/tslibs/offsets.pyx @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import cython -from cython import Py_ssize_t import time from cpython.datetime cimport (PyDateTime_IMPORT, diff --git a/pandas/_libs/tslibs/parsing.pyx b/pandas/_libs/tslibs/parsing.pyx index 9a01bf378e549..6ec49e4fa92ff 100644 --- a/pandas/_libs/tslibs/parsing.pyx +++ b/pandas/_libs/tslibs/parsing.pyx @@ -6,8 +6,6 @@ import sys import re import time -from cython import Py_ssize_t - from cpython.datetime cimport datetime diff --git a/pandas/_libs/tslibs/period.pyx b/pandas/_libs/tslibs/period.pyx index 7f5305065382c..3cb98f29d4486 100644 --- a/pandas/_libs/tslibs/period.pyx +++ b/pandas/_libs/tslibs/period.pyx @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from datetime import datetime, date +from datetime import datetime from cpython cimport ( PyObject_RichCompareBool, diff --git a/pandas/_libs/tslibs/resolution.pyx b/pandas/_libs/tslibs/resolution.pyx index 4acffdea78f55..3760c88a38c39 100644 --- a/pandas/_libs/tslibs/resolution.pyx +++ b/pandas/_libs/tslibs/resolution.pyx @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -from cython import Py_ssize_t - import numpy as np from numpy cimport ndarray, int64_t, int32_t diff --git a/pandas/_libs/tslibs/strptime.pyx b/pandas/_libs/tslibs/strptime.pyx index 46a1145009857..732caf1c0da7f 100644 --- a/pandas/_libs/tslibs/strptime.pyx +++ b/pandas/_libs/tslibs/strptime.pyx @@ -20,8 +20,6 @@ except: except: from _dummy_thread import allocate_lock as _thread_allocate_lock -from cython import Py_ssize_t - import pytz @@ -69,7 +67,7 @@ def array_strptime(object[:] values, object fmt, values : ndarray of string-like objects fmt : string-like regex exact : matches must be exact if True, search if False - coerce : if invalid values found, coerce to NaT + errors : string specifying error handling, {'raise', 'ignore', 'coerce'} """ cdef: diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 219d3cd3ece75..a03f460c9e2d2 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -7,7 +7,6 @@ import sys cdef bint PY3 = (sys.version_info[0] >= 3) import cython -from cython import Py_ssize_t from cpython cimport Py_NE, Py_EQ, PyObject_RichCompare diff --git a/pandas/_libs/tslibs/timezones.pyx b/pandas/_libs/tslibs/timezones.pyx index 9f8922b274abd..b67aab1452ebd 100644 --- a/pandas/_libs/tslibs/timezones.pyx +++ b/pandas/_libs/tslibs/timezones.pyx @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -from cython import Py_ssize_t - -from cpython.datetime cimport tzinfo - # dateutil compat from dateutil.tz import ( tzutc as _dateutil_tzutc,