Skip to content

Conversation

@HyukjinKwon
Copy link
Member

@HyukjinKwon HyukjinKwon commented Dec 11, 2025

Rationale for this change

// TODO(wesm): How pedantic do we really want to be about checking for int32
// overflow here?

Should check and work together with safe paramter.

What changes are included in this PR?

This PR proposes to implement overflow check in date and integer conversions

Are these changes tested?

Yes, manually tested, and also added a unittest:

pytest pyarrow/tests/test_array.py -k "test_array_from_numpy_datetime_overflow" -v

Are there any user-facing changes?

Yes.

import numpy as np
import pyarrow as pa
pa.array(np.array([np.int64(-3000000000)], dtype='datetime64[D]'), safe=True)

Before:

>>> pa.array(np.array([np.int64(-3000000000)], dtype='datetime64[D]'), safe=True)
<pyarrow.lib.Date32Array object at 0x1207f85e0>
[
  <value out of range: 1294967296>
]

After:

pyarrow.lib.ArrowInvalid: Integer value -3000000000 out of bounds for int32 conversion at index 0

@github-actions
Copy link

⚠️ GitHub issue #48457 has been automatically assigned in GitHub to PR creator.

@HyukjinKwon HyukjinKwon force-pushed the overflow-check branch 2 times, most recently from 7d3650e to bad62b6 Compare December 11, 2025 10:06
Copy link
Collaborator

@EnricoMi EnricoMi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @HyukjinKwon, welcome to the Apache Arrow project.

This looks generally good, one possible overflow remark, though.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Dec 11, 2025
Copy link
Collaborator

@EnricoMi EnricoMi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with this. Just a minor suggestion to rename the method to reflect the "limitation" or "assumption".

@HyukjinKwon
Copy link
Member Author

I believe this should be ready for a look too @AlenkaF 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants