Skip to content

Commit 8be210c

Browse files
committed
Avoid unnecessary double/int64_t conversions
1 parent 0880cce commit 8be210c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python/pyarrow/src/arrow/python/helpers.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ Result<uint16_t> PyFloat_AsHalf(PyObject* obj) {
9696
}
9797

9898
Result<std::shared_ptr<Array>> Arange(int64_t start, int64_t stop, int64_t step) {
99-
double delta = static_cast<double>(stop - start);
100-
double size = std::ceil(delta / step);
101-
102-
if (ARROW_PREDICT_FALSE(step == 0 || size <= 0)) {
99+
int64_t size;
100+
if (step > 0 && stop > start) {
101+
// Ceiling division for positive step
102+
size = (stop - start + step - 1) / step;
103+
} else if (step < 0 && stop < start) {
104+
// Ceiling division for negative step
105+
size = (start - stop - step - 1) / (-step);
106+
} else {
103107
return MakeEmptyArray(int64());
104108
}
105109
std::shared_ptr<Buffer> data_buffer;

0 commit comments

Comments
 (0)