Skip to content

Commit d77c181

Browse files
committed
de-privatize timezone functions
1 parent 328c7e1 commit d77c181

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

pandas/_libs/period.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ from pandas._libs import tslib, lib
3535
from pandas._libs.tslib import (Timedelta, Timestamp, iNaT,
3636
NaT)
3737
from tslibs.timezones cimport (
38-
is_utc, is_tzlocal, get_utcoffset, _get_dst_info, maybe_get_tz)
38+
is_utc, is_tzlocal, get_utcoffset, get_dst_info, maybe_get_tz)
3939
from tslib cimport _nat_scalar_rules
4040

4141
from tslibs.frequencies cimport get_freq_code
@@ -557,7 +557,7 @@ cdef _reso_local(ndarray[int64_t] stamps, object tz):
557557
reso = curr_reso
558558
else:
559559
# Adjust datetime64 timestamp, recompute datetimestruct
560-
trans, deltas, typ = _get_dst_info(tz)
560+
trans, deltas, typ = get_dst_info(tz)
561561

562562
_pos = trans.searchsorted(stamps, side='right') - 1
563563
if _pos.dtype != np.int64:
@@ -624,7 +624,7 @@ cdef ndarray[int64_t] localize_dt64arr_to_period(ndarray[int64_t] stamps,
624624
dts.us, dts.ps, freq)
625625
else:
626626
# Adjust datetime64 timestamp, recompute datetimestruct
627-
trans, deltas, typ = _get_dst_info(tz)
627+
trans, deltas, typ = get_dst_info(tz)
628628

629629
_pos = trans.searchsorted(stamps, side='right') - 1
630630
if _pos.dtype != np.int64:

pandas/_libs/tslib.pyx

+16-16
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ iNaT = NPY_NAT
100100

101101

102102
from tslibs.timezones cimport (
103-
is_utc, is_tzlocal, _is_fixed_offset,
103+
is_utc, is_tzlocal, is_fixed_offset,
104104
treat_tz_as_dateutil, treat_tz_as_pytz,
105105
get_timezone, get_utcoffset, maybe_get_tz,
106-
_get_dst_info
106+
get_dst_info
107107
)
108108
from tslibs.timezones import ( # noqa
109109
get_timezone, get_utcoffset, maybe_get_tz,
110-
_p_tz_cache_key, dst_cache,
111-
_unbox_utcoffsets,
112-
_dateutil_gettz
110+
p_tz_cache_key, dst_cache,
111+
unbox_utcoffsets,
112+
dateutil_gettz
113113
)
114114

115115

@@ -167,7 +167,7 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None, box=False):
167167
pandas_datetime_to_datetimestruct(
168168
value, PANDAS_FR_ns, &dts)
169169
result[i] = func_create(value, dts, tz, freq)
170-
elif is_tzlocal(tz) or _is_fixed_offset(tz):
170+
elif is_tzlocal(tz) or is_fixed_offset(tz):
171171
for i in range(n):
172172
value = arr[i]
173173
if value == NPY_NAT:
@@ -181,7 +181,7 @@ def ints_to_pydatetime(ndarray[int64_t] arr, tz=None, freq=None, box=False):
181181
dt = Timestamp(dt)
182182
result[i] = dt
183183
else:
184-
trans, deltas, typ = _get_dst_info(tz)
184+
trans, deltas, typ = get_dst_info(tz)
185185

186186
for i in range(n):
187187

@@ -1641,12 +1641,12 @@ cdef inline void _localize_tso(_TSObject obj, object tz):
16411641
obj.tzinfo = tz
16421642
else:
16431643
# Adjust datetime64 timestamp, recompute datetimestruct
1644-
trans, deltas, typ = _get_dst_info(tz)
1644+
trans, deltas, typ = get_dst_info(tz)
16451645

16461646
pos = trans.searchsorted(obj.value, side='right') - 1
16471647

