Skip to content

Commit

Permalink
Clean up compiler warnings (pandas-dev#60674)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Jan 8, 2025
1 parent 5e6a949 commit 8e49cbe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
10 changes: 5 additions & 5 deletions pandas/_libs/byteswap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from libc.string cimport memcpy

def read_float_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
cdef uint32_t value
assert offset + sizeof(value) < len(data)
assert offset + <Py_ssize_t>sizeof(value) < len(data)
cdef const void *ptr = <unsigned char*>(data) + offset
memcpy(&value, ptr, sizeof(value))
if byteswap:
Expand All @@ -28,7 +28,7 @@ def read_float_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):

def read_double_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
cdef uint64_t value
assert offset + sizeof(value) < len(data)
assert offset + <Py_ssize_t>sizeof(value) < len(data)
cdef const void *ptr = <unsigned char*>(data) + offset
memcpy(&value, ptr, sizeof(value))
if byteswap:
Expand All @@ -41,7 +41,7 @@ def read_double_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):

def read_uint16_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
cdef uint16_t res
assert offset + sizeof(res) < len(data)
assert offset + <Py_ssize_t>sizeof(res) < len(data)
memcpy(&res, <const unsigned char*>(data) + offset, sizeof(res))
if byteswap:
res = _byteswap2(res)
Expand All @@ -50,7 +50,7 @@ def read_uint16_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):

def read_uint32_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
cdef uint32_t res
assert offset + sizeof(res) < len(data)
assert offset + <Py_ssize_t>sizeof(res) < len(data)
memcpy(&res, <const unsigned char*>(data) + offset, sizeof(res))
if byteswap:
res = _byteswap4(res)
Expand All @@ -59,7 +59,7 @@ def read_uint32_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):

def read_uint64_with_byteswap(bytes data, Py_ssize_t offset, bint byteswap):
cdef uint64_t res
assert offset + sizeof(res) < len(data)
assert offset + <Py_ssize_t>sizeof(res) < len(data)
memcpy(&res, <const unsigned char*>(data) + offset, sizeof(res))
if byteswap:
res = _byteswap8(res)
Expand Down
4 changes: 1 addition & 3 deletions pandas/_libs/include/pandas/vendored/klib/khash_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ static void *traced_calloc(size_t num, size_t size) {
}

static void *traced_realloc(void *old_ptr, size_t size) {
PyTraceMalloc_Untrack(KHASH_TRACE_DOMAIN, (uintptr_t)old_ptr);
void *ptr = realloc(old_ptr, size);
if (ptr != NULL) {
if (old_ptr != ptr) {
PyTraceMalloc_Untrack(KHASH_TRACE_DOMAIN, (uintptr_t)old_ptr);
}
PyTraceMalloc_Track(KHASH_TRACE_DOMAIN, (uintptr_t)ptr, size);
}
return ptr;
Expand Down
16 changes: 8 additions & 8 deletions pandas/_libs/tslibs/conversion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,18 @@ def cast_from_unit_vectorized(
if p:
frac = np.round(frac, p)

try:
for i in range(len(values)):
for i in range(len(values)):
try:
if base[i] == NPY_NAT:
out[i] = NPY_NAT
else:
out[i] = <int64_t>(base[i] * m) + <int64_t>(frac[i] * m)
except (OverflowError, FloatingPointError) as err:
# FloatingPointError can be issued if we have float dtype and have
# set np.errstate(over="raise")
raise OutOfBoundsDatetime(
f"cannot convert input {values[i]} with the unit '{unit}'"
) from err
except (OverflowError, FloatingPointError) as err:
# FloatingPointError can be issued if we have float dtype and have
# set np.errstate(over="raise")
raise OutOfBoundsDatetime(
f"cannot convert input {values[i]} with the unit '{unit}'"
) from err
return out


Expand Down

0 comments on commit 8e49cbe

Please sign in to comment.