Skip to content

Commit be18b40

Browse files
committed
MAINT: Correct small cast issues on Windows
Use correct types to avoid downcasts on Windows
1 parent 075ec87 commit be18b40

File tree

5 files changed

+27
-24
lines changed

5 files changed

+27
-24
lines changed

pandas/_libs/lib.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ def has_infs(floating[:] arr) -> bool:
543543
def maybe_indices_to_slice(ndarray[intp_t, ndim=1] indices, int max_len):
544544
cdef:
545545
Py_ssize_t i, n = len(indices)
546-
int k, vstart, vlast, v
546+
intp_t k, vstart, vlast, v
547547

548548
if n == 0:
549549
return slice(0, 0)
@@ -553,7 +553,7 @@ def maybe_indices_to_slice(ndarray[intp_t, ndim=1] indices, int max_len):
553553
return indices
554554

555555
if n == 1:
556-
return slice(vstart, vstart + 1)
556+
return slice(vstart, <intp_t>(vstart + 1))
557557

558558
vlast = indices[n - 1]
559559
if vlast < 0 or max_len <= vlast:
@@ -569,12 +569,12 @@ def maybe_indices_to_slice(ndarray[intp_t, ndim=1] indices, int max_len):
569569
return indices
570570

571571
if k > 0:
572-
return slice(vstart, vlast + 1, k)
572+
return slice(vstart, <intp_t>(vlast + 1), k)
573573
else:
574574
if vlast == 0:
575575
return slice(vstart, None, k)
576576
else:
577-
return slice(vstart, vlast - 1, k)
577+
return slice(vstart, <intp_t>(vlast - 1), k)
578578

579579

580580
@cython.wraparound(False)

pandas/_libs/parsers.pyx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ cdef extern from "parser/tokenizer.h":
203203

204204
int usecols
205205

206-
int expected_fields
206+
Py_ssize_t expected_fields
207207
BadLineHandleMethod on_bad_lines
208208

209209
# floating point options
@@ -398,7 +398,7 @@ cdef class TextReader:
398398
else:
399399
if len(delimiter) > 1:
400400
raise ValueError('only length-1 separators excluded right now')
401-
self.parser.delimiter = ord(delimiter)
401+
self.parser.delimiter = <char>ord(delimiter)
402402

403403
# ----------------------------------------
404404
# parser options
@@ -410,21 +410,21 @@ cdef class TextReader:
410410
if lineterminator is not None:
411411
if len(lineterminator) != 1:
412412
raise ValueError('Only length-1 line terminators supported')
413-
self.parser.lineterminator = ord(lineterminator)
413+
self.parser.lineterminator = <char>ord(lineterminator)
414414

415415
if len(decimal) != 1:
416416
raise ValueError('Only length-1 decimal markers supported')
417-
self.parser.decimal = ord(decimal)
417+
self.parser.decimal = <char>ord(decimal)
418418

419419
if thousands is not None:
420420
if len(thousands) != 1:
421421
raise ValueError('Only length-1 thousands markers supported')
422-
self.parser.thousands = ord(thousands)
422+
self.parser.thousands = <char>ord(thousands)
423423

424424
if escapechar is not None:
425425
if len(escapechar) != 1:
426426
raise ValueError('Only length-1 escapes supported')
427-
self.parser.escapechar = ord(escapechar)
427+
self.parser.escapechar = <char>ord(escapechar)
428428

429429
self._set_quoting(quotechar, quoting)
430430

@@ -437,7 +437,7 @@ cdef class TextReader:
437437
if comment is not None:
438438
if len(comment) > 1:
439439
raise ValueError('Only length-1 comment characters supported')
440-
self.parser.commentchar = ord(comment)
440+
self.parser.commentchar = <char>ord(comment)
441441

442442
self.parser.on_bad_lines = on_bad_lines
443443

@@ -591,7 +591,7 @@ cdef class TextReader:
591591
raise TypeError('"quotechar" must be a 1-character string')
592592
else:
593593
self.parser.quoting = quoting
594-
self.parser.quotechar = ord(quote_char)
594+
self.parser.quotechar = <char>ord(quote_char)
595595

596596
cdef _make_skiprow_set(self):
597597
if util.is_integer_object(self.skiprows):
@@ -1045,8 +1045,8 @@ cdef class TextReader:
10451045
return results
10461046

