Skip to content

CLN: tslibs typing, avoid private funcs #34195

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 5 commits into from
May 20, 2020
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
8 changes: 6 additions & 2 deletions pandas/_libs/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
from pandas._libs.tslibs.parsing import parse_datetime_string

from pandas._libs.tslibs.timedeltas cimport cast_from_unit
from pandas._libs.tslibs.timezones cimport is_utc, is_tzlocal, get_dst_info
from pandas._libs.tslibs.timezones import UTC
from pandas._libs.tslibs.timezones cimport (
get_dst_info,
is_utc,
is_tzlocal,
utc_pytz as UTC,
)
from pandas._libs.tslibs.conversion cimport (
_TSObject, convert_datetime_to_tsobject,
get_datetime64_nanos)
Expand Down
12 changes: 6 additions & 6 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ from pandas._libs.tslibs.nattype cimport (

from pandas._libs.tslibs.tzconversion import tz_localize_to_utc
from pandas._libs.tslibs.tzconversion cimport (
_tz_convert_tzlocal_utc, _tz_convert_tzlocal_fromutc,
tz_convert_single
tz_convert_utc_to_tzlocal,
_tz_convert_tzlocal_fromutc,
tz_convert_single,
)

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -706,8 +707,7 @@ def normalize_i8_timestamps(int64_t[:] stamps, object tz):
result : int64 ndarray of converted of normalized nanosecond timestamps
"""
cdef:
Py_ssize_t n = len(stamps)
int64_t[:] result = np.empty(n, dtype=np.int64)
int64_t[:] result

result = _normalize_local(stamps, tz)

Expand Down Expand Up @@ -746,7 +746,7 @@ cdef int64_t[:] _normalize_local(const int64_t[:] stamps, tzinfo tz):
if stamps[i] == NPY_NAT:
result[i] = NPY_NAT
continue
local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False)
local_val = tz_convert_utc_to_tzlocal(stamps[i], tz)
dt64_to_dtstruct(local_val, &dts)
result[i] = _normalized_stamp(&dts)
else:
Expand Down Expand Up @@ -827,7 +827,7 @@ def is_date_array_normalized(const int64_t[:] stamps, object tz=None):
return False
elif is_tzlocal(tz):
for i in range(n):
local_val = _tz_convert_tzlocal_utc(stamps[i], tz, to_utc=False)
local_val = tz_convert_utc_to_tzlocal(stamps[i], tz)
dt64_to_dtstruct(local_val, &dts)
if (dts.hour + dts.min + dts.sec + dts.us) > 0:
return False
Expand Down
3 changes: 1 addition & 2 deletions pandas/_libs/tslibs/timezones.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ cpdef bint is_utc(object tz)
cdef bint is_tzlocal(object tz)

cdef bint treat_tz_as_pytz(object tz)
cdef bint treat_tz_as_dateutil(object tz)

cpdef bint tz_compare(object start, object end)
cpdef object get_timezone(object tz)
cpdef object maybe_get_tz(object tz)

cdef get_utcoffset(tzinfo tz, obj)
cdef bint is_fixed_offset(object tz)
cdef bint is_fixed_offset(tzinfo tz)

cdef object get_dst_info(object tz)
9 changes: 4 additions & 5 deletions pandas/_libs/tslibs/timezones.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ from datetime import timezone

# dateutil compat
from dateutil.tz import (
gettz as dateutil_gettz,
tzfile as _dateutil_tzfile,
tzlocal as _dateutil_tzlocal,
tzutc as _dateutil_tzutc,
)


from dateutil.tz import gettz as dateutil_gettz

from pytz.tzinfo import BaseTzInfo as _pytz_BaseTzInfo
import pytz
UTC = pytz.utc
Expand Down Expand Up @@ -161,7 +160,7 @@ cdef get_utcoffset(tzinfo tz, obj):
return tz.utcoffset(obj)


cdef inline bint is_fixed_offset(object tz):
cdef inline bint is_fixed_offset(tzinfo tz):
if treat_tz_as_dateutil(tz):
if len(tz._trans_idx) == 0 and len(tz._trans_list) == 0:
return 1
Expand All @@ -178,7 +177,7 @@ cdef inline bint is_fixed_offset(object tz):
return 1


cdef object get_utc_trans_times_from_dateutil_tz(object tz):
cdef object _get_utc_trans_times_from_dateutil_tz(tzinfo tz):
"""
Transition times in dateutil timezones are stored in local non-dst
time. This code converts them to UTC. It's the reverse of the code
Expand Down Expand Up @@ -240,7 +239,7 @@ cdef object get_dst_info(object tz):
elif treat_tz_as_dateutil(tz):
if len(tz._trans_list):
# get utc trans times
trans_list = get_utc_trans_times_from_dateutil_tz(tz)
trans_list = _get_utc_trans_times_from_dateutil_tz(tz)
trans = np.hstack([
np.array([0], dtype='M8[s]'), # place holder for 1st item
np.array(trans_list, dtype='M8[s]')]).astype(
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/tzconversion.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ from numpy cimport int64_t


cdef int64_t tz_convert_utc_to_tzlocal(int64_t utc_val, tzinfo tz)
cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc=*)
cdef int64_t _tz_convert_tzlocal_fromutc(int64_t val, tzinfo tz, bint *fold)
cpdef int64_t tz_convert_single(int64_t val, object tz1, object tz2)
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/util.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ cdef extern from "Python.h":
# thus they cannot be declared 'nogil'. Also PyUnicode_AsUTF8AndSize() can
# potentially allocate memory inside in unlikely case of when underlying
# unicode object was stored as non-utf8 and utf8 wasn't requested before.
bint PyBytes_AsStringAndSize(object obj, char** buf,
Py_ssize_t* length) except -1
const char* PyUnicode_AsUTF8AndSize(object obj,
Py_ssize_t* length) except NULL

Expand Down