Skip to content

Commit d3c3c2b

Browse files
jbrockmendeljreback
authored andcommitted
remove arg that is only ever used as NPY_UNSAFE_CASTING; remove code this renders unreachable (#18546)
1 parent 48c5bfc commit d3c3c2b

File tree

6 files changed

+4
-343
lines changed

6 files changed

+4
-343
lines changed

pandas/_libs/src/datetime.pxd

-9
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ from cpython cimport PyUnicode_Check, PyUnicode_AsASCIIString
77
cdef extern from "numpy/ndarrayobject.h":
88
ctypedef int64_t npy_datetime
99

10-
ctypedef enum NPY_CASTING:
11-
NPY_NO_CASTING
12-
NPY_EQUIV_CASTING
13-
NPY_SAFE_CASTING
14-
NPY_SAME_KIND_CASTING
15-
NPY_UNSAFE_CASTING
16-
1710
cdef extern from "numpy/npy_common.h":
1811
ctypedef unsigned char npy_bool
1912

@@ -45,7 +38,6 @@ cdef extern from "datetime/np_datetime.h":
4538

4639
cdef extern from "datetime/np_datetime_strings.h":
4740
int parse_iso_8601_datetime(char *str, int len, PANDAS_DATETIMEUNIT unit,
48-
NPY_CASTING casting,
4941
pandas_datetimestruct *out,
5042
int *out_local, int *out_tzoffset,
5143
PANDAS_DATETIMEUNIT *out_bestunit,
@@ -75,7 +67,6 @@ cdef inline int _cstring_to_dts(char *val, int length,
7567
int result
7668

7769
result = parse_iso_8601_datetime(val, length, PANDAS_FR_ns,
78-
NPY_UNSAFE_CASTING,
7970
dts, out_local, out_tzoffset,
8071
&out_bestunit, &special)
8172
return result

pandas/_libs/src/datetime/np_datetime.c

-38
Original file line numberDiff line numberDiff line change
@@ -679,44 +679,6 @@ int convert_datetimestruct_to_datetime(pandas_datetime_metadata *meta,
679679
return 0;
680680
}
681681

682-
/*
683-
* This provides the casting rules for the DATETIME data type units.
684-
*
685-
* Notably, there is a barrier between 'date units' and 'time units'
686-
* for all but 'unsafe' casting.
687-
*/
688-
npy_bool can_cast_datetime64_units(PANDAS_DATETIMEUNIT src_unit,
689-
PANDAS_DATETIMEUNIT dst_unit,
690-
NPY_CASTING casting) {
691-
switch (casting) {
692-
/* Allow anything with unsafe casting */
693-
case NPY_UNSAFE_CASTING:
694-
return 1;
695-
696-
/*
697-
* Only enforce the 'date units' vs 'time units' barrier with
698-
* 'same_kind' casting.
699-
*/
700-
case NPY_SAME_KIND_CASTING:
701-
return (src_unit <= PANDAS_FR_D && dst_unit <= PANDAS_FR_D) ||
702-
(src_unit > PANDAS_FR_D && dst_unit > PANDAS_FR_D);
703-
704-
/*
705-
* Enforce the 'date units' vs 'time units' barrier and that
706-
* casting is only allowed towards more precise units with
707-
* 'safe' casting.
708-
*/
709-
case NPY_SAFE_CASTING:
710-
return (src_unit <= dst_unit) &&
711-
((src_unit <= PANDAS_FR_D && dst_unit <= PANDAS_FR_D) ||
712-
(src_unit > PANDAS_FR_D && dst_unit > PANDAS_FR_D));
713-
714-
/* Enforce equality with 'no' or 'equiv' casting */
715-
default:
716-
return src_unit == dst_unit;
717-
}
718-
}
719-
720682
/*
721683
* Converts a datetime based on the given metadata into a datetimestruct
722684
*/

pandas/_libs/src/datetime/np_datetime.h

-11
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ int cmp_pandas_datetimestruct(const pandas_datetimestruct *a,
125125
void
126126
add_minutes_to_datetimestruct(pandas_datetimestruct *dts, int minutes);
127127

128-
/*
129-
* This provides the casting rules for the TIMEDELTA data type units.
130-
*
131-
* Notably, there is a barrier between the nonlinear years and
132-
* months units, and all the other units.
133-
*/
134-
npy_bool
135-
can_cast_datetime64_units(PANDAS_DATETIMEUNIT src_unit,
136-
PANDAS_DATETIMEUNIT dst_unit,
137-
NPY_CASTING casting);
138-
139128

140129
int
141130
convert_datetime_to_datetimestruct(pandas_datetime_metadata *meta,

0 commit comments

Comments
 (0)