scistackplot 0.3.7__tar.gz → 0.4.1__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 (65) hide show
  1. {scistackplot-0.3.7 → scistackplot-0.4.1}/PKG-INFO +3 -3
  2. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/codegen.py +3 -3
  3. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/bins.py +90 -12
  4. {scistackplot-0.3.7 → scistackplot-0.4.1}/.gitignore +0 -0
  5. {scistackplot-0.3.7 → scistackplot-0.4.1}/README.md +0 -0
  6. {scistackplot-0.3.7 → scistackplot-0.4.1}/pyproject.toml +0 -0
  7. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/__init__.py +0 -0
  8. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/__init__.py +0 -0
  9. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/custom.py +0 -0
  10. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/figure_file.py +0 -0
  11. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/plot_data.py +0 -0
  12. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/export/reduction_code.py +0 -0
  13. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/__init__.py +0 -0
  14. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/capability.py +0 -0
  15. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/design.py +0 -0
  16. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/presets.py +0 -0
  17. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/restore.py +0 -0
  18. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/role_labels.py +0 -0
  19. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/roles.py +0 -0
  20. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/shape.py +0 -0
  21. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/spec.py +0 -0
  22. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/model/table.py +0 -0
  23. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/__init__.py +0 -0
  24. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/categorical.py +0 -0
  25. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/cell.py +0 -0
  26. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/chain.py +0 -0
  27. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/compare.py +0 -0
  28. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/diffbars.py +0 -0
  29. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/fits.py +0 -0
  30. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/groups.py +0 -0
  31. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/kde.py +0 -0
  32. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/numeric.py +0 -0
  33. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/omissions.py +0 -0
  34. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/panels.py +0 -0
  35. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/reducer.py +0 -0
  36. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/reduction.py +0 -0
  37. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/resolve.py +0 -0
  38. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/resolved.py +0 -0
  39. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/series_stats.py +0 -0
  40. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/spaghetti.py +0 -0
  41. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/spread.py +0 -0
  42. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/stacking.py +0 -0
  43. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/temporal.py +0 -0
  44. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/variants.py +0 -0
  45. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/weights.py +0 -0
  46. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/reduce/ylimits.py +0 -0
  47. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/render/__init__.py +0 -0
  48. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/render/base.py +0 -0
  49. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/render/mpl.py +0 -0
  50. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/render/plotly_.py +0 -0
  51. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/sources/__init__.py +0 -0
  52. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/sources/base.py +0 -0
  53. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/sources/csv.py +0 -0
  54. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/sources/dedup.py +0 -0
  55. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/sources/frame.py +0 -0
  56. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/__init__.py +0 -0
  57. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/aliases.py +0 -0
  58. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/autosize.py +0 -0
  59. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/colors.py +0 -0
  60. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/figsize.py +0 -0
  61. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/framesize.py +0 -0
  62. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/paper.py +0 -0
  63. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/textsize.py +0 -0
  64. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/ticklabels.py +0 -0
  65. {scistackplot-0.3.7 → scistackplot-0.4.1}/src/scistackplot/text/xaxis.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scistackplot
3
- Version: 0.3.7
3
+ Version: 0.4.1
4
4
  Summary: Spec-driven plotting for long-format scientific data — standalone, GUI-friendly
5
5
  Author: SciStack Contributors
6
6
  License-Expression: MIT
@@ -20,8 +20,8 @@ Requires-Python: >=3.10
20
20
  Requires-Dist: csv-stats>=0.5.0
21
21
  Requires-Dist: numpy>=1.21
22
22
  Requires-Dist: pandas>=1.5
23
- Requires-Dist: scicanonicalhash==0.3.7
24
- Requires-Dist: scistacklog==0.3.7
23
+ Requires-Dist: scicanonicalhash==0.4.1
24
+ Requires-Dist: scistacklog==0.4.1
25
25
  Provides-Extra: dev
26
26
  Requires-Dist: matplotlib>=3.6; extra == 'dev'
27
27
  Requires-Dist: plotly>=5.0; extra == 'dev'
@@ -6,7 +6,7 @@ alternative — ``return scistackplot.render(df, spec_path)`` — is more compac
6
6
  and stays re-editable in the GUI, but it makes every exported pipeline depend
