Skip to content

Commit e9ca781

Browse files
datapythonistajreback
authored andcommitted
Fixing typo in cython casting lint, and making it azure friendly (#23486)
1 parent 0f99f61 commit e9ca781

11 files changed

+34
-34
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
4949
# Note: this grep pattern is (intended to be) equivalent to the python
5050
# regex r'(?<![ ->])> '
5151
MSG='Linting .pyx code for spacing conventions in casting' ; echo $MSG
52-
! grep -r -E --include '*.pyx' --include '*.pxi.in' '> ' pandas/_libs | grep -v '[ ->]> '
52+
! grep -r -E --include '*.pyx' --include '*.pxi.in' '[a-zA-Z0-9*]> ' pandas/_libs
5353
RET=$(($RET + $?)) ; echo $MSG "DONE"
5454

5555
# readability/casting: Warnings about C casting instead of C++ casting

pandas/_libs/algos.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ def is_lexsorted(list_of_arrays: list) -> bint:
128128
nlevels = len(list_of_arrays)
129129
n = len(list_of_arrays[0])
130130

131-
cdef int64_t **vecs = <int64_t**> malloc(nlevels * sizeof(int64_t*))
131+
cdef int64_t **vecs = <int64_t**>malloc(nlevels * sizeof(int64_t*))
132132
for i in range(nlevels):
133133
arr = list_of_arrays[i]
134134
assert arr.dtype.name == 'int64'
135-
vecs[i] = <int64_t*> cnp.PyArray_DATA(arr)
135+
vecs[i] = <int64_t*>cnp.PyArray_DATA(arr)
136136

137137
# Assume uniqueness??
138138
with nogil:

pandas/_libs/groupby.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
4444
if na_count == n:
4545
return NaN
4646

47-
tmp = <float64_t*> malloc((n - na_count) * sizeof(float64_t))
47+
tmp = <float64_t*>malloc((n - na_count) * sizeof(float64_t))
4848

4949
j = 0
5050
for i in range(n):
@@ -121,7 +121,7 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
121121
counts[:] = _counts[1:]
122122

123123
data = np.empty((K, N), dtype=np.float64)
124-
ptr = <float64_t*> cnp.PyArray_DATA(data)
124+
ptr = <float64_t*>cnp.PyArray_DATA(data)
125125

126126
take_2d_axis1_float64_float64(values.T, indexer, out=data)
127127

pandas/_libs/hashing.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def hash_object_array(object[:] arr, object key, object encoding='utf8'):
5454
n = len(arr)
5555

5656
# create an array of bytes
57-
vecs = <char **> malloc(n * sizeof(char *))
58-
lens = <uint64_t*> malloc(n * sizeof(uint64_t))
57+
vecs = <char **>malloc(n * sizeof(char *))
58+
lens = <uint64_t*>malloc(n * sizeof(uint64_t))
5959

6060
for i in range(n):
6161
val = arr[i]

pandas/_libs/hashtable_class_helper.pxi.in

+5-5
Original file line numberDiff line numberDiff line change
@@ -590,13 +590,13 @@ cdef class StringHashTable(HashTable):
590590
cdef:
591591
Py_ssize_t i, n = len(values)
592592
ndarray[int64_t] labels = np.empty(n, dtype=np.int64)
593-
int64_t *resbuf = <int64_t*> labels.data
593+
int64_t *resbuf = <int64_t*>labels.data
594594
khiter_t k
595595
kh_str_t *table = self.table
596596
const char *v
597597
const char **vecs
598598

599-
vecs = <const char **> malloc(n * sizeof(char *))
599+
vecs = <const char **>malloc(n * sizeof(char *))
600600
for i in range(n):
601601
val = values[i]
602602
v = util.get_c_string(val)
@@ -639,7 +639,7 @@ cdef class StringHashTable(HashTable):
639639
const char *v
640640
const char **vecs
641641

642-
vecs = <const char **> malloc(n * sizeof(char *))
642+
vecs = <const char **>malloc(n * sizeof(char *))
643643
uindexer = np.empty(n, dtype=np.int64)
644644
for i in range(n):
645645
val = values[i]
@@ -674,7 +674,7 @@ cdef class StringHashTable(HashTable):
674674
int64_t[:] locs = np.empty(n, dtype=np.int64)
675675

676676
# these by-definition *must* be strings
677-
vecs = <char **> malloc(n * sizeof(char *))
677+
vecs = <char **>malloc(n * sizeof(char *))
678678
for i in range(n):
679679
val = values[i]
680680

@@ -707,7 +707,7 @@ cdef class StringHashTable(HashTable):
707707
khiter_t k
708708

709709
# these by-definition *must* be strings
710-
vecs = <const char **> malloc(n * sizeof(char *))
710+
vecs = <const char **>malloc(n * sizeof(char *))
711711
for i in range(n):
712712
val = values[i]
713713

pandas/_libs/parsers.pyx

+11-11
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ cdef class TextReader:
361361
if not isinstance(encoding, bytes):
362362
encoding = encoding.encode('utf-8')
363363
encoding = encoding.lower()
364-
self.c_encoding = <char*> encoding
364+
self.c_encoding = <char*>encoding
365365
else:
366366
self.c_encoding = NULL
367367

@@ -611,7 +611,7 @@ cdef class TextReader:
611611
for i in self.skiprows:
612612
parser_add_skiprow(self.parser, i)
613613
else:
614-
self.parser.skipfunc = <PyObject *> self.skiprows
614+
self.parser.skipfunc = <PyObject *>self.skiprows
615615

616616
cdef _setup_parser_source(self, source):
617617
cdef:
@@ -668,7 +668,7 @@ cdef class TextReader:
668668
source = icom.UTF8Recoder(source,
669669
self.encoding.decode('utf-8'))
670670
self.encoding = b'utf-8'
671-
self.c_encoding = <char*> self.encoding
671+
self.c_encoding = <char*>self.encoding
672672

673673
self.handle = source
674674

@@ -1444,7 +1444,7 @@ cdef _string_box_factorize(parser_t *parser, int64_t col,
14441444
pyval = PyBytes_FromString(word)
14451445

14461446
k = kh_put_strbox(table, word, &ret)
1447-
table.vals[k] = <PyObject*> pyval
1447+
table.vals[k] = <PyObject*>pyval
14481448

14491449
result[i] = pyval
14501450

@@ -1498,7 +1498,7 @@ cdef _string_box_utf8(parser_t *parser, int64_t col,
14981498
pyval = PyUnicode_FromString(word)
14991499

15001500
k = kh_put_strbox(table, word, &ret)
1501-
table.vals[k] = <PyObject *> pyval
1501+
table.vals[k] = <PyObject *>pyval
15021502

15031503
result[i] = pyval
15041504

@@ -1556,7 +1556,7 @@ cdef _string_box_decode(parser_t *parser, int64_t col,
15561556
pyval = PyUnicode_Decode(word, size, encoding, errors)
15571557

15581558
k = kh_put_strbox(table, word, &ret)
1559-
table.vals[k] = <PyObject *> pyval
1559+
table.vals[k] = <PyObject *>pyval
15601560

15611561
result[i] = pyval
15621562

@@ -1648,7 +1648,7 @@ cdef _to_fw_string(parser_t *parser, int64_t col, int64_t line_start,
16481648
ndarray result
16491649

16501650
result = np.empty(line_end - line_start, dtype='|S%d' % width)
1651-
data = <char*> result.data
1651+
data = <char*>result.data
16521652

16531653
with nogil:
16541654
_to_fw_string_nogil(parser, col, line_start, line_end, width, data)
@@ -1695,7 +1695,7 @@ cdef _try_double(parser_t *parser, int64_t col,
16951695

16961696
lines = line_end - line_start
16971697
result = np.empty(lines, dtype=np.float64)
1698-
data = <double *> result.data
1698+
data = <double *>result.data
16991699
na_fset = kset_float64_from_list(na_flist)
17001700
if parser.double_converter_nogil != NULL: # if it can run without the GIL
17011701
with nogil:
@@ -1803,7 +1803,7 @@ cdef _try_uint64(parser_t *parser, int64_t col,
18031803

18041804
lines = line_end - line_start
18051805
result = np.empty(lines, dtype=np.uint64)
1806-
data = <uint64_t *> result.data
1806+
data = <uint64_t *>result.data
18071807

18081808
uint_state_init(&state)
18091809
coliter_setup(&it, parser, col, line_start)
@@ -1879,7 +1879,7 @@ cdef _try_int64(parser_t *parser, int64_t col,
18791879

18801880
lines = line_end - line_start
18811881
result = np.empty(lines, dtype=np.int64)
1882-
data = <int64_t *> result.data
1882+
data = <int64_t *>result.data
18831883
coliter_setup(&it, parser, col, line_start)
18841884
with nogil:
18851885
error = _try_int64_nogil(parser, col, line_start, line_end,
@@ -1951,7 +1951,7 @@ cdef _try_bool_flex(parser_t *parser, int64_t col,
19511951

19521952
lines = line_end - line_start
19531953
result = np.empty(lines, dtype=np.uint8)
1954-
data = <uint8_t *> result.data
1954+
data = <uint8_t *>result.data
19551955
with nogil:
19561956
error = _try_bool_flex_nogil(parser, col, line_start, line_end,
19571957
na_filter, na_hashset, true_hashset,

pandas/_libs/reduction.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ cdef class Slider:
467467
self.buf.strides[0] = self.stride
468468

469469
cpdef advance(self, Py_ssize_t k):
470-
self.buf.data = <char*> self.buf.data + self.stride * k
470+
self.buf.data = <char*>self.buf.data + self.stride * k
471471

472472
cdef move(self, int start, int end):
473473
"""
@@ -572,7 +572,7 @@ cdef class BlockSlider:
572572
self.idx_slider = Slider(
573573
self.frame.index.values, self.dummy.index.values)
574574

575-
self.base_ptrs = <char**> malloc(sizeof(char*) * len(self.blocks))
575+
self.base_ptrs = <char**>malloc(sizeof(char*) * len(self.blocks))
576576
for i, block in enumerate(self.blocks):
577577
self.base_ptrs[i] = (<ndarray>block).data
578578

pandas/_libs/sparse.pyx

+3-3
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ cdef class BlockIndex(SparseIndex):
342342
self.blengths = np.ascontiguousarray(blengths, dtype=np.int32)
343343

344344
# in case we need
345-
self.locbuf = <int32_t*> self.blocs.data
346-
self.lenbuf = <int32_t*> self.blengths.data
345+
self.locbuf = <int32_t*>self.blocs.data
346+
self.lenbuf = <int32_t*>self.blengths.data
347347

348348
self.length = length
349349
self.nblocks = np.int32(len(self.blocs))
@@ -853,7 +853,7 @@ def get_reindexer(ndarray[object, ndim=1] values, dict index_map):
853853
# SparseIndex index):
854854

855855
# self.index = index
856-
# self.buf = <float64_t*> values.data
856+
# self.buf = <float64_t*>values.data
857857

858858

859859
def reindex_integer(ndarray[float64_t, ndim=1] values,

pandas/_libs/tslibs/conversion.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
920920

921921
trans, deltas, typ = get_dst_info(tz)
922922

923-
tdata = <int64_t*> cnp.PyArray_DATA(trans)
923+
tdata = <int64_t*>cnp.PyArray_DATA(trans)
924924
ntrans = len(trans)
925925

926926
# Determine whether each date lies left of the DST transition (store in

pandas/_libs/tslibs/period.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ cdef object _period_strftime(int64_t value, int freq, object fmt):
12601260
fmt = fmt.replace(pat, repl)
12611261
found_pat[i] = True
12621262

1263-
formatted = c_strftime(&dts, <char*> fmt)
1263+
formatted = c_strftime(&dts, <char*>fmt)
12641264

12651265
result = util.char_to_string(formatted)
12661266
free(formatted)

pandas/_libs/window.pyx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1611,17 +1611,17 @@ def roll_generic(object obj,
16111611
output[i] = NaN
16121612

16131613
# remaining full-length windows
1614-
buf = <float64_t *> arr.data
1614+
buf = <float64_t *>arr.data
16151615
bufarr = np.empty(win, dtype=float)
1616-
oldbuf = <float64_t *> bufarr.data
1616+
oldbuf = <float64_t *>bufarr.data
16171617
for i from (win - offset) <= i < (N - offset):
16181618
buf = buf + 1
1619-
bufarr.data = <char *> buf
1619+
bufarr.data = <char *>buf
16201620
if counts[i] >= minp:
16211621
output[i] = func(bufarr, *args, **kwargs)
16221622
else:
16231623
output[i] = NaN
1624-
bufarr.data = <char *> oldbuf
1624+
bufarr.data = <char *>oldbuf
16251625

16261626
# truncated windows at the end
16271627
for i from int_max(N - offset, 0) <= i < N:

0 commit comments

Comments
 (0)