Skip to content

Commit 4715d67

Browse files
authored
REF: reso->creso (#49123)
1 parent 6a52634 commit 4715d67

File tree

7 files changed

+61
-61
lines changed

7 files changed

+61
-61
lines changed

pandas/_libs/index.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -490,24 +490,24 @@ cdef class ObjectEngine(IndexEngine):
490490
cdef class DatetimeEngine(Int64Engine):
491491

492492
cdef:
493-
NPY_DATETIMEUNIT reso
493+
NPY_DATETIMEUNIT _creso
494494

495495
def __init__(self, ndarray values):
496496
super().__init__(values.view("i8"))
497-
self.reso = get_unit_from_dtype(values.dtype)
497+
self._creso = get_unit_from_dtype(values.dtype)
498498

499499
cdef int64_t _unbox_scalar(self, scalar) except? -1:
500500
# NB: caller is responsible for ensuring tzawareness compat
501501
# before we get here
502502
if scalar is NaT:
503503
return NaT.value
504504
elif isinstance(scalar, _Timestamp):
505-
if scalar._creso == self.reso:
505+
if scalar._creso == self._creso:
506506
return scalar.value
507507
else:
508508
# Note: caller is responsible for catching potential ValueError
509509
# from _as_creso
510-
return (<_Timestamp>scalar)._as_creso(self.reso, round_ok=False).value
510+
return (<_Timestamp>scalar)._as_creso(self._creso, round_ok=False).value
511511
raise TypeError(scalar)
512512

513513
def __contains__(self, val: object) -> bool:
@@ -570,12 +570,12 @@ cdef class TimedeltaEngine(DatetimeEngine):
570570
if scalar is NaT:
571571
return NaT.value
572572
elif isinstance(scalar, _Timedelta):
573-
if scalar._creso == self.reso:
573+
if scalar._creso == self._creso:
574574
return scalar.value
575575
else:
576576
# Note: caller is responsible for catching potential ValueError
577577
# from _as_creso
578-
return (<_Timedelta>scalar)._as_creso(self.reso, round_ok=False).value
578+
return (<_Timedelta>scalar)._as_creso(self._creso, round_ok=False).value
579579
raise TypeError(scalar)
580580

581581

pandas/_libs/tslibs/timestamps.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2099,10 +2099,10 @@ default 'raise'
20992099
value = tz_localize_to_utc_single(self.value, tz,
21002100
ambiguous=ambiguous,
21012101
nonexistent=nonexistent,
2102-
reso=self._creso)
2102+
creso=self._creso)
21032103
elif tz is None:
21042104
# reset tz
2105-
value = tz_convert_from_utc_single(self.value, self.tz, reso=self._creso)
2105+
value = tz_convert_from_utc_single(self.value, self.tz, creso=self._creso)
21062106

