Skip to content

Commit be66ef8

Browse files
jbrockmendeljreback
authored andcommitted
Cross off a few tslibs-TODOs (#18443)
1 parent 9c9a09f commit be66ef8

File tree

10 files changed

+46
-67
lines changed

10 files changed

+46
-67
lines changed

pandas/_libs/lib.pyx

-13
Original file line numberDiff line numberDiff line change
@@ -929,19 +929,6 @@ def write_csv_rows(list data, ndarray data_index,
929929
# ------------------------------------------------------------------------------
930930
# Groupby-related functions
931931

932-
@cython.boundscheck(False)
933-
def arrmap(ndarray[object] index, object func):
934-
cdef int length = index.shape[0]
935-
cdef int i = 0
936-
937-
cdef ndarray[object] result = np.empty(length, dtype=np.object_)
938-
939-
for i from 0 <= i < length:
940-
result[i] = func(index[i])
941-
942-
return result
943-
944-
945932
@cython.wraparound(False)
946933
@cython.boundscheck(False)
947934
def is_lexsorted(list list_of_arrays):

pandas/_libs/period.pyx

-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ cdef class _Period(object):
559559
int64_t ordinal
560560
object freq
561561

562-
_comparables = ['name', 'freqstr']
563562
_typ = 'period'
564563

565564
def __cinit__(self, ordinal, freq):

pandas/_libs/src/datetime/np_datetime.c

+30-34
Original file line numberDiff line numberDiff line change
@@ -564,18 +564,15 @@ void pandas_datetime_to_datetimestruct(npy_datetime val, PANDAS_DATETIMEUNIT fr,
564564

565565
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
566566
PANDAS_DATETIMEUNIT fr,
567-
pandas_timedeltastruct *result) {
567+
pandas_timedeltastruct *result) {
568568
pandas_datetime_metadata meta;
569569

570570
meta.base = fr;
571-
meta.num - 1;
571+
meta.num = 1;
572572

573573
convert_timedelta_to_timedeltastruct(&meta, val, result);
574574
}
575575

576-
PANDAS_DATETIMEUNIT get_datetime64_unit(PyObject *obj) {
577-
return (PANDAS_DATETIMEUNIT)((PyDatetimeScalarObject *)obj)->obmeta.base;
578-
}
579576

580577
/*
581578
* Converts a datetime from a datetimestruct to a datetime based
@@ -1001,7 +998,6 @@ int convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,
1001998
int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
1002999
npy_timedelta td,
10031000
pandas_timedeltastruct *out) {
1004-
npy_int64 perday;
10051001
npy_int64 frac;
10061002
npy_int64 sfrac;
10071003
npy_int64 ifrac;
@@ -1016,11 +1012,11 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
10161012

10171013
// put frac in seconds
10181014
if (td < 0 && td % (1000LL * 1000LL * 1000LL) != 0)
1019-
frac = td / (1000LL * 1000LL * 1000LL) - 1;
1015+
frac = td / (1000LL * 1000LL * 1000LL) - 1;
10201016
else
10211017
frac = td / (1000LL * 1000LL * 1000LL);
10221018

1023-
if (frac < 0) {
1019+
if (frac < 0) {
10241020
sign = -1;
10251021

10261022
// even fraction
@@ -1030,66 +1026,66 @@ int convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
10301026
} else {
10311027
frac = -frac;
10321028
}
1033-
} else {
1029+
} else {
10341030
sign = 1;
10351031
out->days = 0;
1036-
}
1032+
}
10371033

1038-
if (frac >= 86400) {
1034+
if (frac >= 86400) {
10391035
out->days += frac / 86400LL;
10401036
frac -= out->days * 86400LL;
1041-
}
1037+
}
10421038

1043-
if (frac >= 3600) {
1039+
if (frac >= 3600) {
10441040
out->hrs = frac / 3600LL;
10451041
frac -= out->hrs * 3600LL;
1046-
} else {
1042+
} else {
10471043
out->hrs = 0;
1048-
}
1044+
}
10491045

1050-
if (frac >= 60) {
1046+
if (frac >= 60) {
10511047
out->min = frac / 60LL;
10521048
frac -= out->min * 60LL;
1053-
} else {
1049+
} else {
10541050
out->min = 0;
1055-
}
1051+
}
10561052

1057-
if (frac >= 0) {
1053+
if (frac >= 0) {
10581054
out->sec = frac;
10591055
frac -= out->sec;
1060-
} else {
1056+
} else {
10611057
out->sec = 0;
1062-
}
1058+
}
10631059

1064-
sfrac = (out->hrs * 3600LL + out->min * 60LL
1065-
+ out->sec) * (1000LL * 1000LL * 1000LL);
1060+
sfrac = (out->hrs * 3600LL + out->min * 60LL
1061+
+ out->sec) * (1000LL * 1000LL * 1000LL);
10661062

1067-
if (sign < 0)
1063+
if (sign < 0)
10681064
out->days = -out->days;
10691065

1070-
ifrac = td - (out->days * DAY_NS + sfrac);
1066+
ifrac = td - (out->days * DAY_NS + sfrac);
10711067

1072-
if (ifrac != 0) {
1068+
if (ifrac != 0) {
10731069
out->ms = ifrac / (1000LL * 1000LL);
10741070
ifrac -= out->ms * 1000LL * 1000LL;
10751071
out->us = ifrac / 1000LL;
10761072
ifrac -= out->us * 1000LL;
10771073
out->ns = ifrac;
1078-
} else {
1074+
} else {
10791075
out->ms = 0;
10801076
out->us = 0;
10811077
out->ns = 0;
1082-
}
1078+
}
10831079

1084-
out->seconds = out->hrs * 3600 + out->min * 60 + out->sec;
1085-
out->microseconds = out->ms * 1000 + out->us;
1086-
out->nanoseconds = out->ns;
1087-
break;
1080+
out->seconds = out->hrs * 3600 + out->min * 60 + out->sec;
1081+
out->microseconds = out->ms * 1000 + out->us;
1082+
out->nanoseconds = out->ns;
1083+
break;
10881084

10891085
default:
10901086
PyErr_SetString(PyExc_RuntimeError,
1091-
"NumPy datetime metadata is corrupted with invalid "
1092-
"base unit");
1087+
"NumPy timedelta metadata is corrupted with "
1088+
"invalid base unit");
10931089
return -1;
10941090
}
10951091

pandas/_libs/src/datetime/np_datetime.h

-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,4 @@ convert_timedelta_to_timedeltastruct(pandas_timedelta_metadata *meta,
148148
pandas_timedeltastruct *out);
149149

150150

151-
PANDAS_DATETIMEUNIT get_datetime64_unit(PyObject *obj);
152-
153-
154151
#endif // PANDAS__LIBS_SRC_DATETIME_NP_DATETIME_H_

pandas/_libs/tslib.pyx

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ from tslibs.conversion cimport (tz_convert_single, _TSObject,
6060
from tslibs.conversion import tz_convert_single
6161

6262
from tslibs.nattype import NaT, nat_strings, iNaT
63-
from tslibs.nattype cimport _checknull_with_nat, NPY_NAT
63+
from tslibs.nattype cimport checknull_with_nat, NPY_NAT
6464

6565
from tslibs.timestamps cimport (create_timestamp_from_ts,
6666
_NS_UPPER_BOUND, _NS_LOWER_BOUND)
@@ -409,7 +409,7 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'):
409409
for i in range(n):
410410
val = values[i]
411411

412-
if _checknull_with_nat(val):
412+
if checknull_with_nat(val):
413413
iresult[i] = NPY_NAT
414414

415415
elif is_integer_object(val) or is_float_object(val):
@@ -475,7 +475,7 @@ cpdef array_with_unit_to_datetime(ndarray values, unit, errors='coerce'):
475475
for i in range(n):
476476
val = values[i]
477477

478-
if _checknull_with_nat(val):
478+
if checknull_with_nat(val):
479479
oresult[i] = NaT
480480
elif is_integer_object(val) or is_float_object(val):
481481

@@ -526,7 +526,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
526526
for i in range(n):
527527
val = values[i]
528528

529-
if _checknull_with_nat(val):
529+
if checknull_with_nat(val):
530530
iresult[i] = NPY_NAT
531531

532532
elif PyDateTime_Check(val):
@@ -686,7 +686,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
686686
val = values[i]
687687

688688
# set as nan except if its a NaT
689-
if _checknull_with_nat(val):
689+
if checknull_with_nat(val):
690690
if PyFloat_Check(val):
691691
oresult[i] = np.nan
692692
else:
@@ -704,7 +704,7 @@ cpdef array_to_datetime(ndarray[object] values, errors='raise',
704704

705705
for i in range(n):
706706
val = values[i]
707-
if _checknull_with_nat(val):
707+
if checknull_with_nat(val):
708708
oresult[i] = val
709709
elif is_string_object(val):
710710

pandas/_libs/tslibs/conversion.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ from timezones cimport (
4040
from parsing import parse_datetime_string
4141

4242
from nattype import nat_strings, NaT
43-
from nattype cimport NPY_NAT, _checknull_with_nat
43+
from nattype cimport NPY_NAT, checknull_with_nat
4444

4545
# ----------------------------------------------------------------------
4646
# Constants
@@ -143,7 +143,7 @@ def datetime_to_datetime64(ndarray[object] values):
143143
iresult = result.view('i8')
144144
for i in range(n):
145145
val = values[i]
146-
if _checknull_with_nat(val):
146+
if checknull_with_nat(val):
147147
iresult[i] = NPY_NAT
148148
elif PyDateTime_Check(val):
149149
if val.tzinfo is not None:

pandas/_libs/tslibs/nattype.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ cdef int64_t NPY_NAT
66

77
cdef bint _nat_scalar_rules[6]
88

9-
cdef bint _checknull_with_nat(object val)
9+
cdef bint checknull_with_nat(object val)

pandas/_libs/tslibs/nattype.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ NaT = NaTType()
572572

573573
# ----------------------------------------------------------------------
574574

575-
cdef inline bint _checknull_with_nat(object val):
575+
cdef inline bint checknull_with_nat(object val):
576576
""" utility to check if a value is a nat or not """
577577
return val is None or (
578578
PyFloat_Check(val) and val != val) or val is NaT

pandas/_libs/tslibs/strptime.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ from np_datetime cimport (check_dts_bounds,
3838

3939
from util cimport is_string_object
4040

41-
from nattype cimport _checknull_with_nat, NPY_NAT
41+
from nattype cimport checknull_with_nat, NPY_NAT
4242
from nattype import nat_strings
4343

4444

@@ -142,7 +142,7 @@ def array_strptime(ndarray[object] values, object fmt,
142142
iresult[i] = NPY_NAT
143143
continue
144144
else:
145-
if _checknull_with_nat(val):
145+
if checknull_with_nat(val):
146146
iresult[i] = NPY_NAT
147147
continue
148148
else:

pandas/_libs/tslibs/timedeltas.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ from np_datetime cimport (cmp_scalar, reverse_ops, td64_to_tdstruct,
3030
pandas_timedeltastruct)
3131

3232
from nattype import nat_strings, NaT
33-
from nattype cimport _checknull_with_nat, NPY_NAT
33+
from nattype cimport checknull_with_nat, NPY_NAT
3434

3535
# ----------------------------------------------------------------------
3636
# Constants
@@ -111,7 +111,7 @@ cpdef convert_to_timedelta64(object ts, object unit):
111111
# kludgy here until we have a timedelta scalar
112112
# handle the numpy < 1.7 case
113113
"""
114-
if _checknull_with_nat(ts):
114+
if checknull_with_nat(ts):
115115
return np.timedelta64(NPY_NAT)
116116
elif isinstance(ts, Timedelta):
117117
# already in the proper format
@@ -443,7 +443,7 @@ cdef inline timedelta_from_spec(object number, object frac, object unit):
443443

444444
cdef bint _validate_ops_compat(other):
445445
# return True if we are compat with operating
446-
if _checknull_with_nat(other):
446+
if checknull_with_nat(other):
447447
return True
448448
elif PyDelta_Check(other) or is_timedelta64_object(other):
449449
return True
@@ -837,7 +837,7 @@ class Timedelta(_Timedelta):
837837
elif is_integer_object(value) or is_float_object(value):
838838
# unit=None is de-facto 'ns'
839839
value = convert_to_timedelta64(value, unit)
840-
elif _checknull_with_nat(value):
840+
elif checknull_with_nat(value):
841841
return NaT
842842
else:
843843
raise ValueError(

0 commit comments

Comments
 (0)