Skip to content

CLN: tslibs imports and unused variables #24401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/ccalendar.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
14 changes: 2 additions & 12 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import cython
from cython import Py_ssize_t

import numpy as np
cimport numpy as cnp
Expand Down Expand Up @@ -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).
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions pandas/_libs/tslibs/fields.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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':
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

import cython
from cython import Py_ssize_t

import time
from cpython.datetime cimport (PyDateTime_IMPORT,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import sys
import re
import time

from cython import Py_ssize_t

from cpython.datetime cimport datetime


Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import datetime, date
from datetime import datetime

from cpython cimport (
PyObject_RichCompareBool,
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/resolution.pyx
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/tslibs/strptime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ except:
except:
from _dummy_thread import allocate_lock as _thread_allocate_lock

from cython import Py_ssize_t


import pytz

Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down