7
7
  on this package at runtime and hides the figure's definition behind an opaque
8
8
  call. Literal code matches the project's "minimize lock-in" goal and the
9
- precedent in ``docs/claude/gui-export-to-plain-python.md``.
9
+ precedent in ``docs/claude/archive/gui-export-to-plain-python.md``.
10
10
 
11
11
  The spec is emitted as a docstring block so the GUI can round-trip it back out
12
12
  of a file the user has since hand-edited.
@@ -954,7 +954,7 @@ def _histogram_edge_lines(spec, table: LongTable, roles, shape) -> list[str]:
954
954
  from ..reduce.bins import BARS_SOURCE, EDGES_SOURCE, edge_arguments, special_arguments
955
955
 
956
956
  temporal = table.measure(spec.y_measure).temporal
957
- mode, count, width, lo, hi, max_bins = edge_arguments(spec.histogram, temporal=temporal)
957
+ mode, count, width, lo, hi, max_bins, use_grid = edge_arguments(spec.histogram, temporal=temporal)
958
958
  exact, show_nan, _notes = special_arguments(spec.histogram, temporal=temporal)
959
959
  y = spec.y_measure
960
960
  lines = [
@@ -968,7 +968,7 @@ def _histogram_edge_lines(spec, table: LongTable, roles, shape) -> list[str]:
968
968
  "_hist_regular = _scistack_regular(_hist_values, _exact)",
969
969
  f"_nan_slot = {bool(show_nan)!r} and bool((~np.isfinite(_hist_values)).any())",
970
970
  f"_edges = _scistack_bin_edges(_hist_values[_hist_regular], "
971
- f"{mode!r}, {count!r}, {width!r}, {lo!r}, {hi!r}, {max_bins!r})",
971
+ f"{mode!r}, {count!r}, {width!r}, {lo!r}, {hi!r}, {max_bins!r}, {use_grid!r})",
972
972
  ]
973
973
  if spec.histogram.stat is HistStat.PERCENT:
974
974
  keys = [*_hist_panel_keys(spec, table, roles, shape)]
@@ -15,6 +15,13 @@ Three things a histogram decides, each once:
15
15
  fixed duration (``"1h"``, ``"7D"``, ``"30min"``; no months, which have no
16
16
  fixed length — user, 2026-10-22). 7-day bins therefore start on
17
17
  Thursdays (1970-01-01 was one).
