Problem
Converting floating-point sex or bp_position properties containing NaN to their required np.int32 dtype emits:
RuntimeWarning: invalid value encountered in cast
The special floating-to-integer path in open_bed._fix_up_properties_array currently checks:
np.issubdtype(input.dtype, np.floating) and np.issubdtype(dtype, int)
For the target dtype used by these properties:
np.issubdtype(np.int32, int) # False
np.issubdtype(np.int32, np.integer) # True
This behavior was reproduced with NumPy 1.22.4, 1.26.4, 2.0.0, and 2.5.1, so it is not new in NumPy 2.5.
Impact
The resulting array is currently corrected after the cast, so the reproduced output is correct (NaN becomes the missing integer value 0). However:
- Users see an avoidable runtime warning.
- The operation becomes an error when warnings are promoted to errors.
- PySnpTools'
test_writes2 fails under -W error::RuntimeWarning:bed_reader._open_bed when SnpData(pos=None) supplies missing positions as NaN.
- BedReader's local and cloud
test_coverage3 tests currently suppress this exact warning.
History
- Commit
b3c1e892cf7a55f3e230cf6830f724d3ff630709 (April 25, 2024) added the floating-to-integer special case and removed a test expectation for the warning, apparently intending to eliminate it.
- Commit
6d9dbd1f207fc4e600d542729e121dbe4a87c2a6 (October 14, 2024) added filters suppressing the warning in the local and cloud tests.
Suggested fix
- Recognize NumPy integer dtypes with
np.integer rather than Python int.
- Avoid modifying the caller's input array when replacing
NaN; convert through a temporary array or copy.
- Remove the two warning filters.
- Add focused regression coverage for floating-point
sex and bp_position arrays containing NaN, asserting the expected integer missing value and no warning.
- Verify PySnpTools' warning-as-error reproduction after the BedReader fix.
Problem
Converting floating-point
sexorbp_positionproperties containingNaNto their requirednp.int32dtype emits:The special floating-to-integer path in
open_bed._fix_up_properties_arraycurrently checks:For the target dtype used by these properties:
This behavior was reproduced with NumPy 1.22.4, 1.26.4, 2.0.0, and 2.5.1, so it is not new in NumPy 2.5.
Impact
The resulting array is currently corrected after the cast, so the reproduced output is correct (
NaNbecomes the missing integer value0). However:test_writes2fails under-W error::RuntimeWarning:bed_reader._open_bedwhenSnpData(pos=None)supplies missing positions asNaN.test_coverage3tests currently suppress this exact warning.History
b3c1e892cf7a55f3e230cf6830f724d3ff630709(April 25, 2024) added the floating-to-integer special case and removed a test expectation for the warning, apparently intending to eliminate it.6d9dbd1f207fc4e600d542729e121dbe4a87c2a6(October 14, 2024) added filters suppressing the warning in the local and cloud tests.Suggested fix
np.integerrather than Pythonint.NaN; convert through a temporary array or copy.sexandbp_positionarrays containingNaN, asserting the expected integer missing value and no warning.