parq-cli 0.2.1__tar.gz → 0.2.3__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.
Files changed (54) hide show
  1. {parq_cli-0.2.1 → parq_cli-0.2.3}/.gitignore +3 -0
  2. parq_cli-0.2.3/CHANGELOG.md +41 -0
  3. {parq_cli-0.2.1 → parq_cli-0.2.3}/PKG-INFO +3 -2
  4. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/cli.py +126 -114
  5. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/_chunk_writers.py +133 -52
  6. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/_common.py +45 -8
  7. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/_csv.py +3 -1
  8. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/_parquet.py +6 -0
  9. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/_xlsx.py +24 -4
  10. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/output.py +24 -5
  11. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/plain_output.py +30 -5
  12. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/reader.py +228 -106
  13. {parq_cli-0.2.1 → parq_cli-0.2.3}/pyproject.toml +3 -2
  14. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_cli.py +84 -0
  15. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_output.py +33 -0
  16. parq_cli-0.2.3/tests/test_output_not_input.py +63 -0
  17. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_plain_output.py +36 -0
  18. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_reader.py +220 -1
  19. parq_cli-0.2.3/tests/test_xlsx_defused.py +31 -0
  20. {parq_cli-0.2.1 → parq_cli-0.2.3}/uv.lock +101 -87
  21. parq_cli-0.2.1/CHANGELOG.md +0 -18
  22. {parq_cli-0.2.1 → parq_cli-0.2.3}/.claude/settings.json +0 -0
  23. {parq_cli-0.2.1 → parq_cli-0.2.3}/.github/workflows/publish.yml +0 -0
  24. {parq_cli-0.2.1 → parq_cli-0.2.3}/.github/workflows/test.yml +0 -0
  25. {parq_cli-0.2.1 → parq_cli-0.2.3}/.python-version +0 -0
  26. {parq_cli-0.2.1 → parq_cli-0.2.3}/.tmp-bench/csv-large.csv +0 -0
  27. {parq_cli-0.2.1 → parq_cli-0.2.3}/.tmp-bench/csv-small.csv +0 -0
  28. {parq_cli-0.2.1 → parq_cli-0.2.3}/.tmp-bench/parquet-large.parquet +0 -0
  29. {parq_cli-0.2.1 → parq_cli-0.2.3}/.tmp-bench/parquet-small.parquet +0 -0
  30. {parq_cli-0.2.1 → parq_cli-0.2.3}/AGENTS.md +0 -0
  31. {parq_cli-0.2.1 → parq_cli-0.2.3}/CLAUDE.md +0 -0
  32. {parq_cli-0.2.1 → parq_cli-0.2.3}/LICENSE +0 -0
  33. {parq_cli-0.2.1 → parq_cli-0.2.3}/README.md +0 -0
  34. {parq_cli-0.2.1 → parq_cli-0.2.3}/README_CN.md +0 -0
  35. {parq_cli-0.2.1 → parq_cli-0.2.3}/data/test.parquet +0 -0
  36. {parq_cli-0.2.1 → parq_cli-0.2.3}/docs/QUICKSTART.md +0 -0
  37. {parq_cli-0.2.1 → parq_cli-0.2.3}/docs/RELEASE.md +0 -0
  38. {parq_cli-0.2.1 → parq_cli-0.2.3}/examples/README.md +0 -0
  39. {parq_cli-0.2.1 → parq_cli-0.2.3}/examples/create_sample_data.py +0 -0
  40. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/__init__.py +0 -0
  41. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/__main__.py +0 -0
  42. {parq_cli-0.2.1 → parq_cli-0.2.3}/parq/formats/__init__.py +0 -0
  43. {parq_cli-0.2.1 → parq_cli-0.2.3}/scripts/README.md +0 -0
  44. {parq_cli-0.2.1 → parq_cli-0.2.3}/scripts/bump_version.py +0 -0
  45. {parq_cli-0.2.1 → parq_cli-0.2.3}/scripts/check_version.py +0 -0
  46. {parq_cli-0.2.1 → parq_cli-0.2.3}/scripts/performance_benchmark.py +0 -0
  47. {parq_cli-0.2.1 → parq_cli-0.2.3}/scripts/publish.sh +0 -0
  48. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/__init__.py +0 -0
  49. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/conftest.py +0 -0
  50. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_main_entry.py +0 -0
  51. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_package_meta.py +0 -0
  52. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_performance.py +0 -0
  53. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_release_scripts.py +0 -0
  54. {parq_cli-0.2.1 → parq_cli-0.2.3}/tests/test_workflows.py +0 -0
