scistackplot 0.2.5__tar.gz → 0.3.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 (66) hide show
  1. {scistackplot-0.2.5 → scistackplot-0.3.0}/PKG-INFO +3 -3
  2. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/__init__.py +0 -6
  3. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/codegen.py +0 -41
  4. scistackplot-0.2.5/src/scistackplot/reduce/rows.py +0 -185
  5. {scistackplot-0.2.5 → scistackplot-0.3.0}/.gitignore +0 -0
  6. {scistackplot-0.2.5 → scistackplot-0.3.0}/README.md +0 -0
  7. {scistackplot-0.2.5 → scistackplot-0.3.0}/pyproject.toml +0 -0
  8. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/__init__.py +0 -0
  9. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/custom.py +0 -0
  10. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/figure_file.py +0 -0
  11. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/plot_data.py +0 -0
  12. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/export/reduction_code.py +0 -0
  13. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/__init__.py +0 -0
  14. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/capability.py +0 -0
  15. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/design.py +0 -0
  16. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/presets.py +0 -0
  17. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/restore.py +0 -0
  18. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/role_labels.py +0 -0
  19. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/roles.py +0 -0
  20. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/shape.py +0 -0
  21. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/spec.py +0 -0
  22. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/model/table.py +0 -0
  23. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/__init__.py +0 -0
  24. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/bins.py +0 -0
  25. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/categorical.py +0 -0
  26. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/cell.py +0 -0
  27. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/chain.py +0 -0
  28. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/compare.py +0 -0
  29. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/diffbars.py +0 -0
  30. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/fits.py +0 -0
  31. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/groups.py +0 -0
  32. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/kde.py +0 -0
  33. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/numeric.py +0 -0
  34. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/omissions.py +0 -0
  35. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/panels.py +0 -0
  36. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/reducer.py +0 -0
  37. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/reduction.py +0 -0
  38. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/resolve.py +0 -0
  39. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/resolved.py +0 -0
  40. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/series_stats.py +0 -0
  41. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/spaghetti.py +0 -0
  42. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/spread.py +0 -0
  43. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/stacking.py +0 -0
  44. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/temporal.py +0 -0
  45. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/variants.py +0 -0
  46. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/weights.py +0 -0
  47. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/reduce/ylimits.py +0 -0
  48. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/render/__init__.py +0 -0
  49. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/render/base.py +0 -0
  50. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/render/mpl.py +0 -0
  51. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/render/plotly_.py +0 -0
  52. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/sources/__init__.py +0 -0
  53. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/sources/base.py +0 -0
  54. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/sources/csv.py +0 -0
  55. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/sources/dedup.py +0 -0
  56. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/sources/frame.py +0 -0
  57. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/__init__.py +0 -0
  58. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/aliases.py +0 -0
  59. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/autosize.py +0 -0
  60. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/colors.py +0 -0
  61. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/figsize.py +0 -0
  62. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/framesize.py +0 -0
  63. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/paper.py +0 -0
  64. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/textsize.py +0 -0
  65. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/ticklabels.py +0 -0
  66. {scistackplot-0.2.5 → scistackplot-0.3.0}/src/scistackplot/text/xaxis.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scistackplot
3
- Version: 0.2.5
3
+ Version: 0.3.0
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.2.5
24
- Requires-Dist: scistacklog==0.2.5
23
+ Requires-Dist: scicanonicalhash==0.3.0
24
+ Requires-Dist: scistacklog==0.3.0
25
25
  Provides-Extra: dev
26
26
  Requires-Dist: matplotlib>=3.6; extra == 'dev'
27
27
  Requires-Dist: plotly>=5.0; extra == 'dev'
@@ -120,7 +120,6 @@ from .export.custom import (
120
120
  )
121
121
  from .reduce.diffbars import DifferenceBar, bars_for_panel, slot_endpoints
122
122
  from .reduce.panels import PanelOverride, override_for
