Skip to content

Commit 74be91c

Browse files
committed
Simplify round_trip converter
Always make a copy of input string.
1 parent 9cf0755 commit 74be91c

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

pandas/_libs/src/parser/tokenizer.c

+14-22
Original file line numberDiff line numberDiff line change
@@ -1815,37 +1815,29 @@ char* _str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
18151815

18161816
double round_trip(const char *p, char **q, char decimal, char sci, char tsep,
18171817
int skip_trailing, int *error, int *maybe_int) {
1818-
char *pc = NULL;
18191818
// 'normalize' representation to C-locale; replace decimal with '.' and
18201819
// remove t(housand)sep.
18211820
char *endptr = NULL;
1822-
if (decimal != '.' || tsep != '\0') {
1823-
pc = _str_copy_decimal_str_c(p, &endptr, decimal, tsep);
1824-
}
1821+
char *pc = _str_copy_decimal_str_c(p, &endptr, decimal, tsep);
18251822
// This is called from a nogil block in parsers.pyx
18261823
// so need to explicitly get GIL before Python calls
18271824
PyGILState_STATE gstate;
18281825
gstate = PyGILState_Ensure();
1829-
double r;
1830-
if (pc != NULL) {
1831-
char *endpc = NULL;
1832-
r = PyOS_string_to_double(pc, &endpc, 0);
1833-
// PyOS_string_to_double needs to consume the whole string
1834-
if (endpc == pc + strlen(pc)) {
1835-
if (q != NULL) {
1836-
// report endptr from source string (p)
1837-
*q = (char *) endptr;
1838-
}
1839-
} else {
1840-
*error = -1;
1841-
if (q != NULL) {
1842-
// p and pc are different len due to tsep removal. Can't report
1843-
// how much it has consumed of p. Just rewind to beginning.
1844-
*q = (char *)p;
1845-
}
1826+
char *endpc = NULL;
1827+
double r = PyOS_string_to_double(pc, &endpc, 0);
1828+
// PyOS_string_to_double needs to consume the whole string
1829+
if (endpc == pc + strlen(pc)) {
1830+
if (q != NULL) {
1831+
// report endptr from source string (p)
1832+
*q = (char *) endptr;
18461833
}
18471834
} else {
1848-
r = PyOS_string_to_double(p, q, 0);
1835+
*error = -1;
1836+
if (q != NULL) {
1837+
// p and pc are different len due to tsep removal. Can't report
1838+
// how much it has consumed of p. Just rewind to beginning.
1839+
*q = (char *)p;
1840+
}
18491841
}
18501842
if (maybe_int != NULL) *maybe_int = 0;
18511843
if (PyErr_Occurred() != NULL) *error = -1;

0 commit comments

Comments
 (0)