Treat a NaN of any float width as missing - #1441
Merged
Merged
Conversation
column_source.is_missing tested isinstance(value, float), which numpy's float32 and float16 do not satisfy (only float64 subclasses float), so a narrow-dtype NaN from a numpy-backed table was handed to validation as the text 'nan'. The test now accepts any numbers.Real. ndx-hed filtered these itself (its adoption plan Q3); any other numpy-backed caller had the gap.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
math.isnan() can raise OverflowError for valid large real-number values.
Review effort: Balanced
Findings: 1
What changed in this PR
Broadens missing-value detection to support NumPy NaNs of different widths.
Changes:
- Uses
numbers.Realwhen checking for NaN. - Adds NumPy dtype coverage and related missing-value tests.
| File | Description |
|---|---|
hed/models/column_source.py |
Expands NaN detection beyond Python floats. |
tests/models/test_column_source.py |
Tests NumPy float widths and non-missing scalar values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot review of PR hed-standard#1441. numbers.Real includes arbitrary-size integers and Fraction, and math.isnan converts its argument to float, so a valid value such as 10**1000 raised OverflowError inside distinct_values. NaN is the one real value unequal to itself, and that test converts nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

column_source.is_missing tested isinstance(value, float), which numpy's float32 and float16 do not satisfy (only float64 subclasses float), so a narrow-dtype NaN from a numpy-backed table was handed to validation as the text 'nan'. The test now accepts any numbers.Real. ndx-hed filtered these itself (its adoption plan Q3); any other numpy-backed caller had the gap.