Skip to content

Commit b0cf6c8

Browse files
committed
Consume initial/trailing space in round_trip
1 parent 36d5c9b commit b0cf6c8

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

pandas/_libs/src/parser/tokenizer.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,8 @@ char* _str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
17841784
size_t length = strlen(s);
17851785
char *s_copy = malloc(length + 1);
17861786
char *dst = s_copy;
1787+
// Skip leading whitespace.
1788+
while (isspace_ascii(*p)) p++;
17871789
// Copy Leading sign
17881790
if (*p == '+' || *p == '-') {
17891791
*dst++ = *p++;
@@ -1798,10 +1800,25 @@ char* _str_copy_decimal_str_c(const char *s, char **endpos, char decimal,
17981800
*dst++ = '.';
17991801
p++;
18001802
}
1801-
// Copy the remainder of the string as is.
1802-
strncpy(dst, p, length + 1 - (p - s));
1803+
// Copy fractional part after decimal (if any)
1804+
while (isdigit_ascii(*p)) {
1805+
*dst++ = *p++;
1806+
}
1807+
// Copy exponent if any
1808+
if (toupper_ascii(*p) == toupper_ascii('E')) {
1809+
*dst++ = *p++;
1810+
// Copy leading exponent sign (if any)
1811+
if (*p == '+' || *p == '-') {
1812+
*dst++ = *p++;
1813+
}
1814+
// Copy exponent digits
1815+
while (isdigit_ascii(*p)) {
1816+
*dst++ = *p++;
1817+
}
1818+
}
1819+
*dst++ = '\0'; // terminate
18031820
if (endpos != NULL)
1804-
*endpos = (char *)(s + length);
1821+
*endpos = (char *)p;
18051822
return s_copy;
18061823
}
18071824

@@ -1839,6 +1856,11 @@ double round_trip(const char *p, char **q, char decimal, char sci, char tsep,
18391856

18401857
PyGILState_Release(gstate);
18411858
free(pc);
1859+
if (skip_trailing && q != NULL && *q != p) {
1860+
while (isspace_ascii(**q)) {
1861+
(*q)++;
1862+
}
1863+
}
18421864
return r;
18431865
}
18441866

0 commit comments

Comments
 (0)