10471047
# -> tuple["ArrayLike", int]:
1048-
cdef inline _convert_tokens(self, Py_ssize_t i, int start, int end,
1049-
object name, bint na_filter,
1048+
cdef inline _convert_tokens(self, Py_ssize_t i, int64_t start,
1049+
int64_t end, object name, bint na_filter,
10501050
kh_str_starts_t *na_hashset,
10511051
object na_flist, object col_dtype):
10521052

@@ -1537,7 +1537,7 @@ cdef inline int _try_double_nogil(parser_t *parser,
15371537
float64_t (*double_converter)(
15381538
const char *, char **, char,
15391539
char, char, int, int *, int *) nogil,
1540-
int col, int line_start, int line_end,
1540+
int64_t col, int64_t line_start, int64_t line_end,
15411541
bint na_filter, kh_str_starts_t *na_hashset,
15421542
bint use_na_flist,
15431543
const kh_float64_t *na_flist,

pandas/_libs/src/parser/tokenizer.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ GitHub. See Python Software Foundation License and BSD licenses for these.
2525

2626
#include "../headers/portable.h"
2727

28-
void coliter_setup(coliter_t *self, parser_t *parser, int i, int start) {
28+
void coliter_setup(coliter_t *self, parser_t *parser, int64_t i,
29+
int64_t start) {
2930
// column i, starting at 0
3031
self->words = parser->words;
3132
self->col = i;
@@ -411,7 +412,7 @@ static void append_warning(parser_t *self, const char *msg) {
411412
static int end_line(parser_t *self) {
412413
char *msg;
413414
int64_t fields;
414-
int ex_fields = self->expected_fields;
415+
int64_t ex_fields = self->expected_fields;
415416
int64_t bufsize = 100; // for error or warning messages
416417

417418
fields = self->line_fields[self->lines];
@@ -459,8 +460,8 @@ static int end_line(parser_t *self) {
459460
if (self->on_bad_lines == ERROR) {
460461
self->error_msg = malloc(bufsize);
461462
snprintf(self->error_msg, bufsize,
462-
"Expected %d fields in line %" PRIu64 ", saw %" PRId64 "\n",
463-
ex_fields, self->file_lines, fields);
463+
"Expected %" PRId64 " fields in line %" PRIu64 ", saw %"
464+
PRId64 "\n", ex_fields, self->file_lines, fields);
464465

465466
TRACE(("Error at line %d, %d fields\n", self->file_lines, fields));
466467

@@ -471,8 +472,9 @@ static int end_line(parser_t *self) {
471472
// pass up error message
472473
msg = malloc(bufsize);
473474
snprintf(msg, bufsize,
474-
"Skipping line %" PRIu64 ": expected %d fields, saw %"
475-
PRId64 "\n", self->file_lines, ex_fields, fields);
475+
"Skipping line %" PRIu64 ": expected %" PRId64
476+
" fields, saw %" PRId64 "\n",
477+
self->file_lines, ex_fields, fields);
476478
append_warning(self, msg);
477479
free(msg);
478480
}

pandas/_libs/src/parser/tokenizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef struct parser_t {
141141

142142
int usecols; // Boolean: 1: usecols provided, 0: none provided
143143

144-
int expected_fields;
144+
Py_ssize_t expected_fields;
145145
BadLineHandleMethod on_bad_lines;
146146

147147
// floating point options
@@ -175,7 +175,7 @@ typedef struct coliter_t {
175175
int64_t col;
176176
} coliter_t;
177177

178-
void coliter_setup(coliter_t *self, parser_t *parser, int i, int start);
178+
void coliter_setup(coliter_t *self, parser_t *parser, int64_t i, int64_t start);
179179

180180
#define COLITER_NEXT(iter, word) \
181181
do { \

pandas/_libs/tslibs/parsing.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ cdef inline object _parse_dateabbr_string(object date_string, datetime default,
422422
cdef:
423423
object ret
424424
# year initialized to prevent compiler warnings
425-
int year = -1, quarter = -1, month, mnum, date_len
425+
int year = -1, quarter = -1, month, mnum
426+
Py_ssize_t date_len
426427

427428
# special handling for possibilities eg, 2Q2005, 2Q05, 2005Q1, 05Q1
428429
assert isinstance(date_string, str)

0 commit comments

Comments
 (0)