18
+ * Values on a step (every mode, numbers only; user, 2026-11-15): when every
19
+ gap between distinct values is a whole multiple of a step x (ratings 1-10:
20
+ 1; 10, 20, .. 100: 10; half points: 0.5), the edges sit half a step off the
21
+ values, so no edge sits on a value. Auto draws one bar per possible value
22
+ (past 200 of them, numpy's width rounded UP to a multiple of x); a width
23
+ anchors at a multiple of the width minus x/2; a count spans the range
24
+ widened by x/2 each side. Continuous data (no step) keeps numpy's bins.
18
25
 
19
26
  The range is the values' own extent unless ``range_min`` / ``range_max``
20
27
  pin an end. Edges are decided once per FIGURE, over every panel's values,
@@ -76,7 +83,33 @@ class BinError(ValueError):
76
83
 
77
84
  # The edges. ONE source: bin_edges executes it, codegen emits it verbatim.
78
85
  EDGES_SOURCE = '''
79
- def _scistack_bin_edges(values, mode, count, width, lo, hi, max_bins):
86
+ def _scistack_grid(values):
87
+ """The step x the finite values sit on: 1 for ratings 1-10, 10 for
88
+ 10, 20, .. 100, 0.5 for half-point ratings. 0.0 when the data is
89
+ continuous. Every gap between distinct values is a whole multiple of x;
90
+ try x = (smallest gap) / m for m = 1 .. 10 and take the first that fits,
91
+ within a 1e-6 relative tolerance (Euclid's gcd that tolerates float
92
+ noise). One distinct value: 1."""
93
+ import numpy as np
94
+
95
+ values = np.asarray(values, dtype=float)
96
+ values = values[np.isfinite(values)]
97
+ distinct = np.unique(values)
98
+ if not distinct.size:
99
+ return 0.0
100
+ if distinct.size == 1:
101
+ return 1.0
102
+ gaps = np.diff(distinct)
103
+ d_min = float(gaps.min())
104
+ for m in range(1, 11):
105
+ x = d_min / m
106
+ ratios = gaps / x
107
+ if np.all(np.abs(ratios - np.round(ratios)) <= 1e-6 * ratios):
108
+ return float(f"{x:.12g}")
109
+ return 0.0
110
+
111
+
112
+ def _scistack_bin_edges(values, mode, count, width, lo, hi, max_bins, use_grid=True, max_slots=200):
80
113
  """Histogram bin edges: the scistackplot.reduce.bins rule."""
81
114
  import math
82
115
 
@@ -92,19 +125,41 @@ def _scistack_bin_edges(values, mode, count, width, lo, hi, max_bins):
92
125
  return np.array([], dtype=float)
93
126
  if hi < lo:
94
127
  lo, hi = hi, lo
128
+ inside = values[(values >= lo) & (values <= hi)]
129
+ # Values on a step x (ratings 1-10: x = 1; 10, 20, .. 100: x = 10): every
130
+ # mode puts its edges HALF a step off the values, so no edge sits on a
131
+ # value. Off the values, a bin can hold none (auto's 0.82 width on 1-10
132
+ # ratings left [5.09, 5.91) empty) or two (width 1 from 1 put 9 and 10
133
+ # in [9, 10]).
134
+ grid = _scistack_grid(values) if use_grid else 0.0
135
+ half = grid / 2
136
+ # Where the values sit within a step (signed, near 0 for a clean scale).
137
+ offset = float(values.min()) - round(float(values.min()) / grid) * grid if grid else 0.0
95
138
  if mode == "width":
96
- start = math.floor(lo / width) * width
97
- n = max(1, int(math.ceil((hi - start) / width - 1e-9)))
139
+ start = offset - half + math.floor((lo - offset + half) / width + 1e-9) * width
140
+ n = max(1, int(math.ceil((hi + half - start) / width - 1e-9)))
98
141
  if n > max_bins:
99
142
  raise ValueError(
100
143
  f"a bin width of {width:g} makes {n} bins; at most {max_bins} fit"
101
144
  )
102
145
  edges = start + width * np.arange(n + 1, dtype=float)
103
- edges[-1] = max(edges[-1], hi)
146
+ edges[-1] = max(edges[-1], hi + half)
104
147
  return edges
105
- inside = values[(values >= lo) & (values <= hi)]
106
- bins = int(count) if mode == "count" else "auto"
107
- edges = np.histogram_bin_edges(inside, bins=bins, range=(lo, hi))
148
+ if mode == "count":
149
+ return np.histogram_bin_edges(inside, bins=int(count), range=(lo - half, hi + half))
150
+ edges = np.histogram_bin_edges(inside, bins="auto", range=(lo, hi))
151
+ if grid and len(edges) > 1:
152
+ # One bar per possible value; past max_slots values, numpy's width
153
+ # rounded UP to a multiple of x, so each bar holds the same number
154
+ # of values.
155
+ slots = int(round((hi - lo) / grid)) + 1
156
+ step = grid
157
+ if slots > max_slots:
158
+ step = grid * max(1.0, float(math.ceil(float(np.diff(edges).max()) / grid - 1e-9)))
159
+ start = offset - half + math.floor((lo - offset + half) / grid + 1e-9) * grid
160
+ n = max(1, int(math.ceil((hi + half - start) / step - 1e-9)))
161
+ if n <= max_bins:
162
+ return start + step * np.arange(n + 1, dtype=float)
108
163
  if len(edges) - 1 > max_bins:
109
164
  edges = np.histogram_bin_edges(inside, bins=max_bins, range=(lo, hi))
110
165
  return edges
@@ -479,11 +534,14 @@ def histogram_problem(options: HistogramOptions, *, temporal: bool) -> str | Non
479
534
 
480
535
 
481
536
  def edge_arguments(options: HistogramOptions, *, temporal: bool) -> tuple:
482
- """``(mode, count, width, lo, hi, max_bins)`` exactly as
537
+ """``(mode, count, width, lo, hi, max_bins, use_grid)`` exactly as
483
538
  ``_scistack_bin_edges`` takes them — what the generated code passes,
484
- so it bins over its own figure's values by the preview's settings."""
539
+ so it bins over its own figure's values by the preview's settings.
540
+ ``use_grid``: values on a step get edges halfway between the steps in
541
+ every mode — never on a date axis, whose millisecond values are not a
542
+ scale."""
485
543
  mode, count, width, lo, hi, _notes = _arguments(options, temporal=temporal)
486
- return (str(mode), count, width, lo, hi, MAX_BINS)
544
+ return (str(mode), count, width, lo, hi, MAX_BINS, not temporal)
487
545
 
488
546
 
489
547
  def _arguments(options: HistogramOptions, *, temporal: bool) -> tuple:
@@ -506,6 +564,13 @@ def _arguments(options: HistogramOptions, *, temporal: bool) -> tuple:
506
564
  return mode, int(count), width, lo, hi, notes
507
565
 
508
566
 
567
+ #: Values on a step (`_scistack_grid`): edges half a step off the values.
568
+ GRID_NOTE = "The values sit on steps of {x:g}, so the bin edges sit halfway between them."
569
+ #: A bin width that is not a multiple of the step.
570
+ OFF_GRID_NOTE = (
571
+ "Bins {w:g} wide on values {x:g} apart don't all hold the same number of "
572
+ "values. A width that's a multiple of {x:g} does."
573
+ )
509
574
  #: Why a special slot is not drawn — the notes `bin_edges` adds.
510
575
  EXACT_TEMPORAL_NOTE = "Single-value bins apply to numbers, not dates; they are ignored here."
511
576
  NAN_TEMPORAL_NOTE = "Missing times are not drawn as a bar on a date axis."
@@ -547,12 +612,25 @@ def bin_edges(values: Any, options: HistogramOptions, *, temporal: bool = False)
547
612
  if options.stat is HistStat.DENSITY and (exact or (show_nan and n_nan)):
548
613
  notes.append(DENSITY_SPECIAL_NOTE)
549
614
  try:
550
- edges = _edges_function()(regular, str(mode), count, width, lo, hi, MAX_BINS)
615
+ edges = _edges_function()(regular, str(mode), count, width, lo, hi, MAX_BINS, not temporal)
551
616
  except ValueError as exc:
552
617
  raise BinError(f"{exc}. Use a wider bin, or fewer bins.") from exc
553
618
  if mode is BinMode.AUTO and len(edges) - 1 == MAX_BINS:
554
619
  notes.append(f"Automatic bins capped at {MAX_BINS}.")
555
620
  widths = np.diff(edges)
621
+ step = 0.0 if temporal else _source_function("_scistack_grid")(regular)
622
+ if step:
623
+ notes.append(GRID_NOTE.format(x=step))
624
+ if widths.size and abs(widths[0] / step - round(widths[0] / step)) > 1e-6:
625
+ notes.append(OFF_GRID_NOTE.format(w=float(widths[0]), x=step))
626
+ distinct = np.unique(regular[np.isfinite(regular)])
627
+ gap = float(np.diff(distinct).min()) if distinct.size > 1 else step
628
+ Log.info(
629
+ "histogram bins: grid x=%g, m=%d, %d distinct value(s)",
630
+ step, round(gap / step), distinct.size, layer=LAYER,
631
+ )
632
+ elif not temporal:
633
+ Log.info("histogram bins: no grid (continuous)", layer=LAYER)
556
634
  same = widths.size and np.allclose(widths, widths[0], rtol=1e-9, atol=0.0)
557
635
  result = BinEdges(
558
636
  edges=tuple(float(e) for e in edges),
@@ -560,7 +638,7 @@ def bin_edges(values: Any, options: HistogramOptions, *, temporal: bool = False)
560
638
  width=float(widths[0]) if same else None,
561
639
  n_values=int(regular.size),
562
640
  notes=tuple(notes),
563
- call=(str(mode), count, width, lo, hi, MAX_BINS),
641
+ call=(str(mode), count, width, lo, hi, MAX_BINS, not temporal),
564
642
  exact=exact,
565
643
  nan=bool(show_nan and n_nan),
566
644
  n_nan=n_nan,
File without changes
File without changes