Skip to content

Add transpose command for NSV data#6

Merged
namingbe merged 14 commits intomasterfrom
claude/add-nsv-subcommands-Xfj9a
Mar 7, 2026
Merged

Add transpose command for NSV data#6
namingbe merged 14 commits intomasterfrom
claude/add-nsv-subcommands-Xfj9a

Conversation

@namingbe
Copy link
Copy Markdown
Contributor

@namingbe namingbe commented Mar 7, 2026

Summary

This PR adds a new transpose command that swaps rows and columns in NSV (Newline Separated Values) data. The implementation includes comprehensive test coverage.

Key Changes

  • New transpose command: Added to the CLI with support for file input or stdin
  • Table validation: Enforces that input data is a proper table (all rows must have equal arity), rejecting ragged data with a clear error message
  • Core transpose logic: Converts an M×N table to an N×M table by collecting columns into rows
  • Comprehensive test suite: Added tests/test_transpose.sh with 11 test cases covering:
    • Empty input handling
    • Various table dimensions (2×2, 3×4)
    • Single row/column edge cases
    • Stdin input
    • Roundtrip verification (transpose twice returns original)
    • Multiline cell preservation
    • Ragged row rejection

Implementation Details

  • The transpose function validates table structure before processing, ensuring all rows have the same number of cells
  • Preserves NSV encoding including multiline cells and escaped content
  • Returns early for empty input or tables with no columns
  • Uses idiomatic Rust with iterator-based column collection

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap

claude and others added 14 commits March 7, 2026 02:38
Swaps rows and columns of NSV table data. Requires uniform row
arity — exits with an error on ragged input. Works at the byte
level (decode_bytes → transpose → encode_bytes).

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Read → decode → move cells into transposed structure → encode.
No intermediate copies. No silent BOM/CRLF fixup — pipe through
nsv sanitize if needed.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Write each transposed row directly by iterating columns,
avoiding allocation of the entire transposed structure.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Transpose is structure-only: it rearranges cells without
modifying content. Work directly with escaped line slices
instead of decoding then re-escaping each cell.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Replace verbose unwrap_or_else(panic!) with ?, returning
io::Result. Caller handles BrokenPipe silently.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Match the pattern used by sanitize: return Result<(), String>
and let main handle printing and exit code.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
Drop redundant description, show involution as a pipeline.

https://claude.ai/code/session_01QPwRx4hq2FgScPdegPr7ap
@namingbe namingbe merged commit db86ada into master Mar 7, 2026
1 check passed
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.

2 participants