Handle boolean null values instead of treating them as false#435
Handle boolean null values instead of treating them as false#435
Conversation
FITS NULL values in boolean columns (value 127) were silently converted to false. Now bool reads error when nulls are present, directing users to use Option<bool> which represents nulls as None. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe pull request extends boolean column reading functionality in the FITS file library to support nullable booleans. It introduces two trait implementations: ReadsCol for Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
fitsio/src/tables.rs (3)
259-306:⚠️ Potential issue | 🟡 MinorMissing
repeat > 1guard inOption<bool>::read_cell_value.The macro-generated
read_cell_value(lines 134–139) checksrepeat > 1and panics withunimplemented!for vector-valued columns. TheOption<bool>implementation omits this guard, so callingread_cell_valueon a vector logical column would silently read only the first element instead of flagging the unsupported case.🔧 Proposed fix: add repeat guard
let column_number = column_descriptions .iter() .position(|desc| desc.name == test_name) .ok_or(Error::Message(format!( "Cannot find column {:?}", test_name )))?; + let repeat = column_descriptions[column_number].data_type.repeat; + if repeat > 1 { + unimplemented!( + "reading a single cell of a vector value (e.g., TFORM1 = 100L) is unimplemented. Call read_col() or read_col_range()." + ) + } let mut status = 0;
166-306: 🛠️ Refactor suggestion | 🟠 MajorNo tests added for the new nullable boolean functionality.
The PR description notes tests are pending. Both happy-path and error-path coverage are needed:
read_col::<bool>on a column without nulls still works.read_col::<bool>on a column with nulls returns the expected error.read_col::<Option<bool>>correctly returnsSome(true),Some(false), andNone.read_cell_valuevariants for bothboolandOption<bool>.Without these, the sentinel-based null detection is unverified against real CFITSIO output.
Would you like me to open an issue to track adding these tests, or generate skeleton test functions?
194-257:⚠️ Potential issue | 🟠 MajorThe
Option<bool>implementation missingrepeatfactor for vector-valued logical columns.The macro-generated
reads_col_impl!(lines 62–89) correctly multiplies the output buffer allocation and the num_elements parameter tofits_read_col_logby the column'srepeatfactor (lines 80 and 88). TheOption<bool>implementation (lines 194–257) allocates onlynum_output_rowselements (line 206) and passesnum_output_rowstofits_read_col_log(line 223), ignoring therepeatfactor from the column description. For vector-valued logical columns (e.g., TFORM = '10L'), this silently truncates data by reading only a fraction of the available elements.The fix requires extracting the
repeatfactor fromcolumn_descriptions[column_number].data_type.repeatafter obtaining the column number, then multiplying both the buffer allocation and the num_elements parameter by this factor, as demonstrated in the macro at lines 73–78 and 88.
Summary
falseboolreads now return an error when nulls are present, directing users to useOption<bool>ReadsCol for Option<bool>implementation that represents nulls asNoneTest plan
read_col::<bool>errors on null-containing columnsread_col::<Option<bool>>returnsNonefor null values🤖 Generated with Claude Code