BUG: corrected bug in handling left-over samples in uneven double data#108
Merged
jankoslavic merged 1 commit intomainfrom Feb 23, 2026
Merged
BUG: corrected bug in handling left-over samples in uneven double data#108jankoslavic merged 1 commit intomainfrom
jankoslavic merged 1 commit intomainfrom
Conversation
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.
This bug was discovered in the issue:
#107
The bug is in writing dataset 58 when the data is real, double precision, and unevenly spaced.
The UFF dataset 58 format supports 8 different cases depending on the combination of data type (real/complex), precision (single/double), and spacing (even/uneven). Each case has its own code path for formatting the numbers into lines.
When data is unevenly spaced, every x value has to be stored alongside its y value. So if you have 5 data points, the code interleaves them into a flat array of 10 values:
[x1, y1, x2, y2, x3, y3, x4, y4, x5, y5]
These are then written to the file 4 values per line, with alternating format specifiers — narrow for x (%13.5e) and wide for y (%20.11e):
x1 y1 x2 y2 ← line of 4
x3 y3 x4 y4 ← line of 4
x5 y5 ← leftover 2 values
The main lines of 4 are handled fine. The problem is with the leftover values. The code builds a list of format specifiers and tries to pick the right ones for however many leftover values there are:
fmt = ['%13.5e', '%20.11e', '%13.5e', '%20.11e']
fmt[rem_vals] # bug — gets one single item (e.g. fmt[2] = '%13.5e')
fmt[:rem_vals] # fix — gets a slice of the first rem_vals items (e.g. fmt[:2] = ['%13.5e', '%20.11e'])
With the bug, the format string has only one placeholder but there are two values to write, so Python throws a TypeError: not all arguments converted during string formatting.
This means the bug only triggers when there are leftover values, which happens when the number of data points is odd (odd * 2 = not divisible by 4). With an even number of data points, the leftover line is never reached and everything works fine.
Only this one case (real, double, uneven) has the bug. The other 7 cases handle leftovers differently — they use string repetition like rem_vals * '%20.11e' which naturally produces the right number of format specifiers. This case is the only one that uses a list with
mixed format specifiers (alternating between %13.5e and %20.11e), and that's where the indexing typo crept in.
The fix is one character: [ to [:].