Skip to content

Fix multiple sample rates, skew and DAT reading issues - #53

Merged
dparrini merged 5 commits into
masterfrom
fix-issues-48-49-29
Oct 21, 2026
Merged

dparrini merged 5 commits into
masterfrom
fix-issues-48-49-29

Conversation

@dparrini

Copy link
Copy Markdown
Owner

Summary

Tests

New tests cover two sample rates (ASCII and binary), blank timestamps, status-only binary files (BINARY, BINARY32, FLOAT32), skewed channels (ASCII, binary, numpy), block reading, DAT files with more or fewer rows than the CFG says, and numpy versus array.array results. Locally, 150 tests pass and ruff check is clean.

Note

This branch is based on #51 (packaging and CI), so this PR also shows that commit until #51 is merged.

Fixes #48
Fixes #49

🤖 Generated with Claude Code

https://claude.ai/code/session_01UHqqatRKrragoYDgQKzpmh

dparrini and others added 5 commits October 21, 2026 12:51
- Add pyproject.toml (hatchling) so the package is built from this
  repository; the version is read from comtrade.__version__
- Add numpy and pandas extras
- Require Python >= 3.11 (the currently supported versions), bump to 0.2.0
- Rename tests/tests.py to tests/test_comtrade.py and run it with pytest
- Replace the test workflow with CI: ruff, tests on Python 3.11-3.15
  (plus Windows and macOS) and a build/twine check
- Add a release workflow that publishes to PyPI via Trusted Publishing
- Add Dependabot for GitHub Actions updates
- Fix ruff findings (unused variables/import, type comparison)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EPnfFrvYTuVEM9uDp81XiD
- Compute sample times across multiple sample rate segments: each
  segment continues from the last sample of the previous one, instead
  of (n - 1) / samp with the segment's own rate (see #45)
- Accept a blank (non-critical) timestamp in ASCII DAT files and
  compute it from the sample rate (#48)
- Fix loading binary DAT files with status channels only (#49)
- Add Comtrade.analog_time with each analog channel's time plus its
  time skew (#29)
- Read ASCII DAT files in blocks and unpack binary DAT fields for all
  rows at once (numpy is used when use_numpy_arrays is set), replacing
  the struct row-by-row reader
- Update README supported features table and add tests

Fixes #48, fixes #49, fixes #29

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VXtokXPfpX3vJri639eqXo
- Compute sample times across multiple sample rate segments: each
  segment continues from the last sample of the previous one, instead
  of (n - 1) / samp with the segment's own rate (see #45)
- Accept a blank (non-critical) timestamp in ASCII DAT files and
  compute it from the sample rate (#48)
- Fix loading binary DAT files with status channels only (#49)
- Add Comtrade.analog_time with each analog channel's time plus its
  time skew (#29)
- Update README supported features table and add tests

Fixes #48, fixes #49, fixes #29

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VXtokXPfpX3vJri639eqXo
- Unpack each binary DAT field (sample number, timestamp, analog
  channel, 16-bit status group) for all rows at once with strided byte
  slices, replacing the struct row-by-row reader
- Scale binary analog values and extract status bits with numpy when
  use_numpy_arrays is set
- Read ASCII DAT files in blocks of lines (up to 1M values), converting
  each channel of a block at once
- Binary DAT files ending in a partial row load their whole rows
  instead of failing with struct.error
- Add tests for ASCII block reading, DAT files with more or fewer rows
  than the CFG samples and numpy arrays reading

Loading the issue's sample (ASCII, 2212 analog channels, 10000
samples) drops from 3.6 s to 2.0 s. Binary files with 2212 channels
load about 2x faster, and 5.5 to 10x faster with use_numpy_arrays.

Fixes #24

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XUdNv59jhgaaRKFfZmRMwQ
@dparrini
dparrini merged commit 08bc997 into master Oct 21, 2026
36 checks passed
@dparrini
dparrini deleted the fix-issues-48-49-29 branch October 21, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: comtrade loading fails on data with digital signals only Error loading dat file with empty time column

1 participant