16481648
# static/pytz/dateutil specific code
1649-
if _is_fixed_offset(tz):
1649+
if is_fixed_offset(tz):
16501650
# statictzinfo
16511651
if len(deltas) > 0 and obj.value != NPY_NAT:
16521652
pandas_datetime_to_datetimestruct(obj.value + deltas[0],
@@ -4066,7 +4066,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
40664066
* 1000000000)
40674067
utc_dates[i] = v - delta
40684068
else:
4069-
trans, deltas, typ = _get_dst_info(tz1)
4069+
trans, deltas, typ = get_dst_info(tz1)
40704070

40714071
# all-NaT
40724072
tt = vals[vals!=NPY_NAT]
@@ -4108,7 +4108,7 @@ def tz_convert(ndarray[int64_t] vals, object tz1, object tz2):
41084108
return result
41094109

41104110
# Convert UTC to other timezone
4111-
trans, deltas, typ = _get_dst_info(tz2)
4111+
trans, deltas, typ = get_dst_info(tz2)
41124112

41134113
# use first non-NaT element
41144114
# if all-NaT, return all-NaT
@@ -4172,7 +4172,7 @@ def tz_convert_single(int64_t val, object tz1, object tz2):
41724172
delta = int(get_utcoffset(tz1, dt).total_seconds()) * 1000000000
41734173
utc_date = val - delta
41744174
elif get_timezone(tz1) != 'UTC':
4175-
trans, deltas, typ = _get_dst_info(tz1)
4175+
trans, deltas, typ = get_dst_info(tz1)
41764176
pos = trans.searchsorted(val, side='right') - 1
41774177
if pos < 0:
41784178
raise ValueError('First time before start of DST info')
@@ -4191,7 +4191,7 @@ def tz_convert_single(int64_t val, object tz1, object tz2):
41914191
return utc_date + delta
41924192

41934193
# Convert UTC to other timezone
4194-
trans, deltas, typ = _get_dst_info(tz2)
4194+
trans, deltas, typ = get_dst_info(tz2)
41954195

41964196
pos = trans.searchsorted(utc_date, side='right') - 1
41974197
if pos < 0:
@@ -4261,7 +4261,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
42614261
"Length of ambiguous bool-array must be the same size as vals")
42624262
ambiguous_array = np.asarray(ambiguous)
42634263

4264-
trans, deltas, typ = _get_dst_info(tz)
4264+
trans, deltas, typ = get_dst_info(tz)
42654265

42664266
tdata = <int64_t*> trans.data
42674267
ntrans = len(trans)
@@ -4967,7 +4967,7 @@ cdef _normalize_local(ndarray[int64_t] stamps, object tz):
49674967
result[i] = _normalized_stamp(&dts)
49684968
else:
49694969
# Adjust datetime64 timestamp, recompute datetimestruct
4970-
trans, deltas, typ = _get_dst_info(tz)
4970+
trans, deltas, typ = get_dst_info(tz)
49714971

49724972
_pos = trans.searchsorted(stamps, side='right') - 1
49734973
if _pos.dtype != np.int64:
@@ -5022,7 +5022,7 @@ def dates_normalized(ndarray[int64_t] stamps, tz=None):
50225022
if (dt.hour + dt.minute + dt.second + dt.microsecond) > 0:
50235023
return False
50245024
else:
5025-
trans, deltas, typ = _get_dst_info(tz)
5025+
trans, deltas, typ = get_dst_info(tz)
50265026

50275027
for i in range(n):
50285028
# Adjust datetime64 timestamp, recompute datetimestruct

pandas/_libs/tslibs/timezones.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ cpdef object get_timezone(object tz)
1313
cpdef object maybe_get_tz(object tz)
1414

1515
cpdef get_utcoffset(tzinfo, obj)
16-
cdef bint _is_fixed_offset(object tz)
16+
cdef bint is_fixed_offset(object tz)
1717

18-
cdef object _get_dst_info(object tz)
18+
cdef object get_dst_info(object tz)

pandas/_libs/tslibs/timezones.pyx

+11-11
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ cpdef inline object maybe_get_tz(object tz):
111111
return tz
112112

113113

114-
def _p_tz_cache_key(tz):
114+
def p_tz_cache_key(tz):
115115
""" Python interface for cache function to facilitate testing."""
116-
return _tz_cache_key(tz)
116+
return tz_cache_key(tz)
117117

118118

