scistackplotdb 0.3.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scistackplotdb
3
- Version: 0.3.8
3
+ Version: 0.4.1
4
4
  Summary: scidb-backed plotting: load variables into long tables and plot them with scistackplot
5
5
  Author: SciStack Contributors
6
6
  License-Expression: MIT
@@ -17,11 +17,11 @@ Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Topic :: Scientific/Engineering :: Visualization
18
18
  Classifier: Typing :: Typed
19
19
  Requires-Python: >=3.10
20
- Requires-Dist: sciduckdb==0.3.8
21
- Requires-Dist: scifor==0.3.8
22
- Requires-Dist: scistack-db==0.3.8
23
- Requires-Dist: scistacklog==0.3.8
24
- Requires-Dist: scistackplot==0.3.8
20
+ Requires-Dist: sciduckdb==0.4.1
21
+ Requires-Dist: scifor==0.4.1
22
+ Requires-Dist: scistack-db==0.4.1
23
+ Requires-Dist: scistacklog==0.4.1
24
+ Requires-Dist: scistackplot==0.4.1
25
25
  Provides-Extra: dev
26
26
  Requires-Dist: matplotlib>=3.6; extra == 'dev'
27
27
  Requires-Dist: pytest-cov>=4.0; extra == 'dev'
@@ -2,15 +2,17 @@
2
2
  Schema-depth joins.
3
3
 
4
4
  Two variables can share a plot only if their schema levels can be joined.
5
- Because the dataset schema is an ordered, contiguous hierarchy (see
6
- ``docs/claude/schema-hierarchy-contiguity.md``), a variable's levels are always
7
- a *prefix* of the schema key list — so the join rule is simple and total:
8
-
9
- * identical levels → a straight merge on all of them;
10
- * one a prefix of the other → **broadcast**: the shallower variable's value is
11
- repeated across every deeper row beneath it (subject-level Mass against
12
- trial-level Speed);
13
- * otherwise → refuse, and say why.
5
+ A variable lives at a SET of schema keys (the keys its records name). The tree
6
+ of keys is only a default (docs/claude/branched-schema-keys.md); what can join
7
+ what is decided by comparing those sets, so a person-level variable can attach
8
+ to a cross-branch Purchase even though its keys are not a prefix of the key
9
+ list. On a linear schema the sets are prefixes, as before:
10
+
11
+ * identical key sets → a straight merge on all of them;
12
+ * one a subset of the other → **broadcast**: the smaller variable's value is
13
+ repeated across every row of the larger that shares its keys (subject-level
14
+ Mass against trial-level Speed; a person-level age against a Purchase);
15
+ * otherwise → refuse, and say why (no record names both).
14
16
 
15
17
  Answering this question is also what lets the GUI populate its measure list
16
18
  honestly instead of offering combinations that cannot be built.
@@ -37,10 +39,10 @@ _RIGHT_LATEST = "__latest_right"
37
39
 
38
40
 
39
41
  def join_kind(levels_a: list[str], levels_b: list[str]) -> JoinKind:
40
- if levels_a == levels_b:
42
+ keys_a, keys_b = set(levels_a), set(levels_b)
43
+ if keys_a == keys_b:
41
44
  return "identical"
42
- shallow, deep = (levels_a, levels_b) if len(levels_a) < len(levels_b) else (levels_b, levels_a)
43
- if deep[: len(shallow)] == shallow:
45
+ if keys_a < keys_b or keys_b < keys_a:
44
46
  return "broadcast"
45
47
  return "incompatible"
46
48
 
@@ -65,11 +67,13 @@ def join_frames(
65
67
  """
66
68
  kind = join_kind(left.levels, right.levels)
67
69
  if kind == "incompatible":
70
+ only_left = [k for k in left.levels if k not in right.levels]
71
+ only_right = [k for k in right.levels if k not in left.levels]
68
72
  raise ValueError(
69
- f"{left.name} (levels {left.levels}) and {right.name} "
70
- f"(levels {right.levels}) cannot share a plot: neither variable's "
71
- f"schema levels are a prefix of the other's, so there is no "
72
- f"unambiguous way to line their records up."
73
+ f"{left.name} (keys {left.levels}) and {right.name} (keys {right.levels}) "
74
+ f"cannot share a plot: no record names both {only_left} and {only_right}, "
75
+ f"so there is no row to line their values up on. A variable saved at "
76
+ f"both is what would link them."
73
77
  )
74
78
 
75
79
  shallow_levels = left.levels if len(left.levels) <= len(right.levels) else right.levels
@@ -936,18 +936,18 @@ class ScidbSource(BaseSource):
936
936
  f"{factor!r}, which this table already has. Rename the "
937
937
  f"column in the source data, or group by something else."
938
938
  )
939
- if len(variable.levels) > len(levels) or levels[
940
- : len(variable.levels)
941
- ] != list(variable.levels):
942
- # Deeper than the data, or a different branch of the schema:
943
- # merging would multiply rows or match nothing, and either way
944
- # the figure would be quietly wrong about how many observations
945
- # it holds.
939
+ if not set(variable.levels) <= set(levels):
940
+ # It names a key the data's rows do not carry (deeper than the
941
+ # data, or on a branch the rows never visit): merging would
942
+ # multiply rows or match nothing, and either way the figure
943
+ # would be quietly wrong about how many observations it holds.
944
+ extra = [k for k in variable.levels if k not in levels]
946
945
  raise ValueError(
947
- f"{group.label!r} sits at {variable.levels}, which is not a "
948
- f"prefix of {levels} — there is no unambiguous way to "
949
- f"attach one of its values to each row. Group by a variable "
950
- f"recorded at or above the level of the data."
946
+ f"{group.label!r} sits at {variable.levels}, but the data's rows "
947
+ f"({levels}) never name {extra}, so there is no unambiguous way "
948
+ f"to attach one of its values to each row. Group by a variable "
949
+ f"recorded at keys the data's rows also name (no record of the "
950
+ f"measure names both; a variable saved at both would link them)."
951
951
  )
952
952
  on, right = self._keyed_values(variable, group)
953
953
  frame = frame.merge(right, on=on, how="left")
@@ -971,7 +971,10 @@ class ScidbSource(BaseSource):
971
971
  # Depth is the grouping variable's own schema depth: a subject-level
972
972
  # sheet pins one value per subject, so it sits at the same level as
973
973
  # `subject` and OUTSIDE `session` when both share the x axis.
974
- attached[factor] = len(on)
974
+ # Its depth is its place in the flat key order: after the last key
975
+ # that pins it. A prefix gives len(on), as before; a branch (a
976
+ # person-level label on a cross-branch table) sits after `person`.
977
+ attached[factor] = max((levels.index(k) + 1 for k in on), default=0)
975
978
  n_levels = frame[factor].nunique(dropna=True)
976
979
  Log.info(
977
980
  "attached %r as factor %r on %s (%d level(s))",
File without changes