@@ -210,3 +210,6 @@ project_document/
210
210
  .history/
211
211
  .worktrees/
212
212
  worktrees/
213
+
214
+ # macOS
215
+ .DS_Store
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ## 0.2.3
6
+
7
+ - `merge --force` and `convert --force` replace an existing output file only after the new file is fully written. A schema mismatch or a write error leaves the previous file in place, and the temporary file is removed, including on Windows.
8
+ - `diff` treats NaN as equal to NaN, including when NaN is the key.
9
+ - `diff` and `merge` close Parquet file handles when they finish.
10
+ - JSON table output summarizes binary values, matching rich and plain output.
11
+ - `split --force` replaces existing part files only after every part is written. A later write error leaves the previous parts in place.
12
+ - Column stats ignore NaN when computing min, max, and mean. Nulls are still counted separately, and NaN stays in the non-null count.
13
+ - An empty, multi-character, or non-ASCII `--delimiter` is rejected with `delimiter must be a single ASCII character` before CSV parsing or writing.
14
+ - `stats --limit`, `stats --top-n`, and `diff --limit` reject negative values instead of slicing from the end. Zero still means an empty result.
15
+ - Selecting a duplicated column name reports that the name cannot be selected, instead of claiming the column does not exist. A unique column in the same file can still be selected.
16
+ - `diff` compares repeated column names by position. A diff that would compare those names by default asks for `--columns` instead of claiming the column does not exist.
17
+
18
+ ## 0.2.2
19
+
20
+ - `merge --force` and `convert` now refuse an output path that is one of the inputs. Previously `--force` deleted that input before reading it.
21
+ - XLSX workbook XML is parsed with `defusedxml` (added to the `xlsx` extra).
22
+ - Table output escapes cell markup and summarizes binary values (#4).
23
+ - Errors include the file path (#5).
24
+ - Dependency security updates: certifi, urllib3, idna, pygments, cryptography, pyarrow.
25
+
26
+ ## 0.2.1
27
+
28
+ - `diff` and `merge` honor the global `--delimiter` and `--sheet` options.
29
+ - `.tsv` is a supported output format for `convert`, `split`, and `merge`.
30
+ - XLSX `schema` still samples the first 1000 rows. Full reads widen a column when a later row does not fit that sample.
31
+ - String cardinality and top values stay exact past 10,000 distinct values. Nulls are not counted as empty strings.
32
+ - `diff` spills inputs larger than 100,000 rows per side into temporary files.
33
+ - `split --record-count` progress stays indeterminate while the total is still unknown.
34
+ - PyPI uploads run from a `v*` tag and use the repository `PYPI_API_TOKEN`.
35
+ - XLSX reads use `python-calamine`. A full read parses the workbook once and reuses those rows.
36
+ - CSV `convert` no longer counts every row before writing when a progress bar is shown.
37
+ - `--output`, `--delimiter`, and `--sheet` work before a subcommand and on the subcommand. The value on the subcommand wins when both are set.
38
+
39
+ ## 0.2.0
40
+
41
+ - Inspect, split, convert, diff, and merge Parquet, CSV, TSV, and XLSX files.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: parq-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A command-line tool for inspecting tabular files: Parquet, CSV, TSV, and XLSX
5
5
  Project-URL: Homepage, https://github.com/Tendo33/parq-cli
6
6
  Project-URL: Repository, https://github.com/Tendo33/parq-cli
@@ -26,10 +26,11 @@ Provides-Extra: dev
26
26
  Requires-Dist: build>=1.2.0; extra == 'dev'
27
27
  Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
28
28
  Requires-Dist: pytest>=8.0.0; extra == 'dev'
29
- Requires-Dist: ruff>=0.7.0; extra == 'dev'
29
+ Requires-Dist: ruff==0.14.0; extra == 'dev'
30
30
  Requires-Dist: twine>=5.1.0; extra == 'dev'
31
31
  Requires-Dist: vulture>=2.14; extra == 'dev'
32
32
  Provides-Extra: xlsx
33
+ Requires-Dist: defusedxml>=0.7.1; extra == 'xlsx'
33
34
  Requires-Dist: openpyxl>=3.1.0; extra == 'xlsx'
34
35
  Requires-Dist: python-calamine>=0.8.0; extra == 'xlsx'
35
36
  Description-Content-Type: text/markdown
@@ -129,18 +129,20 @@ def _run_with_error_handling(
129
129
  operation: Callable[[Any], None],
130
130
  *,
131
131
  generic_error_prefix: str,
132
+ file_path: Optional[Path] = None,
132
133
  ) -> None:
133
134
  """Execute a CLI operation with consistent error handling."""
135
+ path_text = str(file_path) if file_path is not None else None
134
136
  formatter = _get_formatter(ctx)
135
137
  try:
136
138
  operation(formatter)
137
139
  except typer.Exit:
138
140
  raise
139
141
  except (FileNotFoundError, ValueError, FileExistsError) as e:
140
- formatter.print_error(str(e))
142
+ formatter.print_error(str(e), file_path=path_text)
141
143
  raise typer.Exit(code=1) from e
142
144
  except Exception as e:
143
- formatter.print_error(f"{generic_error_prefix}: {e}")
145
+ formatter.print_error(f"{generic_error_prefix}: {e}", file_path=path_text)
144
146
  raise typer.Exit(code=1) from e
145
147
 
146
148
 
@@ -205,10 +207,12 @@ def meta(
205
207
  _apply_command_options(ctx, output_format, delimiter, sheet)
206
208
 
207
209
  def operation(formatter: Any) -> None:
208
- reader = _get_reader(str(file), _get_state(ctx))
209
- formatter.print_metadata(reader.get_metadata_dict(fast=fast))
210
+ with _get_reader(str(file), _get_state(ctx)) as reader:
211
+ formatter.print_metadata(reader.get_metadata_dict(fast=fast))
210
212
 
211
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to read file")
213
+ _run_with_error_handling(
214
+ ctx, operation, generic_error_prefix="Failed to read file", file_path=file
215
+ )
212
216
 
213
217
 
214
218
  @app.command()
@@ -223,10 +227,12 @@ def schema(
223
227
  _apply_command_options(ctx, output_format, delimiter, sheet)
224
228
 
225
229
  def operation(formatter: Any) -> None:
226
- reader = _get_reader(str(file), _get_state(ctx))
227
- formatter.print_schema(reader.get_schema_info())
230
+ with _get_reader(str(file), _get_state(ctx)) as reader:
231
+ formatter.print_schema(reader.get_schema_info())
228
232
 
229
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to read file")
233
+ _run_with_error_handling(
234
+ ctx, operation, generic_error_prefix="Failed to read file", file_path=file
235
+ )
230
236
 
231
237
 
232
238
  @app.command()
@@ -246,11 +252,13 @@ def head(
246
252
  _apply_command_options(ctx, output_format, delimiter, sheet)
247
253
 
248
254
  def operation(formatter: Any) -> None:
249
- reader = _get_reader(str(file), _get_state(ctx))
250
- table = reader.read_head(n, columns=_parse_column_list(columns))
251
- formatter.print_table(table, f"First {n} Rows")
255
+ with _get_reader(str(file), _get_state(ctx)) as reader:
256
+ table = reader.read_head(n, columns=_parse_column_list(columns))
257
+ formatter.print_table(table, f"First {n} Rows")
252
258
 
253
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to read file")
259
+ _run_with_error_handling(
260
+ ctx, operation, generic_error_prefix="Failed to read file", file_path=file
261
+ )
254
262
 
255
263
 
256
264
  @app.command()
@@ -270,11 +278,13 @@ def tail(
270
278
  _apply_command_options(ctx, output_format, delimiter, sheet)
271
279
 
272
280
  def operation(formatter: Any) -> None:
273
- reader = _get_reader(str(file), _get_state(ctx))
274
- table = reader.read_tail(n, columns=_parse_column_list(columns))
275
- formatter.print_table(table, f"Last {n} Rows")
281
+ with _get_reader(str(file), _get_state(ctx)) as reader:
282
+ table = reader.read_tail(n, columns=_parse_column_list(columns))
283
+ formatter.print_table(table, f"Last {n} Rows")
276
284
 
277
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to read file")
285
+ _run_with_error_handling(
286
+ ctx, operation, generic_error_prefix="Failed to read file", file_path=file
287
+ )
278
288
 
279
289
 
280
290
  @app.command()
@@ -289,10 +299,12 @@ def count(
289
299
  _apply_command_options(ctx, output_format, delimiter, sheet)
290
300
 
291
301
  def operation(formatter: Any) -> None:
292
- reader = _get_reader(str(file), _get_state(ctx))
293
- formatter.print_count(reader.num_rows)
302
+ with _get_reader(str(file), _get_state(ctx)) as reader:
303
+ formatter.print_count(reader.num_rows)
294
304
 
295
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to read file")
305
+ _run_with_error_handling(
306
+ ctx, operation, generic_error_prefix="Failed to read file", file_path=file
307
+ )
296
308
 
297
309
 
298
310
  @app.command()
@@ -340,67 +352,66 @@ def split(
340
352
  import time
341
353
 
342
354
  start_time = time.time()
343
- reader = _get_reader(str(file), state)
344
-
345
- if state.output_format == OutputFormat.RICH:
346
- from rich.progress import (
347
- BarColumn,
348
- Progress,
349
- SpinnerColumn,
350
- TextColumn,
351
- TimeRemainingColumn,
352
- )
353
- from parq.output import console
354
-
355
- with Progress(
356
- SpinnerColumn(),
357
- TextColumn("[bold blue]{task.description}"),
358
- BarColumn(),
359
- TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
360
- TimeRemainingColumn(),
361
- console=console,
362
- ) as progress:
363
- task = progress.add_task(f"[cyan]Splitting {file.name}...", total=None)
364
-
365
- def update_progress(current: int, total: int):
366
- if progress.tasks[task].total is None and total:
367
- progress.update(task, total=total)
368
- progress.update(task, completed=current)
369
-
355
+ with _get_reader(str(file), state) as reader:
356
+ if state.output_format == OutputFormat.RICH:
357
+ from rich.progress import (
358
+ BarColumn,
359
+ Progress,
360
+ SpinnerColumn,
361
+ TextColumn,
362
+ TimeRemainingColumn,
363
+ )
364
+ from parq.output import console
365
+
366
+ with Progress(
367
+ SpinnerColumn(),
368
+ TextColumn("[bold blue]{task.description}"),
369
+ BarColumn(),
370
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
371
+ TimeRemainingColumn(),
372
+ console=console,
373
+ ) as progress:
374
+ task = progress.add_task(f"[cyan]Splitting {file.name}...", total=None)
375
+
376
+ def update_progress(current: int, total: int):
377
+ if progress.tasks[task].total is None and total:
378
+ progress.update(task, total=total)
379
+ progress.update(task, completed=current)
380
+
381
+ output_files = reader.split_file(
382
+ output_pattern=name_format,
383
+ file_count=file_count,
384
+ record_count=record_count,
385
+ progress_callback=update_progress,
386
+ force=force,
387
+ )
388
+ else:
370
389
  output_files = reader.split_file(
371
390
  output_pattern=name_format,
372
391
  file_count=file_count,
373
392
  record_count=record_count,
374
- progress_callback=update_progress,
375
393
  force=force,
376
394
  )
377
- else:
378
- output_files = reader.split_file(
379
- output_pattern=name_format,
380
- file_count=file_count,
381
- record_count=record_count,
382
- force=force,
383
- )
384
395
 
385
- elapsed_time = time.time() - start_time
386
- total_rows = (
387
- reader.last_split_total_rows
388
- if reader.last_split_total_rows is not None
389
- else reader.num_rows
390
- )
391
- formatter.print_split_result(
392
- source_file=file,
393
- output_files=output_files,
394
- total_rows=total_rows,
395
- elapsed_time=elapsed_time,
396
- )
396
+ elapsed_time = time.time() - start_time
397
+ total_rows = (
398
+ reader.last_split_total_rows
399
+ if reader.last_split_total_rows is not None
400
+ else reader.num_rows
401
+ )
402
+ formatter.print_split_result(
403
+ source_file=file,
404
+ output_files=output_files,
405
+ total_rows=total_rows,
406
+ elapsed_time=elapsed_time,
407
+ )
397
408
  except typer.Exit:
398
409
  raise
399
410
  except (FileNotFoundError, ValueError, FileExistsError) as e:
400
- formatter.print_error(str(e))
411
+ formatter.print_error(str(e), file_path=str(file))
401
412
  raise typer.Exit(code=1) from e
402
413
  except Exception as e:
403
- formatter.print_error(f"Failed to split file: {e}")
414
+ formatter.print_error(f"Failed to split file: {e}", file_path=str(file))
404
415
  raise typer.Exit(code=1) from e
405
416
 
406
417
 
@@ -425,12 +436,14 @@ def stats(
425
436
  _apply_command_options(ctx, output_format, delimiter, sheet)
426
437
 
427
438
  def operation(formatter: Any) -> None:
428
- reader = _get_reader(str(file), _get_state(ctx))
429
- formatter.print_stats(
430
- reader.get_stats(columns=_parse_column_list(columns), limit=limit, top_n=top_n)
431
- )
439
+ with _get_reader(str(file), _get_state(ctx)) as reader:
440
+ formatter.print_stats(
441
+ reader.get_stats(columns=_parse_column_list(columns), limit=limit, top_n=top_n)
442
+ )
432
443
 
433
- _run_with_error_handling(ctx, operation, generic_error_prefix="Failed to compute stats")
444
+ _run_with_error_handling(
445
+ ctx, operation, generic_error_prefix="Failed to compute stats", file_path=file
446
+ )
434
447
 
435
448
 
436
449
  @app.command()
@@ -462,59 +475,58 @@ def convert(
462
475
  import time
463
476
 
464
477
  start_time = time.time()
465
- reader = _get_reader(str(source), state)
466
-
467
- if state.output_format == OutputFormat.RICH:
468
- from rich.progress import (
469
- Progress,
470
- SpinnerColumn,
471
- TextColumn,
472
- BarColumn,
473
- TimeRemainingColumn,
474
- )
475
- from parq.output import console
476
-
477
- total_rows_hint = reader.num_rows if reader.input_format == "parquet" else 0
478
-
479
- with Progress(
480
- SpinnerColumn(),
481
- TextColumn("[bold blue]{task.description}"),
482
- BarColumn(),
483
- TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
484
- TimeRemainingColumn(),
485
- console=console,
486
- ) as progress:
487
- task = progress.add_task(
488
- f"[cyan]Converting {source.name}...",
489
- total=total_rows_hint if total_rows_hint > 0 else None,
478
+ with _get_reader(str(source), state) as reader:
479
+ if state.output_format == OutputFormat.RICH:
480
+ from rich.progress import (
481
+ Progress,
482
+ SpinnerColumn,
483
+ TextColumn,
484
+ BarColumn,
485
+ TimeRemainingColumn,
490
486
  )
491
-
492
- def update_progress(current: int, total: int) -> None:
493
- if progress.tasks[task].total is None and total:
494
- progress.update(task, total=total)
495
- progress.update(task, completed=current)
496
-
487
+ from parq.output import console
488
+
489
+ total_rows_hint = reader.num_rows if reader.input_format == "parquet" else 0
490
+
491
+ with Progress(
492
+ SpinnerColumn(),
493
+ TextColumn("[bold blue]{task.description}"),
494
+ BarColumn(),
495
+ TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
496
+ TimeRemainingColumn(),
497
+ console=console,
498
+ ) as progress:
499
+ task = progress.add_task(
500
+ f"[cyan]Converting {source.name}...",
501
+ total=total_rows_hint if total_rows_hint > 0 else None,
502
+ )
503
+
504
+ def update_progress(current: int, total: int) -> None:
505
+ if progress.tasks[task].total is None and total:
506
+ progress.update(task, total=total)
507
+ progress.update(task, completed=current)
508
+
509
+ total_rows = reader.convert_file(
510
+ output,
511
+ columns=_parse_column_list(columns),
512
+ force=force,
513
+ progress_callback=update_progress,
514
+ )
515
+ else:
497
516
  total_rows = reader.convert_file(
498
517
  output,
499
518
  columns=_parse_column_list(columns),
500
519
  force=force,
501
- progress_callback=update_progress,
502
520
  )
503
- else:
504
- total_rows = reader.convert_file(
505
- output,
506
- columns=_parse_column_list(columns),
507
- force=force,
508
- )
509
521
 
510
- formatter.print_convert_result(source, output, total_rows, time.time() - start_time)
522
+ formatter.print_convert_result(source, output, total_rows, time.time() - start_time)
511
523
  except typer.Exit:
512
524
  raise
513
525
  except (FileNotFoundError, ValueError, FileExistsError) as e:
514
- formatter.print_error(str(e))
526
+ formatter.print_error(str(e), file_path=str(source))
515
527
  raise typer.Exit(code=1) from e
516
528
  except Exception as e:
517
- formatter.print_error(f"Failed to convert file: {e}")
529
+ formatter.print_error(f"Failed to convert file: {e}", file_path=str(source))
518
530
  raise typer.Exit(code=1) from e
519
531
 
520
532