119119
# Timezone data caches, key is the pytz string or dateutil file name.
120120
dst_cache = {}
121121

122122

123-
cdef inline object _tz_cache_key(object tz):
123+
cdef inline object tz_cache_key(object tz):
124124
"""
125125
Return the key in the cache for the timezone info object or None
126126
if unknown.
@@ -163,7 +163,7 @@ cpdef get_utcoffset(tzinfo, obj):
163163
return tzinfo.utcoffset(obj)
164164

165165

166-
cdef inline bint _is_fixed_offset(object tz):
166+
cdef inline bint is_fixed_offset(object tz):
167167
if treat_tz_as_dateutil(tz):
168168
if len(tz._trans_idx) == 0 and len(tz._trans_list) == 0:
169169
return 1
@@ -178,7 +178,7 @@ cdef inline bint _is_fixed_offset(object tz):
178178
return 1
179179

180180

181-
cdef object _get_utc_trans_times_from_dateutil_tz(object tz):
181+
cdef object get_utc_trans_times_from_dateutil_tz(object tz):
182182
"""
183183
Transition times in dateutil timezones are stored in local non-dst
184184
time. This code converts them to UTC. It's the reverse of the code
@@ -193,7 +193,7 @@ cdef object _get_utc_trans_times_from_dateutil_tz(object tz):
193193
return new_trans
194194

195195

196-
cpdef ndarray _unbox_utcoffsets(object transinfo):
196+
cpdef ndarray unbox_utcoffsets(object transinfo):
197197
cdef:
198198
Py_ssize_t i, sz
199199
ndarray[int64_t] arr
@@ -211,15 +211,15 @@ cpdef ndarray _unbox_utcoffsets(object transinfo):
211211
# Daylight Savings
212212

213213

214-
cdef object _get_dst_info(object tz):
214+
cdef object get_dst_info(object tz):
215215
"""
216216
return a tuple of :
217217
(UTC times of DST transitions,
218218
UTC offsets in microseconds corresponding to DST transitions,
219219
string of type of transitions)
220220
221221
"""
222-
cache_key = _tz_cache_key(tz)
222+
cache_key = tz_cache_key(tz)
223223
if cache_key is None:
224224
num = int(get_utcoffset(tz, None).total_seconds()) * 1000000000
225225
return (np.array([NPY_NAT + 1], dtype=np.int64),
@@ -235,13 +235,13 @@ cdef object _get_dst_info(object tz):
235235
trans[0] = NPY_NAT + 1
236236
except Exception:
237237
pass
238-
deltas = _unbox_utcoffsets(tz._transition_info)
238+
deltas = unbox_utcoffsets(tz._transition_info)
239239
typ = 'pytz'
240240

241241
elif treat_tz_as_dateutil(tz):
242242
if len(tz._trans_list):
243243
# get utc trans times
244-
trans_list = _get_utc_trans_times_from_dateutil_tz(tz)
244+
trans_list = get_utc_trans_times_from_dateutil_tz(tz)
245245
trans = np.hstack([
246246
np.array([0], dtype='M8[s]'), # place holder for first item
247247
np.array(trans_list, dtype='M8[s]')]).astype(
@@ -255,7 +255,7 @@ cdef object _get_dst_info(object tz):
255255
deltas *= 1000000000
256256
typ = 'dateutil'
257257

258-
elif _is_fixed_offset(tz):
258+
elif is_fixed_offset(tz):
259259
trans = np.array([NPY_NAT + 1], dtype=np.int64)
260260
deltas = np.array([tz._ttinfo_std.offset],
261261
dtype='i8') * 1000000000

pandas/tests/tseries/test_timezones.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ def test_cache_keys_are_distinct_for_pytz_vs_dateutil(self):
11811181
if tz_d is None:
11821182
# skip timezones that dateutil doesn't know about.
11831183
continue
1184-
assert tslib._p_tz_cache_key(tz_p) != tslib._p_tz_cache_key(tz_d)
1184+
assert tslib.p_tz_cache_key(tz_p) != tslib.p_tz_cache_key(tz_d)
11851185

11861186

11871187
class TestTimeZones(object):

0 commit comments

Comments
 (0)