Repository navigation
Fix parameter handling in csv_to_wfdb - #600
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Thanks, this looks good! Building one Record for both modes works well. With default arguments the written files are byte-identical to main, and the returned record now matches the written header. It also fixes CSVs with missing values, which crash on main.
Two small things before merging:
-
boolis treated as a number.isinstance(True, numbers.Number)isTrue, soadc_gain=TruewritesTrue(0)/mVinto the header without an error (mainraised aTypeError). Could_per_channelrejectbool? -
The deprecation warning is hidden in some cases. Python only shows
DeprecationWarningwhen the call comes from the main script, so code callingcsv_to_wfdbfrom inside another module won't see it. Since these arguments are now ignored (e.g.init_value=[1, 2]withrecord_only=Truenow gives the computed values), could you useFutureWarninginstead, which is always shown?
Smaller, optional:
- A test with a missing value (NaN) in the CSV, since that's a fix with no test yet.
- A CSV with a header but no rows now fails with
Missing field required: init_valuewhen writing. A clearer error would help, but it isn't essential. - In
docs/changes.rst, please drop the backticks from the heading, since they don't render inside bold text.
Happy to merge once the first two are addressed.
|
Thanks for the careful review! All done:
The optional ones too:
|
|
Thanks again, looks good! I think we'll have a small conflict to address when #599 is merged. |
Build one Record in both modes and write it with Record.wrsamp, so header parameters are no longer dropped. Broadcast any scalar, treat only None as missing, compute init_value and checksum from the digital samples, deprecate samps_per_frame, init_value and checksum, and correct the parameter descriptions.
Reject bool in _per_channel, warn about ignored arguments with FutureWarning so it is always shown, raise a clear error for a CSV without samples, and test missing values.
3a90c78 to
0366ded
Compare
|
Thanks! I've rebased onto |
Closes #592, closes #593, closes #594.
Following the suggestion in #592,
csv_to_wfdbnow builds oneRecordin both modes. Withrecord_only=Falseit writes that record withRecord.wrsamp(write_dir=...); withrecord_only=Trueit returns it.#592: parameters that had no effect
dat_file_nameis used if given (the default is still<record_name>.dat).counter_freq,base_counter,skew,byte_offset,adc_res,adc_zeroandblock_sizeare written to the header (byte_offsetalso writes the leading bytes, aswr_dat_filealready does).samps_per_frame,init_valueandchecksumfollow from the CSV samples, so as suggested they're deprecated: passing them gives aDeprecationWarningand they're ignored. (samps_per_frameother than 1 also never reached the header before, becausewrsampwritesd_signalunexpanded, see wrsamp incorrectly saves samps_per_frame when expanded=False #333.)#593: defaults and broadcasting
_per_channelhelper: anystr,numbers.Numberor NumPy scalar is repeated for all channels, soadc_gain=200.5andbaseline=np.int64(3)work.None, sobaseline=0withadc_zero=1024stays 0.baselinedefaults toadc_zeroper channel, soadc_zero=[1, 2]givesbaseline=[1, 2]instead of a list of lists.init_valueandchecksumare computed from the digital samples (Record.adc()/calc_checksum()) in both modes, and the remaining defaults come fromset_defaults()as inwrsamp.#594: docstring
file_name,fs,header(ch_0, ch_1, ...) and the descriptions copied from the header spec, and documented the defaults and deprecations.Compatibility
100.heaand100.datforsample-data/100.csvare byte-identical tomain.record_only=True, the returned record now matches what would be written:adc_resdefaults to the resolution offmt(16 for the default format, was 12),init_valueis the rounded digital value (was truncated), andchecksumis over the digital samples (was over the physical values). The returned record still hasd_signal=None, as before.Tests
Seven new tests in
TestCsvToWfdb: record vs written header, scalar broadcasting, zero and list defaults, parameters reaching the files, and the three deprecated arguments. All seven fail onmain.ruff checkis clean, the docs build passes with-W, andpytest -m "not network"passes (89 tests).This touches the same file as #599 (
csv2ann), but a different function. Both add a changelog entry at the same place and append tests totests/io/test_convert.py, so whichever is merged second will have small conflicts there. I'll rebase it.