dataframe-toolkit 0.4.1__tar.gz → 0.5.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.
Files changed (44) hide show
  1. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/PKG-INFO +1 -1
  2. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/pyproject.toml +1 -1
  3. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/__init__.py +6 -3
  4. dataframe_toolkit-0.5.0/src/dftk/commands/info_cmd.py +74 -0
  5. dataframe_toolkit-0.5.0/src/dftk/commands/segid_cmd.py +118 -0
  6. dataframe_toolkit-0.5.0/src/dftk/commands/transpose_cmd.py +57 -0
  7. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/README.md +0 -0
  8. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/__init__.py +0 -0
  9. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/cli.py +0 -0
  10. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/annotate_cmd.py +0 -0
  11. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/base.py +0 -0
  12. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/binx_cmd.py +0 -0
  13. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/clean_cmd.py +0 -0
  14. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/concat_cmd.py +0 -0
  15. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/corr_cmd.py +0 -0
  16. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/dataset_cmd.py +0 -0
  17. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/describe_cmd.py +0 -0
  18. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/eval_cmd.py +0 -0
  19. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/fit_cmd.py +0 -0
  20. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/func_cmd.py +0 -0
  21. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/help.py +0 -0
  22. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/hist_cmd.py +0 -0
  23. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/interp_cmd.py +0 -0
  24. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/line_cmd.py +0 -0
  25. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/melt_cmd.py +0 -0
  26. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/merge_cmd.py +0 -0
  27. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/pivot_cmd.py +0 -0
  28. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/print_cmd.py +0 -0
  29. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/query_cmd.py +0 -0
  30. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/randvar_cmd.py +0 -0
  31. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/sample_cmd.py +0 -0
  32. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/scale_cmd.py +0 -0
  33. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/scat_cmd.py +0 -0
  34. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/split_cmd.py +0 -0
  35. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/stat_cmd.py +0 -0
  36. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/test_cmd.py +0 -0
  37. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/commands/wstat_cmd.py +0 -0
  38. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/__init__.py +0 -0
  39. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/io.py +0 -0
  40. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/plot.py +0 -0
  41. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/seed.py +0 -0
  42. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/seq.py +0 -0
  43. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/common/stats.py +0 -0
  44. {dataframe_toolkit-0.4.1 → dataframe_toolkit-0.5.0}/src/dftk/io.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dataframe-toolkit
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: A command-line toolkit for DataFrame analysis and manipulation
5
5
  Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
6
6
  Author: Gunnar Pálsson
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.4.1"
3
+ version = "0.5.0"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -18,6 +18,7 @@ from dftk.commands.fit_cmd import FitCommand
18
18
  from dftk.commands.func_cmd import FuncCommand
19
19
  from dftk.commands.help import HelpCommand
20
20
  from dftk.commands.hist_cmd import HistCommand
21
+ from dftk.commands.info_cmd import InfoCommand
21
22
  from dftk.commands.interp_cmd import InterpCommand
22
23
  from dftk.commands.line_cmd import LineCommand
23
24
  from dftk.commands.melt_cmd import MeltCommand
@@ -29,15 +30,14 @@ from dftk.commands.randvar_cmd import RandvarCommand
29
30
  from dftk.commands.sample_cmd import SampleCommand
30
31
  from dftk.commands.scale_cmd import ScaleCommand
31
32
  from dftk.commands.scat_cmd import ScatCommand
33
+ from dftk.commands.segid_cmd import SegidCommand
32
34
  from dftk.commands.split_cmd import SplitCommand
33
35
  from dftk.commands.stat_cmd import StatCommand
34
36
  from dftk.commands.test_cmd import TestCommand
37
+ from dftk.commands.transpose_cmd import TransposeCommand
35
38
  from dftk.commands.wstat_cmd import WstatCommand
36
39
 
37
40
  # Ported subcommands — uncomment as each one is added:
38
- # from dftk.commands.segid import SegidCommand
39
- # from dftk.commands.info import InfoCommand
40
- # from dftk.commands.transpose import TransposeCommand
41
41
  # from dftk.commands.color import ColorCommand
42
42
  # from dftk.commands.wavelet import WaveletCommand
43
43
  # from dftk.commands.fisher import FisherCommand # superseded by eval's
