dataframe-textual 0.3.2__py3-none-any.whl → 1.5.0__py3-none-any.whl

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  from .data_frame_help_panel import DataFrameHelpPanel
4
4
  from .data_frame_table import DataFrameTable, History
5
- from .data_frame_viewer import DataFrameViewer, _load_dataframe
5
+ from .data_frame_viewer import DataFrameViewer
6
6
  from .table_screen import FrequencyScreen, RowDetailScreen, TableScreen
7
7
  from .yes_no_screen import (
8
8
  ConfirmScreen,
@@ -31,5 +31,4 @@ __all__ = [
31
31
  "FilterScreen",
32
32
  "FreezeScreen",
33
33
  "OpenFileScreen",
34
- "_load_dataframe",
35
34
  ]
@@ -4,43 +4,91 @@ import argparse
4
4
  import sys
5
5
  from pathlib import Path
6
6
 
7
+ from .common import SUPPORTED_FORMATS, load_dataframe
7
8
  from .data_frame_viewer import DataFrameViewer
8
9
 
9
10
 
10
- def main():
11
- """Run the DataFrame Viewer application."""
11
+ def cli() -> argparse.Namespace:
12
+ """Parse command-line arguments.
13
+
14
+ Determines input files or stdin and validates file existence
15
+ """
12
16
  parser = argparse.ArgumentParser(
13
- description="Interactive CSV/Excel viewer for the terminal (Textual version)",
17
+ prog="dv",
18
+ description="Interactive terminal based viewer/editor for tabular data (e.g., CSV/Excel).",
14
19
  formatter_class=argparse.RawDescriptionHelpFormatter,
15
20
  epilog="Examples:\n"
16
- " dataframe-viewer data.csv\n"
17
- " dataframe-viewer file1.csv file2.csv file3.csv\n"
18
- " dataframe-viewer data.xlsx (opens all sheets in tabs)\n"
19
- " cat data.csv | dataframe-viewer\n",
21
+ " %(prog)s data.csv\n"
22
+ " %(prog)s file1.csv file2.csv file3.csv\n"
23
+ " %(prog)s data.xlsx (opens each sheet in separate tab)\n"
24
+ " cat data.csv | %(prog)s --format csv\n",
25
+ )
26
+ parser.add_argument("files", nargs="*", help="Files to view (or read from stdin)")
27
+ parser.add_argument(
28
+ "-f",
29
+ "--format",
30
+ choices=SUPPORTED_FORMATS,
31
+ help="Specify the format of the input files (csv, excel, tsv etc.)",
32
+ )
33
+ parser.add_argument(
34
+ "-H",
35
+ "--no-header",
36
+ action="store_true",
37
+ help="Specify that input files have no header row when reading CSV/TSV",
38
+ )
39
+ parser.add_argument(
40
+ "-I", "--no-inferrence", action="store_true", help="Do not infer data types when reading CSV/TSV"
20
41
  )
42
+ parser.add_argument("-E", "--ignore-errors", action="store_true", help="Ignore errors when reading CSV/TSV")
21
43
  parser.add_argument(
22
- "files", nargs="*", help="CSV or Excel files to view (or read from stdin)"
44
+ "-c", "--comment-prefix", nargs="?", const="#", help="Comment lines are skipped when reading CSV/TSV"
23
45
  )
46
+ parser.add_argument(
47
+ "-q", "--quote-char", nargs="?", const=None, default='"', help="Quote character for reading CSV/TSV"
48
+ )
49
+ parser.add_argument("-l", "--skip-lines", type=int, default=0, help="Skip lines when reading CSV/TSV")
50
+ parser.add_argument(
51
+ "-a", "--skip-rows-after-header", type=int, default=0, help="Skip rows after header when reading CSV/TSV"
52
+ )
53
+ parser.add_argument("-u", "--null", nargs="+", help="Values to interpret as null values when reading CSV/TSV")
24
54
 
25
55
  args = parser.parse_args()
26
- filenames = []
56
+ if args.files is None:
57
+ args.files = []
27
58
 
28
59
  # Check if reading from stdin (pipe or redirect)
29
60
  if not sys.stdin.isatty():
30
- filenames = ["-"]
31
- elif args.files:
61
+ args.files.append("-")
62
+ else:
32
63
  # Validate all files exist
33
64
  for filename in args.files:
34
65
  if not Path(filename).exists():
35
66
  print(f"File not found: {filename}")
36
67
  sys.exit(1)
37
- filenames = args.files
38
68
 
39
- if not filenames:
69
+ if not args.files:
40
70
  parser.print_help()
41
71
  sys.exit(1)
42
72
 
43
- app = DataFrameViewer(*filenames)
73
+ return args
74
+
75
+
76
+ def main() -> None:
77
+ """Run the DataFrame Viewer application."""
78
+ args = cli()
79
+ sources = load_dataframe(
80
+ args.files,
81
+ file_format=args.format,
82
+ has_header=not args.no_header,
83
+ infer_schema=not args.no_inferrence,
84
+ comment_prefix=args.comment_prefix,
85
+ quote_char=args.quote_char,
86
+ skip_lines=args.skip_lines,
87
+ skip_rows_after_header=args.skip_rows_after_header,
88
+ null_values=args.null,
89
+ ignore_errors=args.ignore_errors,
90
+ )
91
+ app = DataFrameViewer(*sources)
44
92
  app.run()
45
93
 
46
94