21072107
else:
21082108
raise TypeError(
@@ -2245,7 +2245,7 @@ default 'raise'
22452245
fold = self.fold
22462246

22472247
if tzobj is not None:
2248-
value = tz_convert_from_utc_single(value, tzobj, reso=self._creso)
2248+
value = tz_convert_from_utc_single(value, tzobj, creso=self._creso)
22492249

22502250
# setup components
22512251
pandas_datetime_to_datetimestruct(value, self._creso, &dts)

pandas/_libs/tslibs/tzconversion.pxd

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ from pandas._libs.tslibs.np_datetime cimport NPY_DATETIMEUNIT
99

1010

1111
cpdef int64_t tz_convert_from_utc_single(
12-
int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT reso=*
12+
int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT creso=*
1313
) except? -1
1414
cdef int64_t tz_localize_to_utc_single(
1515
int64_t val,
1616
tzinfo tz,
1717
object ambiguous=*,
1818
object nonexistent=*,
19-
NPY_DATETIMEUNIT reso=*,
19+
NPY_DATETIMEUNIT creso=*,
2020
) except? -1
2121

2222

pandas/_libs/tslibs/tzconversion.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ from pandas._typing import npt
1010

1111
# tz_convert_from_utc_single exposed for testing
1212
def tz_convert_from_utc_single(
13-
val: np.int64, tz: tzinfo, reso: int = ...
13+
val: np.int64, tz: tzinfo, creso: int = ...
1414
) -> np.int64: ...
1515
def tz_localize_to_utc(
1616
vals: npt.NDArray[np.int64],
1717
tz: tzinfo | None,
1818
ambiguous: str | bool | Iterable[bool] | None = ...,
1919
nonexistent: str | timedelta | np.timedelta64 | None = ...,
20-
reso: int = ..., # NPY_DATETIMEUNIT
20+
creso: int = ..., # NPY_DATETIMEUNIT
2121
) -> npt.NDArray[np.int64]: ...

pandas/_libs/tslibs/tzconversion.pyx

+41-41
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cdef const int64_t[::1] _deltas_placeholder = np.array([], dtype=np.int64)
5454
cdef class Localizer:
5555
# cdef:
5656
# tzinfo tz
57-
# NPY_DATETIMEUNIT _reso
57+
# NPY_DATETIMEUNIT _creso
5858
# bint use_utc, use_fixed, use_tzlocal, use_dst, use_pytz
5959
# ndarray trans
6060
# Py_ssize_t ntrans
@@ -64,9 +64,9 @@ cdef class Localizer:
6464

6565
@cython.initializedcheck(False)
6666
@cython.boundscheck(False)
67-
def __cinit__(self, tzinfo tz, NPY_DATETIMEUNIT reso):
67+
def __cinit__(self, tzinfo tz, NPY_DATETIMEUNIT creso):
6868
self.tz = tz
69-
self._creso = reso
69+
self._creso = creso
7070
self.use_utc = self.use_tzlocal = self.use_fixed = False
7171
self.use_dst = self.use_pytz = False
7272
self.ntrans = -1 # placeholder
@@ -82,22 +82,22 @@ cdef class Localizer:
8282

8383
else:
8484
trans, deltas, typ = get_dst_info(tz)
85-
if reso != NPY_DATETIMEUNIT.NPY_FR_ns:
85+
if creso != NPY_DATETIMEUNIT.NPY_FR_ns:
8686
# NB: using floordiv here is implicitly assuming we will
8787
# never see trans or deltas that are not an integer number
8888
# of seconds.
8989
# TODO: avoid these np.array calls
90-
if reso == NPY_DATETIMEUNIT.NPY_FR_us:
90+
if creso == NPY_DATETIMEUNIT.NPY_FR_us:
9191
trans = np.array(trans) // 1_000
9292
deltas = np.array(deltas) // 1_000
93-
elif reso == NPY_DATETIMEUNIT.NPY_FR_ms:
93+
elif creso == NPY_DATETIMEUNIT.NPY_FR_ms:
9494
trans = np.array(trans) // 1_000_000
9595
deltas = np.array(deltas) // 1_000_000
96-
elif reso == NPY_DATETIMEUNIT.NPY_FR_s:
96+
elif creso == NPY_DATETIMEUNIT.NPY_FR_s:
9797
trans = np.array(trans) // 1_000_000_000
9898
deltas = np.array(deltas) // 1_000_000_000
9999
else:
100-
raise NotImplementedError(reso)
100+
raise NotImplementedError(creso)
101101

102102
self.trans = trans
103103
self.ntrans = self.trans.shape[0]
@@ -121,7 +121,7 @@ cdef class Localizer:
121121
return utc_val
122122
elif self.use_tzlocal:
123123
return utc_val + _tz_localize_using_tzinfo_api(
124-
utc_val, self.tz, to_utc=False, reso=self._creso, fold=fold
124+
utc_val, self.tz, to_utc=False, creso=self._creso, fold=fold
125125
)
126126
elif self.use_fixed:
127127
return utc_val + self.delta
@@ -140,7 +140,7 @@ cdef int64_t tz_localize_to_utc_single(
140140
tzinfo tz,
141141
object ambiguous=None,
142142
object nonexistent=None,
143-
NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns,
143+
NPY_DATETIMEUNIT creso=NPY_DATETIMEUNIT.NPY_FR_ns,
144144
) except? -1:
145145
"""See tz_localize_to_utc.__doc__"""
146146
cdef:
@@ -155,18 +155,18 @@ cdef int64_t tz_localize_to_utc_single(
155155
return val
156156

157157
elif is_tzlocal(tz) or is_zoneinfo(tz):
158-
return val - _tz_localize_using_tzinfo_api(val, tz, to_utc=True, reso=reso)
158+
return val - _tz_localize_using_tzinfo_api(val, tz, to_utc=True, creso=creso)
159159

160160
elif is_fixed_offset(tz):
161161
_, deltas, _ = get_dst_info(tz)
162162
delta = deltas[0]
163163
# TODO: de-duplicate with Localizer.__init__
164-
if reso != NPY_DATETIMEUNIT.NPY_FR_ns:
165-
if reso == NPY_DATETIMEUNIT.NPY_FR_us:
164+
if creso != NPY_DATETIMEUNIT.NPY_FR_ns:
165+
if creso == NPY_DATETIMEUNIT.NPY_FR_us:
166166
delta = delta // 1000
167-
elif reso == NPY_DATETIMEUNIT.NPY_FR_ms:
167+
elif creso == NPY_DATETIMEUNIT.NPY_FR_ms:
168168
delta = delta // 1_000_000
169-
elif reso == NPY_DATETIMEUNIT.NPY_FR_s:
169+
elif creso == NPY_DATETIMEUNIT.NPY_FR_s:
170170
delta = delta // 1_000_000_000
171171

172172
return val - delta
@@ -177,7 +177,7 @@ cdef int64_t tz_localize_to_utc_single(
177177
tz,
178178
ambiguous=ambiguous,
179179
nonexistent=nonexistent,
180-
reso=reso,
180+
creso=creso,
181181
)[0]
182182

183183

@@ -188,7 +188,7 @@ def tz_localize_to_utc(
188188
tzinfo tz,
189189
object ambiguous=None,
190190
object nonexistent=None,
191-
NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns,
191+
NPY_DATETIMEUNIT creso=NPY_DATETIMEUNIT.NPY_FR_ns,
192192
):
193193
"""
194194
Localize tzinfo-naive i8 to given time zone (using pytz). If
@@ -216,7 +216,7 @@ def tz_localize_to_utc(
216216
nonexistent : {None, "NaT", "shift_forward", "shift_backward", "raise", \
217217
timedelta-like}
218218
How to handle non-existent times when converting wall times to UTC
219-
reso : NPY_DATETIMEUNIT, default NPY_FR_ns
219+
creso : NPY_DATETIMEUNIT, default NPY_FR_ns
220220
221221
Returns
222222
-------
@@ -236,8 +236,8 @@ timedelta-like}
236236
bint shift_forward = False, shift_backward = False
237237
bint fill_nonexist = False
238238
str stamp
239-
Localizer info = Localizer(tz, reso=reso)
240-
int64_t pph = periods_per_day(reso) // 24
239+
Localizer info = Localizer(tz, creso=creso)
240+
int64_t pph = periods_per_day(creso) // 24
241241

242242
# Vectorized version of DstTzInfo.localize
243243
if info.use_utc:
@@ -252,7 +252,7 @@ timedelta-like}
252252
result[i] = NPY_NAT
253253
else:
254254
result[i] = v - _tz_localize_using_tzinfo_api(
255-
v, tz, to_utc=True, reso=reso
255+
v, tz, to_utc=True, creso=creso
256256
)
257257
return result.base # to return underlying ndarray
258258

@@ -294,7 +294,7 @@ timedelta-like}
294294
shift_backward = True
295295
elif PyDelta_Check(nonexistent):
296296
from .timedeltas import delta_to_nanoseconds
297-
shift_delta = delta_to_nanoseconds(nonexistent, reso=reso)
297+
shift_delta = delta_to_nanoseconds(nonexistent, reso=creso)
298298
elif nonexistent not in ('raise', None):
299299
msg = ("nonexistent must be one of {'NaT', 'raise', 'shift_forward', "
300300
"shift_backwards} or a timedelta object")
@@ -303,13 +303,13 @@ timedelta-like}
303303
# Determine whether each date lies left of the DST transition (store in
304304
# result_a) or right of the DST transition (store in result_b)
305305
result_a, result_b =_get_utc_bounds(
306-
vals, info.tdata, info.ntrans, info.deltas, reso=reso
306+
vals, info.tdata, info.ntrans, info.deltas, creso=creso
307307
)
308308

309309
# silence false-positive compiler warning
310310
dst_hours = np.empty(0, dtype=np.int64)
311311
if infer_dst:
312-
dst_hours = _get_dst_hours(vals, result_a, result_b, reso=reso)
312+
dst_hours = _get_dst_hours(vals, result_a, result_b, creso=creso)
313313

314314
# Pre-compute delta_idx_offset that will be used if we go down non-existent
315315
# paths.
@@ -348,7 +348,7 @@ timedelta-like}
348348
# TODO: test with non-nano; parametrize test_dt_round_tz_ambiguous
349349
result[i] = NPY_NAT
350350
else:
351-
stamp = _render_tstamp(val, reso=reso)
351+
stamp = _render_tstamp(val, creso=creso)
352352
raise pytz.AmbiguousTimeError(
353353
f"Cannot infer dst time from {stamp}, try using the "
354354
"'ambiguous' argument"
@@ -386,7 +386,7 @@ timedelta-like}
386386
elif fill_nonexist:
387387
result[i] = NPY_NAT
388388
else:
389-
stamp = _render_tstamp(val, reso=reso)
389+
stamp = _render_tstamp(val, creso=creso)
390390
raise pytz.NonExistentTimeError(stamp)
391391

392392
return result.base # .base to get underlying ndarray
@@ -422,10 +422,10 @@ cdef inline Py_ssize_t bisect_right_i8(int64_t *data,
422422
return left
423423

424424

425-
cdef inline str _render_tstamp(int64_t val, NPY_DATETIMEUNIT reso):
425+
cdef inline str _render_tstamp(int64_t val, NPY_DATETIMEUNIT creso):
426426
""" Helper function to render exception messages"""
427427
from pandas._libs.tslibs.timestamps import Timestamp
428-
ts = Timestamp._from_value_and_reso(val, reso, None)
428+
ts = Timestamp._from_value_and_reso(val, creso, None)
429429
return str(ts)
430430

431431

@@ -434,7 +434,7 @@ cdef _get_utc_bounds(
434434
int64_t* tdata,
435435
Py_ssize_t ntrans,
436436
const int64_t[::1] deltas,
437-
NPY_DATETIMEUNIT reso,
437+
NPY_DATETIMEUNIT creso,
438438
):
439439
# Determine whether each date lies left of the DST transition (store in
440440
# result_a) or right of the DST transition (store in result_b)
@@ -444,7 +444,7 @@ cdef _get_utc_bounds(
444444
Py_ssize_t i, n = vals.size
445445
int64_t val, v_left, v_right
446446
Py_ssize_t isl, isr, pos_left, pos_right
447-
int64_t ppd = periods_per_day(reso)
447+
int64_t ppd = periods_per_day(creso)
448448

449449
result_a = cnp.PyArray_EMPTY(vals.ndim, vals.shape, cnp.NPY_INT64, 0)
450450
result_b = cnp.PyArray_EMPTY(vals.ndim, vals.shape, cnp.NPY_INT64, 0)
@@ -486,11 +486,11 @@ cdef _get_utc_bounds(
486486

487487
@cython.boundscheck(False)
488488
cdef ndarray[int64_t] _get_dst_hours(
489-
# vals, reso only needed here to potential render an exception message
489+
# vals, creso only needed here to potential render an exception message
490490
const int64_t[:] vals,
491491
ndarray[int64_t] result_a,
492492
ndarray[int64_t] result_b,
493-
NPY_DATETIMEUNIT reso,
493+
NPY_DATETIMEUNIT creso,
494494
):
495495
cdef:
496496
Py_ssize_t i, n = vals.shape[0]
@@ -519,7 +519,7 @@ cdef ndarray[int64_t] _get_dst_hours(
519519

520520
if trans_idx.size == 1:
521521
# see test_tz_localize_to_utc_ambiguous_infer
522-
stamp = _render_tstamp(vals[trans_idx[0]], reso=reso)
522+
stamp = _render_tstamp(vals[trans_idx[0]], creso=creso)
523523
raise pytz.AmbiguousTimeError(
524524
f"Cannot infer dst time from {stamp} as there "
525525
"are no repeated times"
@@ -541,7 +541,7 @@ cdef ndarray[int64_t] _get_dst_hours(
541541
delta = np.diff(result_a[grp])
542542
if grp.size == 1 or np.all(delta > 0):
543543
# see test_tz_localize_to_utc_ambiguous_infer
544-
stamp = _render_tstamp(vals[grp[0]], reso=reso)
544+
stamp = _render_tstamp(vals[grp[0]], creso=creso)
545545
raise pytz.AmbiguousTimeError(stamp)
546546

547547
# Find the index for the switch and pull from a for dst and b
@@ -567,7 +567,7 @@ cdef ndarray[int64_t] _get_dst_hours(
567567
# Timezone Conversion
568568

569569
cpdef int64_t tz_convert_from_utc_single(
570-
int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns
570+
int64_t utc_val, tzinfo tz, NPY_DATETIMEUNIT creso=NPY_DATETIMEUNIT.NPY_FR_ns
571571
) except? -1:
572572
"""
573573
Convert the val (in i8) from UTC to tz
@@ -578,14 +578,14 @@ cpdef int64_t tz_convert_from_utc_single(
578578
----------
579579
utc_val : int64
580580
tz : tzinfo
581-
reso : NPY_DATETIMEUNIT, default NPY_FR_ns
581+
creso : NPY_DATETIMEUNIT, default NPY_FR_ns
582582
583583
Returns
584584
-------
585585
converted: int64
586586
"""
587587
cdef:
588-
Localizer info = Localizer(tz, reso=reso)
588+
Localizer info = Localizer(tz, creso=creso)
589589
Py_ssize_t pos
590590

591591
# Note: caller is responsible for ensuring utc_val != NPY_NAT
@@ -598,7 +598,7 @@ cdef int64_t _tz_localize_using_tzinfo_api(
598598
int64_t val,
599599
tzinfo tz,
600600
bint to_utc=True,
601-
NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns,
601+
NPY_DATETIMEUNIT creso=NPY_DATETIMEUNIT.NPY_FR_ns,
602602
bint* fold=NULL,
603603
) except? -1:
604604
"""
@@ -613,7 +613,7 @@ cdef int64_t _tz_localize_using_tzinfo_api(
613613
tz : tzinfo
614614
to_utc : bint
615615
True if converting _to_ UTC, False if going the other direction.
616-
reso : NPY_DATETIMEUNIT
616+
creso : NPY_DATETIMEUNIT
617617
fold : bint*, default NULL
618618
pointer to fold: whether datetime ends up in a fold or not
619619
after adjustment.
@@ -633,9 +633,9 @@ cdef int64_t _tz_localize_using_tzinfo_api(
633633
datetime dt
634634
int64_t delta
635635
timedelta td
636-
int64_t pps = periods_per_second(reso)
636+
int64_t pps = periods_per_second(creso)
637637

638-
pandas_datetime_to_datetimestruct(val, reso, &dts)
638+
pandas_datetime_to_datetimestruct(val, creso, &dts)
639639

640640
# datetime_new is cython-optimized constructor
641641
if not to_utc:

0 commit comments

Comments
 (0)