@@ -57,6 +57,8 @@ COMMAND_GROUPS: list[tuple[str, list]] = [
57
57
  ScaleCommand(),
58
58
  InterpCommand(),
59
59
  BinxCommand(),
60
+ TransposeCommand(),
61
+ SegidCommand(),
60
62
  ],
61
63
  ),
62
64
  (
@@ -68,6 +70,7 @@ COMMAND_GROUPS: list[tuple[str, list]] = [
68
70
  TestCommand(),
69
71
  CorrCommand(),
70
72
  DescribeCommand(),
73
+ InfoCommand(),
71
74
  RandvarCommand(),
72
75
  ],
73
76
  ),
@@ -0,0 +1,74 @@
1
+ """
2
+ dftk.commands.info_cmd — dftk info subcommand.
3
+
4
+ Lightweight structural overview of a DataFrame: per-column dtype, null
5
+ counts, and memory usage. Complements `describe`, which profiles
6
+ statistical distributions and quality flags instead.
7
+
8
+ Example
9
+ -------
10
+ dftk info data.tsv
11
+ dftk info data.tsv --summary
12
+ """
13
+
14
+ import argparse
15
+ import sys
16
+
17
+ import pandas as pd
18
+
19
+ from dftk.commands.base import BaseCommand
20
+ from dftk.common.io import io
21
+
22
+
23
+ def _info(df: pd.DataFrame) -> pd.DataFrame:
24
+ mem = df.memory_usage(deep=True, index=False)
25
+ return pd.DataFrame(
26
+ [
27
+ dict(
28
+ name=col,
29
+ dtype=str(df[col].dtype),
30
+ non_null=int(df[col].notna().sum()),
31
+ null=int(df[col].isna().sum()),
32
+ memory_bytes=int(mem[col]),
33
+ )
34
+ for col in df.columns
35
+ ]
36
+ )
37
+
38
+
39
+ def _summary_line(df: pd.DataFrame) -> str:
40
+ n_rows, n_cols = df.shape
41
+ total_mem = int(df.memory_usage(deep=True).sum())
42
+ n_dupes = int(df.duplicated().sum())
43
+ return (
44
+ f"Dataset: {n_rows} rows x {n_cols} columns, "
45
+ f"{total_mem} bytes, {n_dupes} duplicated row(s)"
46
+ )
47
+
48
+
49
+ class InfoCommand(BaseCommand):
50
+ @property
51
+ def name(self) -> str:
52
+ return "info"
53
+
54
+ @property
55
+ def help(self) -> str:
56
+ return "Structural overview: per-column dtype, null counts, memory usage"
57
+
58
+ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
59
+ self.add_io_arguments(parser)
60
+
61
+ g = parser.add_argument_group("info options")
62
+ g.add_argument(
63
+ "--summary",
64
+ action="store_true",
65
+ help="Print dataset totals (shape, memory, duplicate rows) to stderr.",
66
+ )
67
+
68
+ def execute(self, args: argparse.Namespace) -> None:
69
+ df = io.read(args)
70
+
71
+ if getattr(args, "summary", False):
72
+ print(_summary_line(df), file=sys.stderr)
73
+
74
+ io.printdf(_info(df), args)
@@ -0,0 +1,118 @@
1
+ """
2
+ dftk.commands.segid_cmd — dftk segid subcommand.
3
+
4
+ Port of dfsegid.py: assign a segment ID that increments each time the
5
+ value in a column changes, useful for grouping contiguous runs of
6
+ identical values (e.g. constant-value stretches in a sorted column).
7
+
8
+ Rows matching --ignore are excluded from the run comparison and always get
9
+ segid 0; they don't break a run spanning across them. Redesigned from the
10
+ legacy script's magic sentinel default ('1415926535', digits of pi) to a
11
+ plain optional flag — omit --ignore to include every row.
12
+ """
13
+
14
+ import argparse
15
+
16
+ import pandas as pd
17
+
18
+ from dftk.commands.base import BaseCommand
19
+ from dftk.common.io import check_cols, io
20
+
21
+ _EPILOG = """\
22
+ EXAMPLE
23
+ -------
24
+ col
25
+ A
26
+ A
27
+ B
28
+ B
29
+ A
30
+
31
+ dftk segid data.tsv -c col
32
+
33
+ col segid
34
+ A 1
35
+ A 1
36
+ B 2
37
+ B 2
38
+ A 3
39
+
40
+ With --ignore X, rows where col == X get segid 0 and are skipped when
41
+ detecting value changes, so a run continues across them:
42
+
43
+ col
44
+ A
45
+ X
46
+ A
47
+ B
48
+
49
+ dftk segid data.tsv -c col --ignore X
50
+
51
+ col segid
52
+ A 1
53
+ X 0
54
+ A 1
55
+ B 2
56
+ """
57
+
58
+
59
+ def _segid(df: pd.DataFrame, args: argparse.Namespace) -> pd.DataFrame:
60
+ col = args.col
61
+ dest = args.destcol
62
+
63
+ df[dest] = 0
64
+
65
+ if args.ignore is not None:
66
+ ignore_value = pd.Series([args.ignore]).astype(df[col].dtype).iloc[0]
67
+ mask = df[col] != ignore_value
68
+ else:
69
+ mask = pd.Series(True, index=df.index)
70
+
71
+ subseries = df.loc[mask, col]
72
+ df.loc[mask, dest] = subseries.ne(subseries.shift()).cumsum()
73
+ return df
74
+
75
+
76
+ class SegidCommand(BaseCommand):
77
+ @property
78
+ def name(self) -> str:
79
+ return "segid"
80
+
81
+ @property
82
+ def help(self) -> str:
83
+ return "Assign a segment ID that increments on each value change"
84
+
85
+ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
86
+ parser.formatter_class = argparse.RawDescriptionHelpFormatter
87
+ parser.epilog = _EPILOG
88
+
89
+ self.add_io_arguments(parser)
90
+
91
+ g = parser.add_argument_group("segid options")
92
+ g.add_argument(
93
+ "-c",
94
+ "--col",
95
+ required=True,
96
+ metavar="COL",
97
+ help="Column whose value changes define segment boundaries.",
98
+ )
99
+ g.add_argument(
100
+ "-d",
101
+ "--destcol",
102
+ default="segid",
103
+ metavar="DESTCOL",
104
+ help="Name of the output segment-ID column (default: segid).",
105
+ )
106
+ g.add_argument(
107
+ "--ignore",
108
+ default=None,
109
+ metavar="VALUE",
110
+ help="Column value to exclude from segmenting (gets segid 0, "
111
+ "doesn't break a run spanning across it). Default: none.",
112
+ )
113
+
114
+ def execute(self, args: argparse.Namespace) -> None:
115
+ df = io.read(args)
116
+ check_cols(df, [args.col], "-c/--col")
117
+ result = _segid(df, args)
118
+ io.printdf(result, args)
@@ -0,0 +1,57 @@
1
+ """
2
+ dftk.commands.transpose_cmd — dftk transpose subcommand.
3
+
4
+ Port of dftpos.py: flips rows and columns. Original column names become
5
+ values in a new key column (default name: "column"); original row
6
+ positions become the new column headers.
7
+
8
+ Example
9
+ -------
10
+ Input:
11
+
12
+ sample x y
13
+ s1 1 2
14
+ s2 3 4
15
+
16
+ dftk transpose data.tsv
17
+
18
+ Output:
19
+
20
+ column 0 1
21
+ sample s1 s2
22
+ x 1 3
23
+ y 2 4
24
+ """
25
+
26
+ import argparse
27
+
28
+ from dftk.commands.base import BaseCommand
29
+ from dftk.common.io import io
30
+
31
+
32
+ class TransposeCommand(BaseCommand):
33
+ @property
34
+ def name(self) -> str:
35
+ return "transpose"
36
+
37
+ @property
38
+ def help(self) -> str:
39
+ return "Transpose rows and columns"
40
+
41
+ def add_arguments(self, parser: argparse.ArgumentParser) -> None:
42
+ self.add_io_arguments(parser)
43
+
44
+ g = parser.add_argument_group("transpose options")
45
+ g.add_argument(
46
+ "--keycol",
47
+ default="column",
48
+ metavar="NAME",
49
+ help="Name for the new column holding the original column names "
50
+ "(default: column).",
51
+ )
52
+
53
+ def execute(self, args: argparse.Namespace) -> None:
54
+ df = io.read(args)
55
+ result = df.transpose().reset_index(names=args.keycol)
56
+ result.columns = [str(c) for c in result.columns]
57
+ io.printdf(result, args)