Skip to content

Commit 1f2d54a

Browse files
authored
CLN/TYP: assorted (#46568)
1 parent bea02f3 commit 1f2d54a

16 files changed

+51
-40
lines changed

pandas/_libs/algos.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ def is_monotonic(ndarray[numeric_object_t, ndim=1] arr, bint timelike):
750750
n = len(arr)
751751

752752
if n == 1:
753-
if arr[0] != arr[0] or (timelike and <int64_t>arr[0] == NPY_NAT):
753+
if arr[0] != arr[0] or (numeric_object_t is int64_t and timelike and arr[0] == NPY_NAT):
754754
# single value is NaN
755755
return False, False, True
756756
else:

pandas/_libs/indexing.pyx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ cdef class NDFrameIndexerBase:
22
"""
33
A base class for _NDFrameIndexer for fast instantiation and attribute access.
44
"""
5+
cdef:
6+
Py_ssize_t _ndim
7+
58
cdef public:
69
str name
7-
object obj, _ndim
10+
object obj
811

912
def __init__(self, name: str, obj):
1013
self.obj = obj
1114
self.name = name
12-
self._ndim = None
15+
self._ndim = -1
1316

1417
@property
1518
def ndim(self) -> int:
1619
# Delay `ndim` instantiation until required as reading it
1720
# from `obj` isn't entirely cheap.
1821
ndim = self._ndim
19-
if ndim is None:
22+
if ndim == -1:
2023
ndim = self._ndim = self.obj.ndim
2124
if ndim > 2:
2225
raise ValueError( # pragma: no cover

pandas/_libs/internals.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ cpdef update_blklocs_and_blknos(
544544
"""
545545
cdef:
546546
Py_ssize_t i
547-
cnp.npy_intp length = len(blklocs) + 1
547+
cnp.npy_intp length = blklocs.shape[0] + 1
548548
ndarray[intp_t, ndim=1] new_blklocs, new_blknos
549549

550550
# equiv: new_blklocs = np.empty(length, dtype=np.intp)

pandas/_libs/tslib.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def array_with_unit_to_datetime(
218218
"""
219219
cdef:
220220
Py_ssize_t i, j, n=len(values)
221-
int64_t m
221+
int64_t mult
222222
int prec = 0
223223
ndarray[float64_t] fvalues
224224
bint is_ignore = errors=='ignore'
@@ -242,7 +242,7 @@ def array_with_unit_to_datetime(
242242
)
243243
return result, tz
244244

245-
m, _ = precision_from_unit(unit)
245+
mult, _ = precision_from_unit(unit)
246246

247247
if is_raise:
248248
# try a quick conversion to i8/f8
@@ -254,7 +254,7 @@ def array_with_unit_to_datetime(
254254
# fill missing values by comparing to NPY_NAT
255255
mask = iresult == NPY_NAT
256256
iresult[mask] = 0
257-
fvalues = iresult.astype("f8") * m
257+
fvalues = iresult.astype("f8") * mult
258258
need_to_iterate = False
259259

260260
if not need_to_iterate:
@@ -265,10 +265,10 @@ def array_with_unit_to_datetime(
265265
raise OutOfBoundsDatetime(f"cannot convert input with unit '{unit}'")
266266

267267
if values.dtype.kind in ["i", "u"]:
268-
result = (iresult * m).astype("M8[ns]")
268+
result = (iresult * mult).astype("M8[ns]")
269269

270270
elif values.dtype.kind == "f":
271-
fresult = (values * m).astype("f8")
271+
fresult = (values * mult).astype("f8")
272272
fresult[mask] = 0
273273
if prec:
274274
fresult = round(fresult, prec)

pandas/_libs/tslibs/conversion.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ cdef class _TSObject:
1919
bint fold
2020

2121

22-
cdef convert_to_tsobject(object ts, tzinfo tz, str unit,
23-
bint dayfirst, bint yearfirst,
24-
int32_t nanos=*)
22+
cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
23+
bint dayfirst, bint yearfirst,
24+
int32_t nanos=*)
2525

2626
cdef _TSObject convert_datetime_to_tsobject(datetime ts, tzinfo tz,
2727
int32_t nanos=*)

pandas/_libs/tslibs/conversion.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ cdef class _TSObject:
345345
self.fold = 0
346346

347347

348-
cdef convert_to_tsobject(object ts, tzinfo tz, str unit,
349-
bint dayfirst, bint yearfirst, int32_t nanos=0):
348+
cdef _TSObject convert_to_tsobject(object ts, tzinfo tz, str unit,
349+
bint dayfirst, bint yearfirst, int32_t nanos=0):
350350
"""
351351
Extract datetime and int64 from any of:
352352
- np.int64 (with unit providing a possible modifier)

pandas/_libs/tslibs/dtypes.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from pandas._libs.tslibs.np_datetime cimport NPY_DATETIMEUNIT
55

66
cdef str npy_unit_to_abbrev(NPY_DATETIMEUNIT unit)
77
cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil
8-
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=*)
8+
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=*) except? -1
99

1010
cdef dict attrname_to_abbrevs
1111

pandas/_libs/tslibs/dtypes.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ cdef NPY_DATETIMEUNIT freq_group_code_to_npy_unit(int freq) nogil:
307307
return NPY_DATETIMEUNIT.NPY_FR_D
308308

309309

310-
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns):
310+
cdef int64_t periods_per_day(NPY_DATETIMEUNIT reso=NPY_DATETIMEUNIT.NPY_FR_ns) except? -1:
311311
"""
312312
How many of the given time units fit into a single day?
313313
"""

pandas/_libs/tslibs/offsets.pyx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ cdef class WeekOfMonthMixin(SingleConstructorOffset):
19101910

19111911
shifted = shift_month(other, months, "start")
19121912
to_day = self._get_offset_day(shifted)
1913-
return shift_day(shifted, to_day - shifted.day)
1913+
return _shift_day(shifted, to_day - shifted.day)
19141914

19151915
def is_on_offset(self, dt: datetime) -> bool:
19161916
if self.normalize and not _is_normalized(dt):
@@ -3132,7 +3132,7 @@ cdef class FY5253Quarter(FY5253Mixin):
31323132
qtr_lens = self.get_weeks(norm)
31333133

31343134
# check that qtr_lens is consistent with self._offset addition
3135-
end = shift_day(start, days=7 * sum(qtr_lens))
3135+
end = _shift_day(start, days=7 * sum(qtr_lens))
31363136
assert self._offset.is_on_offset(end), (start, end, qtr_lens)
31373137

31383138
tdelta = norm - start
@@ -3173,7 +3173,7 @@ cdef class FY5253Quarter(FY5253Mixin):
31733173
# Note: we always have 0 <= n < 4
31743174
weeks = sum(qtr_lens[:n])
31753175
if weeks:
3176-
res = shift_day(res, days=weeks * 7)
3176+
res = _shift_day(res, days=weeks * 7)
31773177

31783178
return res
31793179

@@ -3210,7 +3210,7 @@ cdef class FY5253Quarter(FY5253Mixin):
32103210

32113211
current = next_year_end
32123212
for qtr_len in qtr_lens:
3213-
current = shift_day(current, days=qtr_len * 7)
3213+
current = _shift_day(current, days=qtr_len * 7)
32143214
if dt == current:
32153215
return True
32163216
return False
@@ -3729,7 +3729,7 @@ cpdef to_offset(freq):
37293729
# ----------------------------------------------------------------------
37303730
# RelativeDelta Arithmetic
37313731

3732-
def shift_day(other: datetime, days: int) -> datetime:
3732+
cdef datetime _shift_day(datetime other, int days):
37333733
"""
37343734
Increment the datetime `other` by the given number of days, retaining
37353735
the time-portion of the datetime. For tz-naive datetimes this is
@@ -3915,6 +3915,8 @@ cdef inline void _shift_quarters(const int64_t[:] dtindex,
39153915
out[i] = dtstruct_to_dt64(&dts)
39163916

39173917

3918+
@cython.wraparound(False)
3919+
@cython.boundscheck(False)
39183920
cdef ndarray[int64_t] _shift_bdays(const int64_t[:] i8other, int periods):
39193921
"""
39203922
Implementation of BusinessDay.apply_offset.

pandas/_libs/tslibs/timedeltas.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ cdef class _Timedelta(timedelta):
1515
int64_t _d, _h, _m, _s, _ms, _us, _ns
1616

1717
cpdef timedelta to_pytimedelta(_Timedelta self)
18-
cpdef bint _has_ns(self)
18+
cdef bint _has_ns(self)
19+
cdef _ensure_components(_Timedelta self)

0 commit comments

Comments
 (0)