Skip to content

Commit 21cbca6

Browse files
jbrockmendeljreback
authored andcommitted
remove cnp usage from sas.pyx (#22111)
1 parent 415a01e commit 21cbca6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pandas/io/sas/sas.pyx

+15-13
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
# cython: boundscheck=False, initializedcheck=False
33

44
import numpy as np
5-
cimport numpy as cnp
6-
from numpy cimport uint8_t, uint16_t, int8_t, int64_t, ndarray
75
import sas_constants as const
86

7+
ctypedef signed long long int64_t
8+
ctypedef unsigned char uint8_t
9+
ctypedef unsigned short uint16_t
10+
911
# rle_decompress decompresses data using a Run Length Encoding
1012
# algorithm. It is partially documented here:
1113
#
1214
# https://cran.r-project.org/web/packages/sas7bdat/vignettes/sas7bdat.pdf
13-
cdef ndarray[uint8_t, ndim=1] rle_decompress(
14-
int result_length, ndarray[uint8_t, ndim=1] inbuff):
15+
cdef const uint8_t[:] rle_decompress(int result_length,
16+
const uint8_t[:] inbuff):
1517

1618
cdef:
1719
uint8_t control_byte, x
18-
uint8_t [:] result = np.zeros(result_length, np.uint8)
20+
uint8_t[:] result = np.zeros(result_length, np.uint8)
1921
int rpos = 0, ipos = 0, length = len(inbuff)
2022
int i, nbytes, end_of_first_byte
2123

@@ -115,14 +117,14 @@ cdef ndarray[uint8_t, ndim=1] rle_decompress(
115117
# rdc_decompress decompresses data using the Ross Data Compression algorithm:
116118
#
117119
# http://collaboration.cmc.ec.gc.ca/science/rpn/biblio/ddj/Website/articles/CUJ/1992/9210/ross/ross.htm
118-
cdef ndarray[uint8_t, ndim=1] rdc_decompress(
119-
int result_length, ndarray[uint8_t, ndim=1] inbuff):
120+
cdef const uint8_t[:] rdc_decompress(int result_length,
121+
const uint8_t[:] inbuff):
120122

121123
cdef:
122124
uint8_t cmd
123125
uint16_t ctrl_bits, ctrl_mask = 0, ofs, cnt
124126
int ipos = 0, rpos = 0, k
125-
uint8_t [:] outbuff = np.zeros(result_length, dtype=np.uint8)
127+
uint8_t[:] outbuff = np.zeros(result_length, dtype=np.uint8)
126128

127129
ii = -1
128130

@@ -230,8 +232,8 @@ cdef class Parser(object):
230232
int subheader_pointer_length
231233
int current_page_type
232234
bint is_little_endian
233-
ndarray[uint8_t, ndim=1] (*decompress)(
234-
int result_length, ndarray[uint8_t, ndim=1] inbuff)
235+
const uint8_t[:] (*decompress)(int result_length,
236+
const uint8_t[:] inbuff)
235237
object parser
236238

237239
def __init__(self, object parser):
@@ -395,7 +397,7 @@ cdef class Parser(object):
395397
Py_ssize_t j
396398
int s, k, m, jb, js, current_row
397399
int64_t lngt, start, ct
398-
ndarray[uint8_t, ndim=1] source
400+
const uint8_t[:] source
399401
int64_t[:] column_types
400402
int64_t[:] lengths
401403
int64_t[:] offsets
@@ -434,8 +436,8 @@ cdef class Parser(object):
434436
jb += 1
435437
elif column_types[j] == column_type_string:
436438
# string
437-
string_chunk[js, current_row] = source[start:(
438-
start + lngt)].tostring().rstrip()
439+
string_chunk[js, current_row] = np.array(source[start:(
440+
start + lngt)]).tostring().rstrip()
439441
js += 1
440442

441443
self.current_row_on_page_index += 1

0 commit comments

Comments
 (0)