1
1
# Copyright (c) 2012, Lambda Foundry, Inc.
2
2
# See LICENSE for the license
3
+ import os
4
+ import sys
5
+ import time
6
+ import warnings
7
+
8
+ from csv import QUOTE_MINIMAL, QUOTE_NONNUMERIC, QUOTE_NONE
3
9
4
10
from libc.stdio cimport fopen, fclose
5
11
from libc.stdlib cimport malloc, free
6
12
from libc.string cimport strncpy, strlen, strcmp, strcasecmp
7
- cimport libc.stdio as stdio
8
- import warnings
9
13
10
- from csv import QUOTE_MINIMAL, QUOTE_NONNUMERIC, QUOTE_NONE
14
+ cimport cython
15
+ from cython cimport Py_ssize_t
16
+
11
17
from cpython cimport (PyObject, PyBytes_FromString,
12
18
PyBytes_AsString, PyBytes_Check,
13
19
PyUnicode_Check, PyUnicode_AsUTF8String,
14
20
PyErr_Occurred, PyErr_Fetch)
15
21
from cpython.ref cimport Py_XDECREF
16
- from pandas.errors import (ParserError, DtypeWarning,
17
- EmptyDataError, ParserWarning)
18
22
19
- # Import CParserError as alias of ParserError for backwards compatibility.
20
- # Ultimately, we want to remove this import. See gh-12665 and gh-14479.
21
- CParserError = ParserError
22
23
23
24
cdef extern from " Python.h" :
24
25
object PyUnicode_FromString(char * v)
@@ -29,15 +30,24 @@ cdef extern from "Python.h":
29
30
cdef extern from " stdlib.h" :
30
31
void memcpy(void * dst, void * src, size_t n)
31
32
32
- cimport cython
33
- cimport numpy as cnp
34
33
34
+ import numpy as np
35
+ cimport numpy as cnp
35
36
from numpy cimport ndarray, uint8_t, uint64_t, int64_t
37
+ cnp.import_array()
36
38
37
- import numpy as np
38
- cimport util
39
+ from util cimport UINT64_MAX, INT64_MAX, INT64_MIN
40
+ import lib
41
+
42
+ from khash cimport (
43
+ khiter_t,
44
+ kh_str_t, kh_init_str, kh_put_str, kh_exist_str,
45
+ kh_get_str, kh_destroy_str,
46
+ kh_float64_t, kh_get_float64, kh_destroy_float64,
47
+ kh_put_float64, kh_init_float64,
48
+ kh_strbox_t, kh_put_strbox, kh_get_strbox, kh_init_strbox,
49
+ kh_destroy_strbox)
39
50
40
- import pandas._libs.lib as lib
41
51
import pandas.compat as compat
42
52
from pandas.core.dtypes.common import (
43
53
is_categorical_dtype, CategoricalDtype,
@@ -47,55 +57,44 @@ from pandas.core.dtypes.common import (
47
57
pandas_dtype)
48
58
from pandas.core.categorical import Categorical
49
59
from pandas.core.dtypes.concat import union_categoricals
50
-
51
60
import pandas.io.common as com
52
61
53
- import time
54
- import os
55
-
56
- cnp.import_array()
62
+ from pandas.errors import (ParserError, DtypeWarning,
63
+ EmptyDataError, ParserWarning)
57
64
58
- from khash cimport (
59
- khiter_t,
60
- kh_str_t, kh_init_str, kh_put_str, kh_exist_str,
61
- kh_get_str, kh_destroy_str,
62
- kh_float64_t, kh_get_float64, kh_destroy_float64,
63
- kh_put_float64, kh_init_float64,
64
- kh_strbox_t, kh_put_strbox, kh_get_strbox, kh_init_strbox,
65
- kh_destroy_strbox)
65
+ # Import CParserError as alias of ParserError for backwards compatibility.
66
+ # Ultimately, we want to remove this import. See gh-12665 and gh-14479.
67
+ CParserError = ParserError
66
68
67
- import sys
68
69
69
70
cdef bint PY3 = (sys.version_info[0 ] >= 3 )
70
71
71
72
cdef double INF = < double > np.inf
72
73
cdef double NEGINF = - INF
73
74
74
- cdef extern from " headers/stdint.h" :
75
- enum : UINT8_MAX
76
- enum : UINT16_MAX
77
- enum : UINT32_MAX
78
- enum : UINT64_MAX
79
- enum : INT8_MIN
80
- enum : INT8_MAX
81
- enum : INT16_MIN
82
- enum : INT16_MAX
83
- enum : INT32_MAX
84
- enum : INT32_MIN
85
- enum : INT64_MAX
86
- enum : INT64_MIN
87
-
88
- cdef extern from " headers/portable.h" :
89
- pass
90
75
91
76
cdef extern from " errno.h" :
92
77
int errno
93
78
79
+ cdef extern from " headers/portable.h" :
80
+ # I *think* this is here so that strcasecmp is defined on Windows
81
+ # so we don't get
82
+ # `parsers.obj : error LNK2001: unresolved external symbol strcasecmp`
83
+ # in Appveyor.
84
+ # In a sane world, the `from libc.string cimport` above would fail
85
+ # loudly.
86
+ pass
87
+
94
88
try :
95
89
basestring
96
90
except NameError :
97
91
basestring = str
98
92
93
+ cdef extern from " src/numpy_helper.h" :
94
+ object sarr_from_data(cnp.dtype, int length, void * data)
95
+ void transfer_object_column(char * dst, char * src, size_t stride,
96
+ size_t length)
97
+
99
98
cdef extern from " parser/tokenizer.h" :
100
99
101
100
ctypedef enum ParserState:
@@ -2360,7 +2359,7 @@ def _to_structured_array(dict columns, object names, object usecols):
2360
2359
# We own the data.
2361
2360
buf = < char * > malloc(length * stride)
2362
2361
2363
- recs = util. sarr_from_data(dt, length, buf)
2362
+ recs = sarr_from_data(dt, length, buf)
2364
2363
assert (recs.flags.owndata)
2365
2364
2366
2365
for i in range (nfields):
@@ -2385,7 +2384,7 @@ cdef _fill_structured_column(char *dst, char* src, int64_t elsize,
2385
2384
int64_t i
2386
2385
2387
2386
if incref:
2388
- util. transfer_object_column(dst, src, stride, length)
2387
+ transfer_object_column(dst, src, stride, length)
2389
2388
else :
2390
2389
for i in range (length):
2391
2390
memcpy(dst, src, elsize)
0 commit comments