Skip to content

Commit 5eaf80b

Browse files
authored
CLN: remove redundant integer limit argument from interger parsers (#62714)
1 parent 533821c commit 5eaf80b

File tree

4 files changed

+21
-37
lines changed

4 files changed

+21
-37
lines changed

pandas/_libs/include/pandas/parser/pd_parser.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ typedef struct {
3737
int (*parser_trim_buffers)(parser_t *);
3838
int (*tokenize_all_rows)(parser_t *, const char *);
3939
int (*tokenize_nrows)(parser_t *, size_t, const char *);
40-
int64_t (*str_to_int64)(const char *, int64_t, int64_t, int *, char);
41-
uint64_t (*str_to_uint64)(uint_state *, const char *, int64_t, uint64_t,
42-
int *, char);
40+
int64_t (*str_to_int64)(const char *, int *, char);
41+
uint64_t (*str_to_uint64)(uint_state *, const char *, int *, char);
4342
double (*xstrtod)(const char *, char **, char, char, char, int, int *, int *);
4443
double (*precise_xstrtod)(const char *, char **, char, char, char, int, int *,
4544
int *);
@@ -87,12 +86,10 @@ static PandasParser_CAPI *PandasParserAPI = NULL;
8786
PandasParserAPI->tokenize_all_rows((self), (encoding_errors))
8887
#define tokenize_nrows(self, nrows, encoding_errors) \
8988
PandasParserAPI->tokenize_nrows((self), (nrows), (encoding_errors))
90-
#define str_to_int64(p_item, int_min, int_max, error, t_sep) \
91-
PandasParserAPI->str_to_int64((p_item), (int_min), (int_max), (error), \
92-
(t_sep))
93-
#define str_to_uint64(state, p_item, int_max, uint_max, error, t_sep) \
94-
PandasParserAPI->str_to_uint64((state), (p_item), (int_max), (uint_max), \
95-
(error), (t_sep))
89+
#define str_to_int64(p_item, error, t_sep) \
90+
PandasParserAPI->str_to_int64((p_item), (error), (t_sep))
91+
#define str_to_uint64(state, p_item, error, t_sep) \
92+
PandasParserAPI->str_to_uint64((state), (p_item), (error), (t_sep))
9693
#define xstrtod(p, q, decimal, sci, tsep, skip_trailing, error, maybe_int) \
9794
PandasParserAPI->xstrtod((p), (q), (decimal), (sci), (tsep), \
9895
(skip_trailing), (error), (maybe_int))

pandas/_libs/include/pandas/parser/tokenizer.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,9 @@ void uint_state_init(uint_state *self);
208208

209209
int uint64_conflict(uint_state *self);
210210

211-
uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
212-
uint64_t uint_max, int *error, char tsep);
213-
int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max,
214-
int *error, char tsep);
211+
uint64_t str_to_uint64(uint_state *state, const char *p_item, int *error,
212+
char tsep);
213+
int64_t str_to_int64(const char *p_item, int *error, char tsep);
215214
double xstrtod(const char *p, char **q, char decimal, char sci, char tsep,
216215
int skip_trailing, int *error, int *maybe_int);
217216
double precise_xstrtod(const char *p, char **q, char decimal, char sci,

pandas/_libs/parsers.pyx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ from numpy cimport (
6363
cnp.import_array()
6464

6565
from pandas._libs cimport util
66-
from pandas._libs.util cimport (
67-
INT64_MAX,
68-
INT64_MIN,
69-
UINT64_MAX,
70-
)
7166

7267
from pandas._libs import lib
7368

@@ -281,10 +276,8 @@ cdef extern from "pandas/parser/pd_parser.h":
281276
int tokenize_all_rows(parser_t *self, const char *encoding_errors) nogil
282277
int tokenize_nrows(parser_t *self, size_t nrows, const char *encoding_errors) nogil
283278

284-
int64_t str_to_int64(char *p_item, int64_t int_min,
285-
int64_t int_max, int *error, char tsep) nogil
286-
uint64_t str_to_uint64(uint_state *state, char *p_item, int64_t int_max,
287-
uint64_t uint_max, int *error, char tsep) nogil
279+
int64_t str_to_int64(char *p_item, int *error, char tsep) nogil
280+
uint64_t str_to_uint64(uint_state *state, char *p_item, int *error, char tsep) nogil
288281

289282
double xstrtod(const char *p, char **q, char decimal,
290283
char sci, char tsep, int skip_trailing,
@@ -1855,15 +1848,13 @@ cdef int _try_uint64_nogil(parser_t *parser, int64_t col,
18551848
data[i] = 0
18561849
continue
18571850

1858-
data[i] = str_to_uint64(state, word, INT64_MAX, UINT64_MAX,
1859-
&error, parser.thousands)
1851+
data[i] = str_to_uint64(state, word, &error, parser.thousands)
18601852
if error != 0:
18611853
return error
18621854
else:
18631855
for i in range(lines):
18641856
COLITER_NEXT(it, word)
1865-
data[i] = str_to_uint64(state, word, INT64_MAX, UINT64_MAX,
1866-
&error, parser.thousands)
1857+
data[i] = str_to_uint64(state, word, &error, parser.thousands)
18671858
if error != 0:
18681859
return error
18691860

@@ -1920,15 +1911,13 @@ cdef int _try_int64_nogil(parser_t *parser, int64_t col,
19201911
data[i] = NA
19211912
continue
19221913

1923-
data[i] = str_to_int64(word, INT64_MIN, INT64_MAX,
1924-
&error, parser.thousands)
1914+
data[i] = str_to_int64(word, &error, parser.thousands)
19251915
if error != 0:
19261916
return error
19271917
else:
19281918
for i in range(lines):
19291919
COLITER_NEXT(it, word)
1930-
data[i] = str_to_int64(word, INT64_MIN, INT64_MAX,
1931-
&error, parser.thousands)
1920+
data[i] = str_to_int64(word, &error, parser.thousands)
19321921
if error != 0:
19331922
return error
19341923

pandas/_libs/src/parser/tokenizer.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,8 +1872,7 @@ static int copy_string_without_char(char output[PROCESSED_WORD_CAPACITY],
18721872
return 0;
18731873
}
18741874

1875-
int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max,
1876-
int *error, char tsep) {
1875+
int64_t str_to_int64(const char *p_item, int *error, char tsep) {
18771876
const char *p = p_item;
18781877
// Skip leading spaces.
18791878
while (isspace_ascii(*p)) {
@@ -1907,7 +1906,7 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max,
19071906
char *endptr;
19081907
int64_t number = strtoll(p, &endptr, 10);
19091908

1910-
if (errno == ERANGE || number > int_max || number < int_min) {
1909+
if (errno == ERANGE) {
19111910
*error = ERROR_OVERFLOW;
19121911
errno = 0;
19131912
return 0;
@@ -1928,8 +1927,8 @@ int64_t str_to_int64(const char *p_item, int64_t int_min, int64_t int_max,
19281927
return number;
19291928
}
19301929

1931-
uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
1932-
uint64_t uint_max, int *error, char tsep) {
1930+
uint64_t str_to_uint64(uint_state *state, const char *p_item, int *error,
1931+
char tsep) {
19331932
const char *p = p_item;
19341933
// Skip leading spaces.
19351934
while (isspace_ascii(*p)) {
@@ -1967,7 +1966,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
19671966
char *endptr;
19681967
uint64_t number = strtoull(p, &endptr, 10);
19691968

1970-
if (errno == ERANGE || number > uint_max) {
1969+
if (errno == ERANGE) {
19711970
*error = ERROR_OVERFLOW;
19721971
errno = 0;
19731972
return 0;
@@ -1984,7 +1983,7 @@ uint64_t str_to_uint64(uint_state *state, const char *p_item, int64_t int_max,
19841983
return 0;
19851984
}
19861985

1987-
if (number > (uint64_t)int_max) {
1986+
if (number > (uint64_t)INT64_MAX) {
19881987
state->seen_uint = 1;
19891988
}
19901989

0 commit comments

Comments
 (0)