Skip to content

Clean Up Case Insensitive Comps in Tokenizer #29534

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

Merged
merged 3 commits into from
Nov 12, 2019
Merged
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
10 changes: 0 additions & 10 deletions pandas/_libs/src/parse_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ The full license is in the LICENSE file, distributed with this software.
#define PANDAS__LIBS_SRC_PARSE_HELPER_H_

#include <float.h>
#include "inline_helper.h"
#include "headers/portable.h"
#include "parser/tokenizer.h"

int to_double(char *item, double *p_value, char sci, char decimal,
Expand Down Expand Up @@ -94,12 +92,4 @@ int floatify(PyObject *str, double *result, int *maybe_int) {
return -1;
}

PANDAS_INLINE void lowercase(char *p) {
for (; *p; ++p) *p = tolower_ascii(*p);
}

PANDAS_INLINE void uppercase(char *p) {
for (; *p; ++p) *p = toupper_ascii(*p);
}

#endif // PANDAS__LIBS_SRC_PARSE_HELPER_H_
54 changes: 21 additions & 33 deletions pandas/_libs/src/parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,42 +1426,30 @@ int tokenize_all_rows(parser_t *self) {
return status;
}

PANDAS_INLINE void uppercase(char *p) {
for (; *p; ++p) *p = toupper_ascii(*p);
}

/*
* Function: to_boolean
* --------------------
*
* Validate if item should be recognized as a boolean field.
*
* item: const char* representing parsed text
* val : pointer to a uint8_t of boolean representation
*
* If item is determined to be boolean, this method will set
* the appropriate value of val and return 0. A non-zero exit
* status means that item was not inferred to be boolean, and
* leaves the value of *val unmodified.
*/
int to_boolean(const char *item, uint8_t *val) {
char *tmp;
int i, status = 0;
size_t length0 = (strlen(item) + 1);
int bufsize = length0;

static const char *tstrs[1] = {"TRUE"};
static const char *fstrs[1] = {"FALSE"};

tmp = malloc(bufsize);
snprintf(tmp, length0, "%s", item);
uppercase(tmp);

for (i = 0; i < 1; ++i) {
if (strcmp(tmp, tstrs[i]) == 0) {
*val = 1;
goto done;
}
if (strcasecmp(item, "TRUE") == 0) {
*val = 1;
return 0;
} else if (strcasecmp(item, "FALSE") == 0) {
*val = 0;
return 0;
}

for (i = 0; i < 1; ++i) {
if (strcmp(tmp, fstrs[i]) == 0) {
*val = 0;
goto done;
}
}

status = -1;

done:
free(tmp);
return status;
return -1;
}

// ---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/src/parser/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ See LICENSE for the license

#include "../headers/stdint.h"
#include "../inline_helper.h"
#include "../headers/portable.h"

#include "khash.h"

Expand Down