Skip to content

Commit 7fb878a

Browse files
authored
CLN: Added static types (#33126)
1 parent 2627978 commit 7fb878a

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

pandas/_libs/parsers.pyx

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ cimport numpy as cnp
3434
from numpy cimport ndarray, uint8_t, uint64_t, int64_t, float64_t
3535
cnp.import_array()
3636

37+
cimport pandas._libs.util as util
3738
from pandas._libs.util cimport UINT64_MAX, INT64_MAX, INT64_MIN
3839
import pandas._libs.lib as lib
3940

@@ -279,73 +280,61 @@ cdef class TextReader:
279280

280281
cdef public:
281282
int64_t leading_cols, table_width, skipfooter, buffer_lines
282-
object allow_leading_cols
283-
object delimiter, converters, delim_whitespace
283+
bint allow_leading_cols, mangle_dupe_cols, memory_map, low_memory
284+
bint delim_whitespace
285+
object delimiter, converters
284286
object na_values
285-
object memory_map
286287
object header, orig_header, names, header_start, header_end
287288
object index_col
288-
object low_memory
289289
object skiprows
290290
object dtype
291291
object encoding
292292
object compression
293-
object mangle_dupe_cols
294293
object usecols
295294
list dtype_cast_order
296295
set unnamed_cols
297296
set noconvert
298297

299298
def __cinit__(self, source,
300299
delimiter=b',',
301-
302300
header=0,
303301
header_start=0,
304302
header_end=0,
305303
index_col=None,
306304
names=None,
307-
308-
memory_map=False,
305+
bint memory_map=False,
309306
tokenize_chunksize=DEFAULT_CHUNKSIZE,
310-
delim_whitespace=False,
311-
307+
bint delim_whitespace=False,
312308
compression=None,
313-
314309
converters=None,
315-
316-
skipinitialspace=False,
310+
bint skipinitialspace=False,
317311
escapechar=None,
318-
doublequote=True,
312+
bint doublequote=True,
319313
quotechar=b'"',
320314
quoting=0,
321315
lineterminator=None,
322-
323316
encoding=None,
324-
325317
comment=None,
326318
decimal=b'.',
327319
thousands=None,
328-
329320
dtype=None,
330321
usecols=None,
331-
error_bad_lines=True,
332-
warn_bad_lines=True,
333-
334-
na_filter=True,
322+
bint error_bad_lines=True,
323+
bint warn_bad_lines=True,
324+
bint na_filter=True,
335325
na_values=None,
336326
na_fvalues=None,
337-
keep_default_na=True,
338-
327+
bint keep_default_na=True,
339328
true_values=None,
340329
false_values=None,
341-
allow_leading_cols=True,
342-
low_memory=False,
330+
bint allow_leading_cols=True,
331+
bint low_memory=False,
343332
skiprows=None,
344333
skipfooter=0,
345-
verbose=False,
346-
mangle_dupe_cols=True,
334+
bint verbose=False,
335+
bint mangle_dupe_cols=True,
347336
float_precision=None,
348-
skip_blank_lines=True):
337+
bint skip_blank_lines=True):
349338

350339
# set encoding for native Python and C library
351340
if encoding is not None:
@@ -591,7 +580,7 @@ cdef class TextReader:
591580
self.parser.quotechar = ord(quote_char)
592581

593582
cdef _make_skiprow_set(self):
594-
if isinstance(self.skiprows, (int, np.integer)):
583+
if util.is_integer_object(self.skiprows):
595584
parser_set_skipfirstnrows(self.parser, self.skiprows)
596585
elif not callable(self.skiprows):
597586
for i in self.skiprows:
@@ -683,15 +672,14 @@ cdef class TextReader:
683672
# header is now a list of lists, so field_count should use header[0]
684673

685674
cdef:
686-
Py_ssize_t i, start, field_count, passed_count, unnamed_count
675+
Py_ssize_t i, start, field_count, passed_count, unnamed_count, level
687676
char *word
688677
object name, old_name
689678
uint64_t hr, data_line = 0
690679
char *errors = "strict"
691680
StringPath path = _string_path(self.c_encoding)
692-
693-
header = []
694-
unnamed_cols = set()
681+
list header = []
682+
set unnamed_cols = set()
695683

696684
if self.parser.header_start >= 0:
697685

@@ -847,7 +835,7 @@ cdef class TextReader:
847835
cdef _read_low_memory(self, rows):
848836
cdef:
849837
size_t rows_read = 0
850-
chunks = []
838+
list chunks = []
851839

852840
if rows is None:
853841
while True:
@@ -2038,12 +2026,11 @@ def _concatenate_chunks(list chunks):
20382026
cdef:
20392027
list names = list(chunks[0].keys())
20402028
object name
2041-
list warning_columns
2029+
list warning_columns = []
20422030
object warning_names
20432031
object common_type
20442032

20452033
result = {}
2046-
warning_columns = list()
20472034
for name in names:
20482035
arrs = [chunk.pop(name) for chunk in chunks]
20492036
# Check each arr for consistent types.
@@ -2147,7 +2134,7 @@ def _maybe_encode(values):
21472134

21482135

21492136
def sanitize_objects(ndarray[object] values, set na_values,
2150-
convert_empty=True):
2137+
bint convert_empty=True):
21512138
"""
21522139
Convert specified values, including the given set na_values and empty
21532140
strings if convert_empty is True, to np.nan.
@@ -2156,7 +2143,7 @@ def sanitize_objects(ndarray[object] values, set na_values,
21562143
----------
21572144
values : ndarray[object]
21582145
na_values : set
2159-
convert_empty : bool (default True)
2146+
convert_empty : bool, default True
21602147
"""
21612148
cdef:
21622149
Py_ssize_t i, n

0 commit comments

Comments
 (0)