|
3 | 3 |
|
4 | 4 | from libc.stdio cimport fopen, fclose
|
5 | 5 | from libc.stdlib cimport malloc, free
|
6 |
| -from libc.string cimport strncpy, strlen |
| 6 | +from libc.string cimport strncpy, strlen, strcmp |
7 | 7 | cimport libc.stdio as stdio
|
8 | 8 |
|
9 | 9 | from cpython cimport (PyObject, PyBytes_FromString,
|
@@ -44,6 +44,9 @@ import sys
|
44 | 44 |
|
45 | 45 | cdef bint PY3 = (sys.version_info[0] >= 3)
|
46 | 46 |
|
| 47 | +cdef double INF = <double> np.inf |
| 48 | +cdef double NEGINF = -INF |
| 49 | + |
47 | 50 | cdef extern from "stdint.h":
|
48 | 51 | enum: UINT8_MAX
|
49 | 52 | enum: UINT16_MAX
|
@@ -458,7 +461,7 @@ cdef class TextReader:
|
458 | 461 |
|
459 | 462 | if self.memory_map:
|
460 | 463 | ptr = new_mmap(source)
|
461 |
| - if ptr == NULL: |
| 464 | + if ptr == NULL: |
462 | 465 | # fall back
|
463 | 466 | ptr = new_file_source(source, self.parser.chunksize)
|
464 | 467 | self.parser.cb_io = &buffer_file_bytes
|
@@ -1152,6 +1155,8 @@ cdef _to_fw_string(parser_t *parser, int col, int line_start,
|
1152 | 1155 |
|
1153 | 1156 | return result
|
1154 | 1157 |
|
| 1158 | +cdef char* cinf = b'inf' |
| 1159 | +cdef char* cneginf = b'-inf' |
1155 | 1160 |
|
1156 | 1161 | cdef _try_double(parser_t *parser, int col, int line_start, int line_end,
|
1157 | 1162 | bint na_filter, kh_str_t *na_hashset):
|
@@ -1182,14 +1187,24 @@ cdef _try_double(parser_t *parser, int col, int line_start, int line_end,
|
1182 | 1187 | else:
|
1183 | 1188 | error = to_double(word, data, parser.sci, parser.decimal)
|
1184 | 1189 | if error != 1:
|
1185 |
| - return None, None |
| 1190 | + if strcmp(word, cinf) == 0: |
| 1191 | + data[0] = INF |
| 1192 | + elif strcmp(word, cneginf) == 0: |
| 1193 | + data[0] = NEGINF |
| 1194 | + else: |
| 1195 | + return None, None |
1186 | 1196 | data += 1
|
1187 | 1197 | else:
|
1188 | 1198 | for i in range(lines):
|
1189 | 1199 | word = COLITER_NEXT(it)
|
1190 | 1200 | error = to_double(word, data, parser.sci, parser.decimal)
|
1191 | 1201 | if error != 1:
|
1192 |
| - return None, None |
| 1202 | + if strcmp(word, cinf) == 0: |
| 1203 | + data[0] = INF |
| 1204 | + elif strcmp(word, cneginf) == 0: |
| 1205 | + data[0] = NEGINF |
| 1206 | + else: |
| 1207 | + return None, None |
1193 | 1208 | data += 1
|
1194 | 1209 |
|
1195 | 1210 | return result, na_count
|
@@ -1492,18 +1507,18 @@ cdef _apply_converter(object f, parser_t *parser, int col,
|
1492 | 1507 | c_encoding, errors)
|
1493 | 1508 | result[i] = f(val)
|
1494 | 1509 |
|
1495 |
| - values = lib.maybe_convert_objects(result) |
| 1510 | + return lib.maybe_convert_objects(result) |
1496 | 1511 |
|
1497 |
| - if issubclass(values.dtype.type, (np.number, np.bool_)): |
1498 |
| - return values |
| 1512 | + # if issubclass(values.dtype.type, (np.number, np.bool_)): |
| 1513 | + # return values |
1499 | 1514 |
|
1500 |
| - # XXX |
1501 |
| - na_values = set(['']) |
1502 |
| - try: |
1503 |
| - return lib.maybe_convert_numeric(values, na_values, False) |
1504 |
| - except Exception: |
1505 |
| - na_count = lib.sanitize_objects(values, na_values, False) |
1506 |
| - return result |
| 1515 | + # # XXX |
| 1516 | + # na_values = set(['']) |
| 1517 | + # try: |
| 1518 | + # return lib.maybe_convert_numeric(values, na_values, False) |
| 1519 | + # except Exception: |
| 1520 | + # na_count = lib.sanitize_objects(values, na_values, False) |
| 1521 | + # return result |
1507 | 1522 |
|
1508 | 1523 | def _to_structured_array(dict columns, object names):
|
1509 | 1524 | cdef:
|
|
0 commit comments