123
- from .reduce.rows import ROW_FACTOR, element_values, explode_row_lists, row_factor, row_origin
124
123
  from .model.shape import Shape, classify_column, classify_value, is_plottable
125
124
  from .sources import BaseSource, CsvSource, DataFrameSource, DataSource, UnknownMeasureError
126
125
  from .model.spec import (
@@ -358,11 +357,6 @@ __all__ = [
358
357
  "FactorInfo",
359
358
  "MISSING_LEVEL",
360
359
  "MeasureInfo",
361
- "ROW_FACTOR",
362
- "element_values",
363
- "explode_row_lists",
364
- "row_factor",
365
- "row_origin",
366
360
  "Shape",
367
361
  "classify_value",
368
362
  "classify_column",
@@ -50,7 +50,6 @@ from ..reduce.resolve import (
50
50
  )
51
51
  from ..reduce.resolved import DASH_CYCLE
52
52
  from ..reduce.reduction import LocationMask, ReductionPlan, ValueFilter, filter_steps
53
- from ..reduce.rows import row_factor
54
53
  from ..model.roles import (
55
54
  collapse_steps,
56
55
  complete_roles,
@@ -593,44 +592,6 @@ def _factor_level_lines(table, factor: str) -> list[str]:
593
592
  return [f"df[{factor!r}] = df[{factor!r}].fillna({MISSING_LEVEL!r}).astype(str)"]
594
593
 
595
594
 
596
- def _row_split_lines(spec, table) -> list[str]:
597
- """The ``Row`` split of combined rows, mirrored for the endpoint.
598
-
599
- The interactive path splits row-list cells in ``ScidbSource`` through
600
- ``rows.explode_row_lists``; the endpoint receives them from scidb as a
601
- Python list (several rows) or the plain value (one row,
602
- ``sciduckdb.unwrap_row_list``), so a list is the only cell to split.
603
- Which fields, and the factor's name, come from the Row factor's origin
604
- (``rows.row_factor``) — the resolved result, not re-derived."""
605
- factor = row_factor(table)
606
- if factor is None:
607
- return []
608
- origin = factor.origin or {}
609
- fields = list(origin.get("fields") or [])
610
- field_factor = origin.get("field_factor")
611
- y, row = spec.y_measure, factor.name
612
- split = (
613
- f"df[{field_factor!r}].isin(_row_lists)"
614
- if field_factor
615
- else "[True] * len(df)"
616
- )
617
- return [
618
- f"# {row}: one row per source row of the combined (\"combine rows\") "
619
- f"field(s), numbered 1, 2, … in source order",
620
- f"_row_lists = {fields!r}",
621
- f"_cells = [list(_v) if _s and isinstance(_v, (list, tuple)) else [_v] "
622
- f"for _v, _s in zip(df[{y!r}], {split})]",
623
- f"df[{y!r}] = _cells",
624
- f"df[{row!r}] = [[str(_i) for _i in range(1, len(_c) + 1)] for _c in _cells]",
625
- f"df = df.explode([{y!r}, {row!r}], ignore_index=True)",
626
- "try:",
627
- f" df[{y!r}] = pd.to_numeric(df[{y!r}]).astype(\"float64\")",
628
- "except (TypeError, ValueError):",
629
- " pass # not all numbers: left as they are, as the preview leaves them",
630
- "",
631
- ]
632
-
633
-
634
595
  def _preamble(spec, table, roles, shape, categorical_lines: list[str] = ()) -> list[str]:
635
596
  """Melt, filters, 1-D explosion, aggregation — the order resolve() uses.
636
597
 
@@ -732,8 +693,6 @@ def _preamble(spec, table, roles, shape, categorical_lines: list[str] = ()) -> l
732
693
  ]
733
694
  )
734
695
 
735
- lines.extend(_row_split_lines(spec, table))
736
-
737
696
  # A datetime measure becomes wall-clock ms in the plot's time zone mode,
738
697
  # after the melt (which makes the column) and before anything filters or
739
698
  # averages it — where `reduce` applies `temporal.apply_temporal`.
@@ -1,185 +0,0 @@
1
- """The ``Row`` factor — one owner for splitting "combine rows" cells into rows.
2
-
3
- A variable saved with ``on_duplicate="combine"`` holds, per record, one value
4
- PER SOURCE ROW in each ``row_list`` column (``sciduckdb.row_lists``):
5
- ``FIN = [6573…, 6597…]`` for a subject who appeared twice in the input. Those
6
- elements are observations (one hospital stay each), not samples along an
7
- axis, so drawing them as a 1-D series put them against an "index" x axis and
8
- let the scalar kinds only average them (2026-10-30,
9
- ``.claude/plan-row-list-plots.md``).
10
-
11
- :func:`explode_row_lists` turns each element into its own row and numbers it
12
- with a synthetic factor, :data:`ROW_FACTOR`, 1-based in source-row order. The
13
- combine rule keeps every list column aligned (position i is "source row i"),
14
- so the same Row number names the same source row in every field.
15
-
16
- **View only.** The Row factor exists in a plot's long table and never in the
17
- database: a save-side Row was considered and rejected by the user (it would
18
- turn accidental duplicates into silent replicates).
19
-
20
- Who calls this:
21
-
22
- * ``scistackplotdb.ScidbSource`` on the interactive path, after the struct
23
- melt;
24
- * ``codegen`` emits the same reshape inline (a generated endpoint imports
25
- only numpy/pandas/seaborn), driven by :func:`row_factor` — the parity test
26
- in ``scistackplotdb/tests/test_fanout_parity.py`` holds the two together
27
- (docs/claude/synthetic-factors.md invariant 4).
28
- """
29
-
30
- from __future__ import annotations
31
-
32
- from dataclasses import dataclass, field
33
- from typing import TYPE_CHECKING, Any
34
-
35
- import numpy as np
36
- import pandas as pd
37
-
38
- if TYPE_CHECKING:
39
- from ..model.table import FactorInfo, LongTable
40
-
41
- #: The factor's name. A schema key of the same name is never shadowed:
42
- #: :func:`explode_row_lists` appends ``_`` until the name is free.
43
- ROW_FACTOR = "Row"
44
-
45
- #: ``FactorInfo.origin["kind"]`` of the Row factor. Consumers of ``origin``
46
- #: act on ``"code"``/``"param"`` only, so this kind is inert to them.
47
- ROW_LIST_ORIGIN = "row_list"
48
-
49
-
50
- @dataclass
51
- class RowSplit:
52
- """What :func:`explode_row_lists` did, for the log and the table."""
53
-
54
- frame: pd.DataFrame
55
- #: The Row column's name, or None when no cell held more than one element
56
- #: — a one-level factor is a constant, not a factor (synthetic-factors.md
57
- #: invariant 6), so the column is dropped, but the cells are still
58
- #: unwrapped to scalars.
59
- row_factor: str | None
60
- #: The row-list fields that were split (all of them for a one-column
61
- #: variable, whose list is ``[measure]``).
62
- fields: list[str] = field(default_factory=list)
63
- cells: int = 0
64
- rows_in: int = 0
65
- rows_out: int = 0
66
- max_rows: int = 0
67
-
68
-
69
- def is_list_cell(value: Any) -> bool:
70
- """A cell holding a row list's elements: an array or a list/tuple. A
71
- string is iterable but is ONE value."""
72
- return isinstance(value, (list, tuple, np.ndarray)) and not isinstance(value, str)
73
-
74
-
75
- def _elements(value: Any) -> list:
76
- if is_list_cell(value):
77
- items = list(np.asarray(value, dtype=object).ravel())
78
- # A row list never stores an empty list (the combine makes at least
79
- # one element), but if one arrives it stays one missing row rather
80
- # than vanishing — never drop data silently.
81
- return items or [None]
82
- return [value]
83
-
84
-
85
- def element_values(series: pd.Series) -> pd.Series:
86
- """Every element of a row-list column as one flat Series — what a
87
- caller classifies to decide whether the column is plottable (a VARCHAR
88
- row list is text, not a 1-D series)."""
89
- return pd.Series(
90
- [item for value in series for item in _elements(value)], dtype=object
91
- )
92
-
93
-
94
- def _as_numbers(values: pd.Series) -> pd.Series:
95
- """float64 when every non-missing element is a number, else unchanged.
96
-
97
- Exploding goes through object dtype; a numeric field must come back as
98
- one float buffer or it would classify by its first cell and reduce
99
- slowly. Anything else (a datetime, text) is left for the caller's own
100
- classification."""
101
- present = values.dropna()
102
- if len(present) and all(
103
- isinstance(v, (int, float, np.integer, np.floating))
104
- and not isinstance(v, (bool, np.bool_))
105
- for v in present
106
- ):
107
- return pd.to_numeric(values).astype("float64")
108
- return values
109
-
110
-
111
- def explode_row_lists(
112
- frame: pd.DataFrame,
113
- measure: str,
114
- row_list_fields: list[str],
115
- *,
116
- field_factor: str | None = None,
117
- ) -> RowSplit:
118
- """One row per element of every row-list cell of ``measure``.
119
-
120
- ``frame`` is long: one ``measure`` column, plus ``field_factor`` (the
121
- struct's ``ColName``) when the variable was melted. Rows whose field is
122
- in ``row_list_fields`` are split; rows of other fields, and one-element
123
- cells, become one row with Row 1. Without a ``field_factor`` the measure
124
- column itself is the row list (``row_list_fields == [measure]``).
125
-
126
- Pure: the input frame is not modified.
127
- """
128
- if field_factor is not None:
129
- split = frame[field_factor].isin(row_list_fields).to_numpy()
130
- else:
131
- split = np.full(len(frame), measure in row_list_fields)
132
-
133
- cells = [
134
- _elements(value) if flag else [value]
135
- for value, flag in zip(frame[measure].to_numpy(dtype=object), split)
136
- ]
137
- counts = [len(c) for c in cells]
138
- max_rows = max(counts, default=0)
139
-
140
- name = ROW_FACTOR
141
- while name in frame.columns: # never shadow a schema key
142
- name += "_"
143
-
144
- out = frame.copy()
145
- out[measure] = pd.Series(cells, index=frame.index, dtype=object)
146
- out[name] = pd.Series(
147
- [[str(i) for i in range(1, n + 1)] for n in counts],
148
- index=frame.index,
149
- dtype=object,
150
- )
151
- out = out.explode([measure, name], ignore_index=True)
152
- out[measure] = _as_numbers(out[measure])
153
-
154
- row_factor: str | None = name
155
- if max_rows < 2:
156
- out = out.drop(columns=[name])
157
- row_factor = None
158
- return RowSplit(
159
- frame=out,
160
- row_factor=row_factor,
161
- fields=list(row_list_fields),
162
- cells=int(split.sum()),
163
- rows_in=len(frame),
164
- rows_out=len(out),
165
- max_rows=max_rows,
166
- )
167
-
168
-
169
- def row_origin(fields: list[str], field_factor: str | None) -> dict:
170
- """``FactorInfo.origin`` of the Row factor: which fields were split, and
171
- by which field factor — what codegen needs to emit the same reshape."""
172
- return {
173
- "kind": ROW_LIST_ORIGIN,
174
- "fields": list(fields),
175
- "field_factor": field_factor,
176
- }
177
-
178
-
179
- def row_factor(table: "LongTable") -> "FactorInfo | None":
180
- """The table's Row factor, or None. The one lookup; nothing matches the
181
- name."""
182
- for factor in table.factors:
183
- if (factor.origin or {}).get("kind") == ROW_LIST_ORIGIN:
184
- return factor
185
- return None
File without changes
File without changes