Add lift/unlift functions for seqseq dimension conversion - #2
Merged
Conversation
Add nsv/ensv.py with lift and unlift functions as defined in the ENSV spec. lift collapses a seqseq into a single row using separator semantics (init ∘ spill[String, ''] ∘ map(map(escape))), and unlift recovers the original structure by unescaping and splitting on empty strings. Includes 31 tests covering escaping, empty rows, ragged data, and bidirectional roundtrip properties. https://claude.ai/code/session_01PuxiBkVsjVDzcSopK3kNRg
Rewrite lift to use separator semantics directly instead of going through spill+init. Remove ValueError for empty input (caller's responsibility). Remove lift/unlift from top-level namespace. Add decomposition equivalence test. https://claude.ai/code/session_01PuxiBkVsjVDzcSopK3kNRg
Use existing SAMPLES_DATA from test_utils for roundtrip and decomposition equivalence tests instead of maintaining a separate set of cases. Trim redundant unit tests that are covered by samples. https://claude.ai/code/session_01PuxiBkVsjVDzcSopK3kNRg
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.
Summary
This PR adds
liftandunliftfunctions to convert between 2D sequences of strings (seqseq) and 1D sequences, enabling dimension reduction/recovery while preserving structural information through escape sequences and empty string delimiters.Key Changes
New module
nsv/ensv.py: Implementslift()andunlift()functionslift(seqseq): Converts a 2D sequence into a 1D sequence by escaping special characters (backslashes, newlines, empty cells) and using empty strings as row delimitersunlift(seq): Recovers the original 2D structure from a lifted sequence by unescaping and splitting on empty string delimitersReader.unescape()andWriter.escape()utilitiesUpdated
nsv/__init__.py: Exportsliftandunliftfunctions for public API accessComprehensive test suite
tests/test_ensv.py:unlift(lift(x)) == xandlift(unlift(y)) == yImplementation Details
lift()requires non-empty input (raisesValueErrorfor empty seqseq since[]is irrepresentable)\\, newlines →\n, empty cells →\https://claude.ai/code/session_01PuxiBkVsjVDzcSopK3kNRg