Skip to content

remove cnp usage from sas.pyx #22111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions pandas/io/sas/sas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
# cython: boundscheck=False, initializedcheck=False

import numpy as np
cimport numpy as cnp
from numpy cimport uint8_t, uint16_t, int8_t, int64_t, ndarray
import sas_constants as const

ctypedef signed long long int64_t
ctypedef unsigned char uint8_t
ctypedef unsigned short uint16_t

# rle_decompress decompresses data using a Run Length Encoding
# algorithm. It is partially documented here:
#
# https://cran.r-project.org/web/packages/sas7bdat/vignettes/sas7bdat.pdf
cdef ndarray[uint8_t, ndim=1] rle_decompress(
int result_length, ndarray[uint8_t, ndim=1] inbuff):
cdef const uint8_t[:] rle_decompress(int result_length,
const uint8_t[:] inbuff):

cdef:
uint8_t control_byte, x
uint8_t [:] result = np.zeros(result_length, np.uint8)
uint8_t[:] result = np.zeros(result_length, np.uint8)
int rpos = 0, ipos = 0, length = len(inbuff)
int i, nbytes, end_of_first_byte

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

cdef:
uint8_t cmd
uint16_t ctrl_bits, ctrl_mask = 0, ofs, cnt
int ipos = 0, rpos = 0, k
uint8_t [:] outbuff = np.zeros(result_length, dtype=np.uint8)
uint8_t[:] outbuff = np.zeros(result_length, dtype=np.uint8)

ii = -1

Expand Down Expand Up @@ -230,8 +232,8 @@ cdef class Parser(object):
int subheader_pointer_length
int current_page_type
bint is_little_endian
ndarray[uint8_t, ndim=1] (*decompress)(
int result_length, ndarray[uint8_t, ndim=1] inbuff)
const uint8_t[:] (*decompress)(int result_length,
const uint8_t[:] inbuff)
object parser

def __init__(self, object parser):
Expand Down Expand Up @@ -395,7 +397,7 @@ cdef class Parser(object):
Py_ssize_t j
int s, k, m, jb, js, current_row
int64_t lngt, start, ct
ndarray[uint8_t, ndim=1] source
const uint8_t[:] source
int64_t[:] column_types
int64_t[:] lengths
int64_t[:] offsets
Expand Down Expand Up @@ -434,8 +436,8 @@ cdef class Parser(object):
jb += 1
elif column_types[j] == column_type_string:
# string
string_chunk[js, current_row] = source[start:(
start + lngt)].tostring().rstrip()
string_chunk[js, current_row] = np.array(source[start:(
start + lngt)]).tostring().rstrip()
js += 1

self.current_row_on_page_index += 1
Expand Down