-
Notifications
You must be signed in to change notification settings - Fork 17
First stab at streaming refactor #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af6a57d
First stab at streaming refactor
xflow-ben 1bca249
Remove .claude/settings.local.json from version control, some of the …
xflow-ben 36a644e
Address author feedback: improve inheritance, remove duplication, ref…
xflow-ben 94c6209
Implement requested edits
xflow-ben File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ dist | |
| *.png | ||
| _* | ||
| .claude | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| # Streaming Mode - Quick Reference | ||
|
|
||
| ## For Users | ||
|
|
||
| ### Header-only inspection (memory efficient!) | ||
| ```python | ||
| import weio | ||
|
|
||
| with weio.read('large_file.outb', streaming=True) as f: | ||
| print(f['attribute_names']) # Column names | ||
| print(f['attribute_units']) # Units | ||
| # f.data is None - no data loaded | ||
| ``` | ||
|
|
||
| ### Load data after inspection | ||
| ```python | ||
| import weio | ||
|
|
||
| with weio.read('file.out', streaming=True) as f: | ||
| print(f"Channels: {len(f['attribute_names'])}") | ||
| f.readAll() # Load data now | ||
| df = f.toDataFrame() | ||
| ``` | ||
|
|
||
| ### Process CSV in chunks | ||
| ```python | ||
| import weio | ||
|
|
||
| with weio.read('huge.csv', streaming=True) as f: | ||
| while True: | ||
| chunk = f.readChunk(nlines=10000) | ||
| if chunk is None: | ||
| break | ||
| # Process chunk... | ||
| ``` | ||
|
|
||
| ## For Developers | ||
|
|
||
| ### Adding streaming to a new file format | ||
|
|
||
| 1. **Add `streaming` parameter to `_read()`:** | ||
| ```python | ||
| def _read(self, streaming=False, **kwargs): | ||
| if streaming: | ||
| # Read headers only, keep file open | ||
| self._fid = open(self.filename, 'r') | ||
| self['header'] = self._fid.readline() | ||
| self.data = None | ||
| else: | ||
| # Normal mode: read everything | ||
| with open(self.filename, 'r') as f: | ||
| self.data = f.read() | ||
| ``` | ||
|
|
||
| 2. **Implement `_readAll()`:** | ||
| ```python | ||
| def _readAll(self): | ||
| if self._fid is None: | ||
| raise RuntimeError("No open file handle") | ||
| # Read remaining data | ||
| self.data = self._fid.read() | ||
| ``` | ||
|
|
||
| 3. **Optional: Implement `_readChunk()`:** | ||
| ```python | ||
| def _readChunk(self, nlines=None, **kwargs): | ||
| if self._fid is None: | ||
| raise RuntimeError("No open file handle") | ||
| if nlines is None: | ||
| nlines = 1000 | ||
| # Read chunk... | ||
| return chunk # or None if EOF | ||
| ``` | ||
|
|
||
| That's it! The base File class handles context managers and enforcement. | ||
|
|
||
| ## Supported Formats (so far) | ||
|
|
||
| - ✅ **OpenFAST:** `.out` (ASCII), `.outb` (binary) | ||
| - ✅ **CSV:** `.csv`, `.txt` (with chunk reading) | ||
| - ✅ **HAWC2:** `.dat`, `.sel` (ASCII and binary) | ||
|
|
||
| ## Key Design Points | ||
|
|
||
| - **Single `streaming` parameter** (not both `headerOnly` and `streaming`) | ||
| - **Context manager required** for streaming mode (`with` statement) | ||
| - **Header-only:** Exit `with` block without calling `readAll()` | ||
| - **Full streaming:** Call `readAll()` or `readChunk()` inside `with` block | ||
| - **Backward compatible:** Default `streaming=False` means existing code works unchanged |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.