Skip to content

CLN: Fix compile time warnings #13607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.19.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,4 @@ Bug Fixes
- Bug in ``groupby`` with ``as_index=False`` returns all NaN's when grouping on multiple columns including a categorical one (:issue:`13204`)

- Bug where ``pd.read_gbq()`` could throw ``ImportError: No module named discovery`` as a result of a naming conflict with another python package called apiclient (:issue:`13454`)
- Clean compile time warnings, ``warning: comparison of constant -1 with expression of type 'PANDAS_DATETIMEUNIT' is always true`` (:issue:`13607`)
28 changes: 4 additions & 24 deletions pandas/src/datetime/np_datetime_strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ parse_iso_8601_datetime(char *str, int len,
}

/* Check the casting rule */
if (unit != -1 && !can_cast_datetime64_units(bestunit, unit,
if (!can_cast_datetime64_units(bestunit, unit,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea what this was for? e.g. what was the intent originally

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess checking -1 or not is for https://github.com/pydata/pandas/blob/820e1105a44f6f9347a02ebed0a85b4b71d70363/pandas/src/datetime/np_datetime_strings.c#L316 .
Only this line assigns -1 for PANDAS_DATETIMEUNIT a type variable.

casting)) {
PyErr_Format(PyExc_TypeError, "Cannot parse \"%s\" as unit "
"'%s' using casting rule %s",
Expand Down Expand Up @@ -503,7 +503,7 @@ parse_iso_8601_datetime(char *str, int len,
}

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

/* Check the casting rule */
if (unit != -1 && !can_cast_datetime64_units(bestunit, unit,
if (!can_cast_datetime64_units(bestunit, unit,
casting)) {
PyErr_Format(PyExc_TypeError, "Cannot parse \"%s\" as unit "
"'%s' using casting rule %s",
Expand Down Expand Up @@ -1005,11 +1005,6 @@ get_datetime_iso_8601_strlen(int local, PANDAS_DATETIMEUNIT base)
{
int len = 0;

/* If no unit is provided, return the maximum length */
if (base == -1) {
return PANDAS_DATETIME_MAX_ISO8601_STRLEN;
}

switch (base) {
/* Generic units can only be used to represent NaT */
/*case PANDAS_FR_GENERIC:*/
Expand Down Expand Up @@ -1146,28 +1141,13 @@ make_iso_8601_datetime(pandas_datetimestruct *dts, char *outstr, int outlen,
local = 0;
}

/* Automatically detect a good unit */
if (base == -1) {
base = lossless_unit_from_datetimestruct(dts);
/*
* If there's a timezone, use at least minutes precision,
* and never split up hours and minutes by default
*/
if ((base < PANDAS_FR_m && local) || base == PANDAS_FR_h) {
base = PANDAS_FR_m;
}
/* Don't split up dates by default */
else if (base < PANDAS_FR_D) {
base = PANDAS_FR_D;
}
}
/*
* Print weeks with the same precision as days.
*
* TODO: Could print weeks with YYYY-Www format if the week
* epoch is a Monday.
*/
else if (base == PANDAS_FR_W) {
if (base == PANDAS_FR_W) {
base = PANDAS_FR_D;
}

Expand Down
2 changes: 1 addition & 1 deletion pandas/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static void *PyUnicodeToUTF8(JSOBJ _obj, JSONTypeContext *tc, void *outValue, si

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

if (((PyObjectEncoder*) tc->encoder)->datetimeIso)
{
Expand Down