dataframe-textual 2.37.0__tar.gz → 2.38.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/PKG-INFO +41 -37
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/README.md +40 -36
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/pyproject.toml +1 -1
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/__main__.py +2 -2
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/common.py +90 -32
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/data_frame_table.py +277 -79
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/data_frame_viewer.py +12 -11
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/file_picker_screen.py +5 -5
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/loading_screen.py +38 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/table_screen.py +108 -4
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/yes_no_screen.py +130 -44
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/uv.lock +4 -4
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/.gitignore +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/LICENSE +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/main.py +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/__init__.py +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/data_frame_help_panel.py +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/src/dataframe_textual/theme_screen.py +0 -0
- {dataframe_textual-2.37.0 → dataframe_textual-2.38.0}/xbk/common.py_w_compute_error +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dataframe-textual
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.38.0
|
|
4
4
|
Summary: Interactive terminal viewer/editor for tabular data
|
|
5
5
|
Project-URL: Homepage, https://github.com/need47/dataframe-textual
|
|
6
6
|
Project-URL: Repository, https://github.com/need47/dataframe-textual.git
|
|
@@ -53,10 +53,10 @@ A powerful, interactive terminal-based viewer/editor for CSV/TSV/Excel/[Parquet]
|
|
|
53
53
|
- 🔄 **Smart Pagination** - Lazy load rows on demand for handling large datasets
|
|
54
54
|
|
|
55
55
|
### Data Manipulation
|
|
56
|
-
- 📝 **Data Editing** - Edit cells, delete rows, and
|
|
56
|
+
- 📝 **Data Editing** - Edit cells, delete rows, remove columns, and explode columns
|
|
57
57
|
- 🔍 **Search & Filter** - Find values, highlight matches, and filter selected rows
|
|
58
58
|
- ↔️ **Column/Row Reordering** - Move columns and rows with simple keyboard shortcuts
|
|
59
|
-
- 📈 **Sorting & Statistics** - Multi-column sorting
|
|
59
|
+
- 📈 **Sorting & Statistics** - Multi-column sorting, frequency distribution, and histogram analysis
|
|
60
60
|
- 💾 **Save & Undo** - Save edits back to file with full undo/redo support
|
|
61
61
|
|
|
62
62
|
### Advanced Features
|
|
@@ -105,7 +105,7 @@ pip install -e ".[dev]"
|
|
|
105
105
|
### Basic Usage - Single File
|
|
106
106
|
|
|
107
107
|
```bash
|
|
108
|
-
#
|
|
108
|
+
# Open one file
|
|
109
109
|
dv pokemon.csv
|
|
110
110
|
```
|
|
111
111
|
|
|
@@ -115,7 +115,7 @@ dv pokemon.csv
|
|
|
115
115
|
# Open multiple files in tabs
|
|
116
116
|
dv file1.csv file2.csv file3.csv
|
|
117
117
|
|
|
118
|
-
# Open multiple sheets in
|
|
118
|
+
# Open multiple sheets in an Excel file as separate tabs
|
|
119
119
|
dv file.xlsx
|
|
120
120
|
|
|
121
121
|
# Mix files and stdin
|
|
@@ -308,41 +308,45 @@ dv data.csv -o data.parquet
|
|
|
308
308
|
|
|
309
309
|
#### Display
|
|
310
310
|
|
|
311
|
-
| Key | Action
|
|
312
|
-
| ---------------- |
|
|
313
|
-
| `Enter` | Record view of current row transposed
|
|
314
|
-
| `F` | Show frequency distribution for current column
|
|
315
|
-
| `
|
|
316
|
-
| `
|
|
317
|
-
| `
|
|
318
|
-
| `
|
|
319
|
-
| `
|
|
320
|
-
|
|
|
321
|
-
| `
|
|
322
|
-
|
|
|
323
|
-
|
|
|
324
|
-
|
|
|
325
|
-
|
|
|
326
|
-
|
|
|
311
|
+
| Key | Action |
|
|
312
|
+
| ---------------- | -------------------------------------------------- |
|
|
313
|
+
| `Enter` | Record view of current row transposed |
|
|
314
|
+
| `F` | Show frequency distribution for current column |
|
|
315
|
+
| `i` | Show histogram for current column |
|
|
316
|
+
| `I` | Show histogram for current column with custom bins |
|
|
317
|
+
| `s` | Show statistics for current column |
|
|
318
|
+
| `S` | Show statistics for entire dataframe |
|
|
319
|
+
| `m` | Show metadata for row count and column count |
|
|
320
|
+
| `M` | Show metadata for current column |
|
|
321
|
+
| `K` | Cycle cursor types: cell → row → column → cell |
|
|
322
|
+
| `~` | Toggle row labels |
|
|
323
|
+
| `_` (underscore) | Toggle column full width |
|
|
324
|
+
| `f` | Toggle freeze rows and/or columns |
|
|
325
|
+
| `,` | Toggle thousand separator for numeric display |
|
|
326
|
+
| `&` | Set current row as the new header row |
|
|
327
|
+
| `h` | Hide current column |
|
|
328
|
+
| `H` | Show all hidden columns |
|
|
327
329
|
|
|
328
330
|
#### Editing
|
|
329
331
|
|
|
330
|
-
| Key | Action
|
|
331
|
-
| -------------- |
|
|
332
|
-
| `Double-click` | Edit cell or rename column header
|
|
333
|
-
| `Delete` | Clear current cell (set to NULL)
|
|
334
|
-
| `Shift+Delete` | Clear current column (set matching cells to NULL)
|
|
335
|
-
| `e` | Edit current cell (respects data type)
|
|
336
|
-
| `E` | Edit entire column with value/expression
|
|
337
|
-
| `a` | Add empty column after current
|
|
338
|
-
| `A` | Add column with name and value/expression
|
|
339
|
-
| `@` | Add a link column from URL template
|
|
340
|
-
| `-` (minus) | Delete current column
|
|
341
|
-
| `x` | Delete current row
|
|
342
|
-
| `X` | Delete current row and all those below
|
|
343
|
-
| `Ctrl+X` | Delete current row and all those above
|
|
344
|
-
| `d` | Duplicate current column
|
|
345
|
-
| `D` | Duplicate current row
|
|
332
|
+
| Key | Action |
|
|
333
|
+
| -------------- | ------------------------------------------------------------- |
|
|
334
|
+
| `Double-click` | Edit cell or rename column header |
|
|
335
|
+
| `Delete` | Clear current cell (set to NULL) |
|
|
336
|
+
| `Shift+Delete` | Clear current column (set matching cells to NULL) |
|
|
337
|
+
| `e` | Edit current cell (respects data type) |
|
|
338
|
+
| `E` | Edit entire column with value/expression |
|
|
339
|
+
| `a` | Add empty column after current |
|
|
340
|
+
| `A` | Add column with name and value/expression |
|
|
341
|
+
| `@` | Add a link column from URL template |
|
|
342
|
+
| `-` (minus) | Delete current column |
|
|
343
|
+
| `x` | Delete current row |
|
|
344
|
+
| `X` | Delete current row and all those below |
|
|
345
|
+
| `Ctrl+X` | Delete current row and all those above |
|
|
346
|
+
| `d` | Duplicate current column |
|
|
347
|
+
| `D` | Duplicate current row |
|
|
348
|
+
| `o` | Explode current list column into multiple rows |
|
|
349
|
+
| `O` | Explode current string column by delimiter into multiple rows |
|
|
346
350
|
|
|
347
351
|
#### Row Selection
|
|
348
352
|
|
|
@@ -14,10 +14,10 @@ A powerful, interactive terminal-based viewer/editor for CSV/TSV/Excel/[Parquet]
|
|
|
14
14
|
- 🔄 **Smart Pagination** - Lazy load rows on demand for handling large datasets
|
|
15
15
|
|
|
16
16
|
### Data Manipulation
|
|
17
|
-
- 📝 **Data Editing** - Edit cells, delete rows, and
|
|
17
|
+
- 📝 **Data Editing** - Edit cells, delete rows, remove columns, and explode columns
|
|
18
18
|
- 🔍 **Search & Filter** - Find values, highlight matches, and filter selected rows
|
|
19
19
|
- ↔️ **Column/Row Reordering** - Move columns and rows with simple keyboard shortcuts
|
|
20
|
-
- 📈 **Sorting & Statistics** - Multi-column sorting
|
|
20
|
+
- 📈 **Sorting & Statistics** - Multi-column sorting, frequency distribution, and histogram analysis
|
|
21
21
|
- 💾 **Save & Undo** - Save edits back to file with full undo/redo support
|
|
22
22
|
|
|
23
23
|
### Advanced Features
|
|
@@ -66,7 +66,7 @@ pip install -e ".[dev]"
|
|
|
66
66
|
### Basic Usage - Single File
|
|
67
67
|
|
|
68
68
|
```bash
|
|
69
|
-
#
|
|
69
|
+
# Open one file
|
|
70
70
|
dv pokemon.csv
|
|
71
71
|
```
|
|
72
72
|
|
|
@@ -76,7 +76,7 @@ dv pokemon.csv
|
|
|
76
76
|
# Open multiple files in tabs
|
|
77
77
|
dv file1.csv file2.csv file3.csv
|
|
78
78
|
|
|
79
|
-
# Open multiple sheets in
|
|
79
|
+
# Open multiple sheets in an Excel file as separate tabs
|
|
80
80
|
dv file.xlsx
|
|
81
81
|
|
|
82
82
|
# Mix files and stdin
|
|
@@ -269,41 +269,45 @@ dv data.csv -o data.parquet
|
|
|
269
269
|
|
|
270
270
|
#### Display
|
|
271
271
|
|
|
272
|
-
| Key | Action
|
|
273
|
-
| ---------------- |
|
|
274
|
-
| `Enter` | Record view of current row transposed
|
|
275
|
-
| `F` | Show frequency distribution for current column
|
|
276
|
-
| `
|
|
277
|
-
| `
|
|
278
|
-
| `
|
|
279
|
-
| `
|
|
280
|
-
| `
|
|
281
|
-
|
|
|
282
|
-
| `
|
|
283
|
-
|
|
|
284
|
-
|
|
|
285
|
-
|
|
|
286
|
-
|
|
|
287
|
-
|
|
|
272
|
+
| Key | Action |
|
|
273
|
+
| ---------------- | -------------------------------------------------- |
|
|
274
|
+
| `Enter` | Record view of current row transposed |
|
|
275
|
+
| `F` | Show frequency distribution for current column |
|
|
276
|
+
| `i` | Show histogram for current column |
|
|
277
|
+
| `I` | Show histogram for current column with custom bins |
|
|
278
|
+
| `s` | Show statistics for current column |
|
|
279
|
+
| `S` | Show statistics for entire dataframe |
|
|
280
|
+
| `m` | Show metadata for row count and column count |
|
|
281
|
+
| `M` | Show metadata for current column |
|
|
282
|
+
| `K` | Cycle cursor types: cell → row → column → cell |
|
|
283
|
+
| `~` | Toggle row labels |
|
|
284
|
+
| `_` (underscore) | Toggle column full width |
|
|
285
|
+
| `f` | Toggle freeze rows and/or columns |
|
|
286
|
+
| `,` | Toggle thousand separator for numeric display |
|
|
287
|
+
| `&` | Set current row as the new header row |
|
|
288
|
+
| `h` | Hide current column |
|
|
289
|
+
| `H` | Show all hidden columns |
|
|
288
290
|
|
|
289
291
|
#### Editing
|
|
290
292
|
|
|
291
|
-
| Key | Action
|
|
292
|
-
| -------------- |
|
|
293
|
-
| `Double-click` | Edit cell or rename column header
|
|
294
|
-
| `Delete` | Clear current cell (set to NULL)
|
|
295
|
-
| `Shift+Delete` | Clear current column (set matching cells to NULL)
|
|
296
|
-
| `e` | Edit current cell (respects data type)
|
|
297
|
-
| `E` | Edit entire column with value/expression
|
|
298
|
-
| `a` | Add empty column after current
|
|
299
|
-
| `A` | Add column with name and value/expression
|
|
300
|
-
| `@` | Add a link column from URL template
|
|
301
|
-
| `-` (minus) | Delete current column
|
|
302
|
-
| `x` | Delete current row
|
|
303
|
-
| `X` | Delete current row and all those below
|
|
304
|
-
| `Ctrl+X` | Delete current row and all those above
|
|
305
|
-
| `d` | Duplicate current column
|
|
306
|
-
| `D` | Duplicate current row
|
|
293
|
+
| Key | Action |
|
|
294
|
+
| -------------- | ------------------------------------------------------------- |
|
|
295
|
+
| `Double-click` | Edit cell or rename column header |
|
|
296
|
+
| `Delete` | Clear current cell (set to NULL) |
|
|
297
|
+
| `Shift+Delete` | Clear current column (set matching cells to NULL) |
|
|
298
|
+
| `e` | Edit current cell (respects data type) |
|
|
299
|
+
| `E` | Edit entire column with value/expression |
|
|
300
|
+
| `a` | Add empty column after current |
|
|
301
|
+
| `A` | Add column with name and value/expression |
|
|
302
|
+
| `@` | Add a link column from URL template |
|
|
303
|
+
| `-` (minus) | Delete current column |
|
|
304
|
+
| `x` | Delete current row |
|
|
305
|
+
| `X` | Delete current row and all those below |
|
|
306
|
+
| `Ctrl+X` | Delete current row and all those above |
|
|
307
|
+
| `d` | Duplicate current column |
|
|
308
|
+
| `D` | Duplicate current row |
|
|
309
|
+
| `o` | Explode current list column into multiple rows |
|
|
310
|
+
| `O` | Explode current string column by delimiter into multiple rows |
|
|
307
311
|
|
|
308
312
|
#### Row Selection
|
|
309
313
|
|
|
@@ -255,8 +255,8 @@ def main() -> None:
|
|
|
255
255
|
sys.exit(1)
|
|
256
256
|
|
|
257
257
|
# If output file is specified, write the (optionally modified) data to the output file and exit
|
|
258
|
-
if args.output:
|
|
259
|
-
return write_file(sources,
|
|
258
|
+
if filename := args.output:
|
|
259
|
+
return write_file(sources, filename)
|
|
260
260
|
|
|
261
261
|
# Run the DataFrame Viewer application
|
|
262
262
|
app = DataFrameViewer(*sources, theme=args.theme)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"""Common utilities and constants for dataframe_viewer."""
|
|
2
2
|
|
|
3
|
+
import gzip
|
|
3
4
|
import json
|
|
4
5
|
import os
|
|
5
6
|
import re
|
|
6
7
|
import sys
|
|
8
|
+
from contextlib import contextmanager
|
|
7
9
|
from dataclasses import dataclass
|
|
8
10
|
from io import StringIO
|
|
9
11
|
from pathlib import Path
|
|
@@ -19,7 +21,6 @@ SUPPORTED_FORMATS = {
|
|
|
19
21
|
"csv": ",",
|
|
20
22
|
"psv": "|",
|
|
21
23
|
"xlsx": None,
|
|
22
|
-
"xls": None,
|
|
23
24
|
"parquet": None,
|
|
24
25
|
"ndjson": None,
|
|
25
26
|
"jsonl": None,
|
|
@@ -167,6 +168,7 @@ CURSOR_TYPES = ["row", "column", "cell"]
|
|
|
167
168
|
|
|
168
169
|
# Row index mapping between filtered and original dataframe
|
|
169
170
|
RID = "^_RID_^"
|
|
171
|
+
RID_OLD = "^_RID_OLD_^"
|
|
170
172
|
|
|
171
173
|
|
|
172
174
|
@dataclass
|
|
@@ -539,6 +541,14 @@ def handle_compute_error(err_msg: str) -> None:
|
|
|
539
541
|
)
|
|
540
542
|
sys.exit(1)
|
|
541
543
|
|
|
544
|
+
# no data to load
|
|
545
|
+
elif "The provided LazyFrame has no data to load" in err_msg:
|
|
546
|
+
print(
|
|
547
|
+
f"{'-' * 21}\n{err_msg}\n{'-' * 21}\nNo data could be read from the input. Check if the file is empty or if the format/delimiter is correct.",
|
|
548
|
+
file=sys.stderr,
|
|
549
|
+
)
|
|
550
|
+
sys.exit(1)
|
|
551
|
+
|
|
542
552
|
else:
|
|
543
553
|
print(
|
|
544
554
|
f"{'-' * 21}\n{err_msg}\n{'-' * 21}\nUnhandled error. Try again with `-E` to ignore errors", file=sys.stderr
|
|
@@ -615,6 +625,71 @@ def round_to_nearest_hundreds(num: int, N: int = 100) -> tuple[int, int]:
|
|
|
615
625
|
return (lower, upper)
|
|
616
626
|
|
|
617
627
|
|
|
628
|
+
@contextmanager
|
|
629
|
+
def zopen(source: str | Path | StringIO):
|
|
630
|
+
"""Context manager to open files, including gzip compressed files.
|
|
631
|
+
|
|
632
|
+
Args:
|
|
633
|
+
source: The file path, Path object, or StringIO to open.
|
|
634
|
+
|
|
635
|
+
Yields:
|
|
636
|
+
A file-like object for the opened source.
|
|
637
|
+
"""
|
|
638
|
+
# Handle StringIO from stdin directly
|
|
639
|
+
if isinstance(source, StringIO):
|
|
640
|
+
yield source
|
|
641
|
+
|
|
642
|
+
# file-like object
|
|
643
|
+
else:
|
|
644
|
+
filepath = Path(source)
|
|
645
|
+
is_gzipped = filepath.suffix.lower() == ".gz"
|
|
646
|
+
|
|
647
|
+
if is_gzipped:
|
|
648
|
+
with gzip.open(filepath, "rt") as f:
|
|
649
|
+
yield f
|
|
650
|
+
else:
|
|
651
|
+
with open(filepath, "r") as f:
|
|
652
|
+
yield f
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
def scan_ndjson(
|
|
656
|
+
source: str | Path | StringIO,
|
|
657
|
+
n_rows: int | None = None,
|
|
658
|
+
infer_schema_length: int | None = 100,
|
|
659
|
+
ignore_errors: bool = False,
|
|
660
|
+
) -> pl.LazyFrame:
|
|
661
|
+
"""Scan an NDJSON file into a Polars LazyFrame while preserving column order.
|
|
662
|
+
|
|
663
|
+
Args:
|
|
664
|
+
source: Path to the NDJSON file, a Path object, or a StringIO object.
|
|
665
|
+
n_rows: Number of rows to read from the file. If None, read all rows. Defaults to None.
|
|
666
|
+
infer_schema_length: Number of rows to use for schema inference. Defaults to 100.
|
|
667
|
+
ignore_errors: Whether to ignore errors during scanning. Defaults to False.
|
|
668
|
+
|
|
669
|
+
Returns:
|
|
670
|
+
A Polars LazyFrame representing the scanned NDJSON data.
|
|
671
|
+
"""
|
|
672
|
+
# https://github.com/pola-rs/polars/issues/23023
|
|
673
|
+
# read_ndjson does not retain column order for 33 or more columns
|
|
674
|
+
with zopen(source) as f:
|
|
675
|
+
# Get column order from the first line
|
|
676
|
+
line = f.readline()
|
|
677
|
+
ordered_columns = json.loads(line).keys()
|
|
678
|
+
|
|
679
|
+
# Reset file to the beginning
|
|
680
|
+
f.seek(0)
|
|
681
|
+
|
|
682
|
+
lf = pl.scan_ndjson(
|
|
683
|
+
f,
|
|
684
|
+
n_rows=n_rows,
|
|
685
|
+
infer_schema_length=infer_schema_length,
|
|
686
|
+
ignore_errors=ignore_errors,
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
# Reorder columns to match original order
|
|
690
|
+
return lf.select(pl.col(ordered_columns))
|
|
691
|
+
|
|
692
|
+
|
|
618
693
|
def scan_vortex(source: str | list[str], n_rows: int | None = None) -> pl.LazyFrame:
|
|
619
694
|
"""Scan a Vortex file into a Polars LazyFrame.
|
|
620
695
|
|
|
@@ -847,7 +922,7 @@ def load_file(
|
|
|
847
922
|
new_columns=new_columns,
|
|
848
923
|
)
|
|
849
924
|
data.append(Source(lf, filename, filepath.stem))
|
|
850
|
-
elif fmt
|
|
925
|
+
elif fmt == "xlsx":
|
|
851
926
|
if first_sheet:
|
|
852
927
|
# Read only the first sheet for multiple files
|
|
853
928
|
try:
|
|
@@ -874,23 +949,8 @@ def load_file(
|
|
|
874
949
|
lf = pl.scan_parquet(source, n_rows=n_rows)
|
|
875
950
|
data.append(Source(lf, filename, filepath.stem))
|
|
876
951
|
elif fmt in ("jsonl", "ndjson"):
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
if isinstance(source, StringIO):
|
|
880
|
-
line = source.readline()
|
|
881
|
-
ordered_columns = json.loads(line).keys() # Get column order from the first line
|
|
882
|
-
source.seek(0) # Reset StringIO to the beginning after validation
|
|
883
|
-
else:
|
|
884
|
-
with open(source) as f:
|
|
885
|
-
line = f.readline()
|
|
886
|
-
ordered_columns = json.loads(line).keys() # Get column order from the first line
|
|
887
|
-
lf = pl.scan_ndjson(
|
|
888
|
-
source,
|
|
889
|
-
n_rows=n_rows,
|
|
890
|
-
infer_schema_length=infer_schema_length,
|
|
891
|
-
ignore_errors=ignore_errors,
|
|
892
|
-
)
|
|
893
|
-
data.append(Source(lf.select(ordered_columns), filename, filepath.stem))
|
|
952
|
+
lf = scan_ndjson(source, n_rows=n_rows, infer_schema_length=infer_schema_length, ignore_errors=ignore_errors)
|
|
953
|
+
data.append(Source(lf, filename, filepath.stem))
|
|
894
954
|
elif fmt == "json":
|
|
895
955
|
try:
|
|
896
956
|
df = pl.read_json(source)
|
|
@@ -934,37 +994,39 @@ def load_file(
|
|
|
934
994
|
def write_file(sources: list[Source], filename: str) -> None:
|
|
935
995
|
if not (fmt := guess_file_format(filename)):
|
|
936
996
|
print(
|
|
937
|
-
f"Unsupported output file format for `{filename}`. Supported formats: {', '.join(SUPPORTED_FORMATS)}",
|
|
997
|
+
f"Unsupported output file format `{fmt}` for `{filename}`. Supported formats: {', '.join(SUPPORTED_FORMATS)}",
|
|
938
998
|
file=sys.stderr,
|
|
939
999
|
)
|
|
940
1000
|
sys.exit(1)
|
|
941
1001
|
|
|
942
|
-
if len(sources) > 1 and fmt
|
|
943
|
-
print("Only Excel
|
|
1002
|
+
if len(sources) > 1 and fmt != "xlsx":
|
|
1003
|
+
print("Only Excel format (.xlsx) support multiple tabs", file=sys.stderr)
|
|
944
1004
|
sys.exit(1)
|
|
945
1005
|
|
|
946
1006
|
# Get rid of the RID column
|
|
947
1007
|
for source in sources:
|
|
948
1008
|
source.lf = source.lf.select(pl.exclude(RID))
|
|
949
1009
|
|
|
1010
|
+
compression = "gzip" if filename.endswith(".gz") else "uncompressed"
|
|
1011
|
+
|
|
950
1012
|
try:
|
|
951
1013
|
if fmt == "csv":
|
|
952
|
-
sources[0].lf.sink_csv(filename)
|
|
1014
|
+
sources[0].lf.sink_csv(filename, compression=compression)
|
|
953
1015
|
elif fmt == "tsv":
|
|
954
|
-
sources[0].lf.sink_csv(filename, separator="\t")
|
|
1016
|
+
sources[0].lf.sink_csv(filename, separator="\t", compression=compression)
|
|
955
1017
|
elif fmt == "psv":
|
|
956
|
-
sources[0].lf.sink_csv(filename, separator="|")
|
|
1018
|
+
sources[0].lf.sink_csv(filename, separator="|", compression=compression)
|
|
957
1019
|
elif fmt == "parquet":
|
|
958
1020
|
sources[0].lf.sink_parquet(filename)
|
|
959
1021
|
elif fmt in ("jsonl", "ndjson"):
|
|
960
|
-
sources[0].lf.sink_ndjson(filename)
|
|
1022
|
+
sources[0].lf.sink_ndjson(filename, compression=compression)
|
|
961
1023
|
elif fmt == "json":
|
|
962
1024
|
sources[0].lf.collect().write_json(filename)
|
|
963
1025
|
elif fmt == "vortex":
|
|
964
1026
|
import vortex as vx
|
|
965
1027
|
|
|
966
1028
|
vx.io.write(sources[0].lf.collect().to_arrow(), filename)
|
|
967
|
-
elif fmt
|
|
1029
|
+
elif fmt == "xlsx":
|
|
968
1030
|
if len(sources) == 1:
|
|
969
1031
|
sources[0].lf.collect().write_excel(filename)
|
|
970
1032
|
else:
|
|
@@ -973,11 +1035,7 @@ def write_file(sources: list[Source], filename: str) -> None:
|
|
|
973
1035
|
worksheet = wb.add_worksheet(source.tabname)
|
|
974
1036
|
source.lf.collect().write_excel(workbook=wb, worksheet=worksheet)
|
|
975
1037
|
else:
|
|
976
|
-
|
|
977
|
-
f"Unsupported output format: {fmt}. Supported formats are: {', '.join(SUPPORTED_FORMATS)}",
|
|
978
|
-
file=sys.stderr,
|
|
979
|
-
)
|
|
980
|
-
sys.exit(1)
|
|
1038
|
+
pass
|
|
981
1039
|
except Exception as e:
|
|
982
1040
|
print(f"Error writing to output file: {e}", file=sys.stderr)
|
|
983
1041
|
sys.exit(1)
|