Skip to content

Commit 27d2915

Browse files
yui-knkjreback
authored andcommitted
CLN: Fix compile time warnings
This commit suppresses these warnings warning: comparison of constant -1 with expression\ of type 'PANDAS_DATETIMEUNIT' is always true\ [-Wtautological-constant-out-of-range-compare] Author: yui-knk <[email protected]> Closes pandas-dev#13607 from yui-knk/fix_c_warning and squashes the following commits: e9eee1d [yui-knk] CLN: Fix compile time warnings
1 parent 7c357d2 commit 27d2915

File tree

3 files changed

+6
-25
lines changed

3 files changed

+6
-25
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ Bug Fixes
536536
- Bug in ``Peirod`` and ``Series`` or ``Index`` comparison raises ``TypeError`` (:issue:`13200`)
537537
- Bug in ``pd.set_eng_float_format()`` that would prevent NaN's from formatting (:issue:`11981`)
538538
- Bug in ``.unstack`` with ``Categorical`` dtype resets ``.ordered`` to ``True`` (:issue:`13249`)
539+
- Clean some compile time warnings in datetime parsing (:issue:`13607`)
539540

540541

541542
- Bug in ``Series`` comparison operators when dealing with zero dim NumPy arrays (:issue:`13006`)

pandas/src/datetime/np_datetime_strings.c

+4-24
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ parse_iso_8601_datetime(char *str, int len,
460460
}
461461

462462
/* Check the casting rule */
463-
if (unit != -1 && !can_cast_datetime64_units(bestunit, unit,
463+
if (!can_cast_datetime64_units(bestunit, unit,
464464
casting)) {
465465
PyErr_Format(PyExc_TypeError, "Cannot parse \"%s\" as unit "
466466
"'%s' using casting rule %s",
@@ -503,7 +503,7 @@ parse_iso_8601_datetime(char *str, int len,
503503
}
504504

505505
/* Check the casting rule */
506-
if (unit != -1 && !can_cast_datetime64_units(bestunit, unit,
506+
if (!can_cast_datetime64_units(bestunit, unit,
507507
casting)) {
508508
PyErr_Format(PyExc_TypeError, "Cannot parse \"%s\" as unit "
509509
"'%s' using casting rule %s",
@@ -975,7 +975,7 @@ parse_iso_8601_datetime(char *str, int len,
975975
}
976976

977977
/* Check the casting rule */
978-
if (unit != -1 && !can_cast_datetime64_units(bestunit, unit,
978+
if (!can_cast_datetime64_units(bestunit, unit,
979979
casting)) {
980980
PyErr_Format(PyExc_TypeError, "Cannot parse \"%s\" as unit "
981981
"'%s' using casting rule %s",
@@ -1005,11 +1005,6 @@ get_datetime_iso_8601_strlen(int local, PANDAS_DATETIMEUNIT base)
10051005
{
10061006
int len = 0;
10071007

1008-
/* If no unit is provided, return the maximum length */
1009-
if (base == -1) {
1010-
return PANDAS_DATETIME_MAX_ISO8601_STRLEN;
1011-
}
1012-
10131008
switch (base) {
10141009
/* Generic units can only be used to represent NaT */
10151010
/*case PANDAS_FR_GENERIC:*/
@@ -1146,28 +1141,13 @@ make_iso_8601_datetime(pandas_datetimestruct *dts, char *outstr, int outlen,
11461141
local = 0;
11471142
}
11481143

1149-
/* Automatically detect a good unit */
1150-
if (base == -1) {
1151-
base = lossless_unit_from_datetimestruct(dts);
1152-
/*
1153-
* If there's a timezone, use at least minutes precision,
1154-
* and never split up hours and minutes by default
1155-
*/
1156-
if ((base < PANDAS_FR_m && local) || base == PANDAS_FR_h) {
1157-
base = PANDAS_FR_m;
1158-
}
1159-
/* Don't split up dates by default */
1160-
else if (base < PANDAS_FR_D) {
1161-
base = PANDAS_FR_D;
1162-
}
1163-
}
11641144
/*
11651145
* Print weeks with the same precision as days.
11661146
*
11671147
* TODO: Could print weeks with YYYY-Www format if the week
11681148
* epoch is a Monday.
11691149
*/
1170-
else if (base == PANDAS_FR_W) {
1150+
if (base == PANDAS_FR_W) {
11711151
base = PANDAS_FR_D;
11721152
}
11731153

pandas/src/ujson/python/objToJSON.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si
450450

451451
static void *PandasDateTimeStructToJSON(pandas_datetimestruct *dts, JSONTypeContext *tc, void *outValue, size_t *_outLen)
452452
{
453-
int base = ((PyObjectEncoder*) tc->encoder)->datetimeUnit;
453+
PANDAS_DATETIMEUNIT base = ((PyObjectEncoder*) tc->encoder)->datetimeUnit;
454454

455455
if (((PyObjectEncoder*) tc->encoder)->datetimeIso)
456456
{

0 commit comments

Comments
 (0)