Skip to content

Commit 58ecadf

Browse files
jbrockmendeljreback
authored andcommitted
BLD: fix some build warnings (#29271)
1 parent 109d682 commit 58ecadf

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

pandas/_libs/algos_common_helper.pxi.in

+41-40
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,55 @@ ctypedef fused out_t:
2222
def diff_2d(ndarray[diff_t, ndim=2] arr,
2323
ndarray[out_t, ndim=2] out,
2424
Py_ssize_t periods, int axis):
25+
cdef:
26+
Py_ssize_t i, j, sx, sy
2527

2628
# Disable for unsupported dtype combinations,
2729
# see https://github.com/cython/cython/issues/2646
28-
if out_t is float32_t:
29-
if not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t):
30-
raise NotImplementedError
30+
if (out_t is float32_t
31+
and not (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
32+
raise NotImplementedError
33+
elif (out_t is float64_t
34+
and (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t)):
35+
raise NotImplementedError
3136
else:
32-
if (diff_t is float32_t or diff_t is int8_t or diff_t is int16_t):
33-
raise NotImplementedError
34-
35-
cdef:
36-
Py_ssize_t i, j, sx, sy
37-
38-
sx, sy = (<object>arr).shape
39-
if arr.flags.f_contiguous:
40-
if axis == 0:
41-
if periods >= 0:
42-
start, stop = periods, sx
37+
# We put this inside an indented else block to avoid cython build
38+
# warnings about unreachable code
39+
sx, sy = (<object>arr).shape
40+
if arr.flags.f_contiguous:
41+
if axis == 0:
42+
if periods >= 0:
43+
start, stop = periods, sx
44+
else:
45+
start, stop = 0, sx + periods
46+
for j in range(sy):
47+
for i in range(start, stop):
48+
out[i, j] = arr[i, j] - arr[i - periods, j]
4349
else:
44-
start, stop = 0, sx + periods
45-
for j in range(sy):
46-
for i in range(start, stop):
47-
out[i, j] = arr[i, j] - arr[i - periods, j]
50+
if periods >= 0:
51+
start, stop = periods, sy
52+
else:
53+
start, stop = 0, sy + periods
54+
for j in range(start, stop):
55+
for i in range(sx):
56+
out[i, j] = arr[i, j] - arr[i, j - periods]
4857
else:
49-
if periods >= 0:
50-
start, stop = periods, sy
58+
if axis == 0:
59+
if periods >= 0:
60+
start, stop = periods, sx
61+
else:
62+
start, stop = 0, sx + periods
63+
for i in range(start, stop):
64+
for j in range(sy):
65+
out[i, j] = arr[i, j] - arr[i - periods, j]
5166
else:
52-
start, stop = 0, sy + periods
53-
for j in range(start, stop):
67+
if periods >= 0:
68+
start, stop = periods, sy
69+
else:
70+
start, stop = 0, sy + periods
5471
for i in range(sx):
55-
out[i, j] = arr[i, j] - arr[i, j - periods]
56-
else:
57-
if axis == 0:
58-
if periods >= 0:
59-
start, stop = periods, sx
60-
else:
61-
start, stop = 0, sx + periods
62-
for i in range(start, stop):
63-
for j in range(sy):
64-
out[i, j] = arr[i, j] - arr[i - periods, j]
65-
else:
66-
if periods >= 0:
67-
start, stop = periods, sy
68-
else:
69-
start, stop = 0, sy + periods
70-
for i in range(sx):
71-
for j in range(start, stop):
72-
out[i, j] = arr[i, j] - arr[i, j - periods]
72+
for j in range(start, stop):
73+
out[i, j] = arr[i, j] - arr[i, j - periods]
7374

7475

7576
# ----------------------------------------------------------------------

pandas/_libs/groupby.pyx

+7-2
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ cdef inline bint _treat_as_na(rank_t val, bint is_datetimelike) nogil:
833833

834834
elif rank_t is int64_t:
835835
return is_datetimelike and val == NPY_NAT
836+
elif rank_t is uint64_t:
837+
# There is no NA value for uint64
838+
return False
836839
else:
837840
return val != val
838841

@@ -1278,7 +1281,8 @@ def group_max(groupby_t[:, :] out,
12781281
if groupby_t is uint64_t:
12791282
runtime_error = True
12801283
break
1281-
out[i, j] = nan_val
1284+
else:
1285+
out[i, j] = nan_val
12821286
else:
12831287
out[i, j] = maxx[i, j]
12841288

@@ -1349,7 +1353,8 @@ def group_min(groupby_t[:, :] out,
13491353
if groupby_t is uint64_t:
13501354
runtime_error = True
13511355
break
1352-
out[i, j] = nan_val
1356+
else:
1357+
out[i, j] = nan_val
13531358
else:
13541359
out[i, j] = minx[i, j]
13551360

pandas/io/msgpack/_packer.pyx

+2-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ cdef class Packer:
235235
continue
236236
else:
237237
raise TypeError("can't serialize {thing!r}".format(thing=o))
238-
return ret
238+
break
239+
return ret
239240

240241
cpdef pack(self, object obj):
241242
cdef int ret

0 commit comments

Comments
 (0)