scimatlab 0.3.8__tar.gz → 0.4.2__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 (101) hide show
  1. {scimatlab-0.3.8 → scimatlab-0.4.2}/PKG-INFO +4 -4
  2. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/crossing.py +15 -0
  3. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/entry.py +73 -13
  4. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/wire.py +11 -2
  5. scimatlab-0.4.2/src/scimatlab/matlab/+scidb/+internal/datetime_key_to_python.m +18 -0
  6. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/metadata_to_pydict.m +1 -2
  7. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/metadata_to_pykwargs.m +4 -0
  8. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/BaseVariable.m +1 -0
  9. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Merge.m +1 -1
  10. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Pipeline.m +1 -1
  11. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Variant.m +29 -23
  12. scimatlab-0.4.2/src/scimatlab/matlab/+scidb/all_of.m +38 -0
  13. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/configure_database.m +26 -7
  14. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/for_each.m +10 -1
  15. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/for_each.m +5 -1
  16. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/merge_tables.m +9 -4
  17. {scimatlab-0.3.8 → scimatlab-0.4.2}/.gitignore +0 -0
  18. {scimatlab-0.3.8 → scimatlab-0.4.2}/pyproject.toml +0 -0
  19. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/__init__.py +0 -0
  20. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/__init__.py +0 -0
  21. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/convert.py +0 -0
  22. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/bridge/pipeline.py +0 -0
  23. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/build_csv_kwargs.m +0 -0
  24. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/cartesian_product.m +0 -0
  25. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/codec.m +0 -0
  26. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/datetime_from_python.m +0 -0
  27. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/datetime_to_python.m +0 -0
  28. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/decode_codec_input.m +0 -0
  29. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/duration_from_python.m +0 -0
  30. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/encode_codec_output.m +0 -0
  31. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/ensure_registered.m +0 -0
  32. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/from_python.m +0 -0
  33. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/function_name.m +0 -0
  34. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/hash_function.m +0 -0
  35. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/iteration_tally.m +0 -0
  36. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/load_pathinput_checked.m +0 -0
  37. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/metadata_number.m +0 -0
  38. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/normalize_cell_column.m +0 -0
  39. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/number_to_python.m +0 -0
  40. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/pipeline_registry.m +0 -0
  41. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/pydict_to_struct.m +0 -0
  42. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/pylist_to_cell.m +0 -0
  43. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/reject_csv_spec_args.m +0 -0
  44. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/resolve_var_names.m +0 -0
  45. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/split_csv_args.m +0 -0
  46. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/split_version_arg.m +0 -0
  47. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/to_python.m +0 -0
  48. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/to_python_input.m +0 -0
  49. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/try_flatten_cell_column.m +0 -0
  50. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/try_stack_numeric.m +0 -0
  51. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/unwrap_input.m +0 -0
  52. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/validate_csv_filename.m +0 -0
  53. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/+internal/whole_metadata_columns.m +0 -0
  54. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/AcrossVariants.m +0 -0
  55. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/ColName.m +0 -0
  56. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Filter.m +0 -0
  57. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Fixed.m +0 -0
  58. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Log.m +0 -0
  59. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/Parameter.m +0 -0
  60. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/PathInput.m +0 -0
  61. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/SchemaKey.m +0 -0
  62. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/add_to_var_group.m +0 -0
  63. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/close_database.m +0 -0
  64. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/entities.m +0 -0
  65. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/exclude_schema.m +0 -0
  66. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/get_database.m +0 -0
  67. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/get_var_group.m +0 -0
  68. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/include_schema.m +0 -0
  69. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/isabsolute.m +0 -0
  70. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/list_exclusions.m +0 -0
  71. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/list_var_groups.m +0 -0
  72. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/raw_sql.m +0 -0
  73. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/register_variable.m +0 -0
  74. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/remove_from_var_group.m +0 -0
  75. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/run_marker.m +0 -0
  76. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scidb/schema_key.m +0 -0
  77. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/Col.m +0 -0
  78. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/ColFilter.m +0 -0
  79. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/ColName.m +0 -0
  80. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/ColumnSelection.m +0 -0
  81. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/CompoundFilter.m +0 -0
  82. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/EachOf.m +0 -0
  83. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/Fixed.m +0 -0
  84. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/Log.m +0 -0
  85. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/Merge.m +0 -0
  86. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/NotFilter.m +0 -0
  87. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/PathInput.m +0 -0
  88. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/PathOutput.m +0 -0
  89. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/categorize_metadata.m +0 -0
  90. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/classify_blame.m +0 -0
  91. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/failure_from_mexception.m +0 -0
  92. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/frame_origin.m +0 -0
  93. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/get_schema.m +0 -0
  94. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/has_no_data.m +0 -0
  95. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/key_types_to_py.m +0 -0
  96. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/option_pairs.m +0 -0
  97. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/output_column_name.m +0 -0
  98. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/require_alternatives.m +0 -0
  99. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/matlab/+scifor/set_schema.m +0 -0
  100. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/source_hash.py +0 -0
  101. {scimatlab-0.3.8 → scimatlab-0.4.2}/src/scimatlab/stubs.py +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scimatlab
3
- Version: 0.3.8
3
+ Version: 0.4.2
4
4
  Summary: MATLAB bridge for the sci* scientific data processing framework
5
5
  License: MIT
6
6
  Requires-Python: >=3.10
7
- Requires-Dist: scicanonicalhash==0.3.8
8
- Requires-Dist: scifor==0.3.8
9
- Requires-Dist: scistack-db==0.3.8
7
+ Requires-Dist: scicanonicalhash==0.4.2
8
+ Requires-Dist: scifor==0.4.2
9
+ Requires-Dist: scistack-db==0.4.2
10
10
  Provides-Extra: dev
11
11
  Requires-Dist: pytest>=7.0.0; extra == 'dev'
@@ -158,10 +158,18 @@ def datetime_keys_as_text(metadata: dict) -> dict:
158
158
  would then re-save at a different address.
159
159
  """
160
160
  from scicanonicalhash import datetime_key_text
161
+ from scidb.model.log import Log
161
162
 
162
163
  out = {}
163
164
  for key, value in dict(metadata).items():
164
165
  text = datetime_key_text(value)
166
+ if text is not None:
167
+ # Which zone object arrived decides whether "[Zone]" is spelled.
168
+ Log.debug(
169
+ f"[bridge] datetime key {key!r}: {type(value).__name__} "
170
+ f"tzinfo={getattr(value, 'tzinfo', None)!r} -> {text!r}",
171
+ layer="matlab",
172
+ )
165
173
  out[key] = value if text is None else text
166
174
  return out
167
175
 
@@ -176,4 +184,11 @@ def datetime_key_text_of(value: Any) -> str:
176
184
  text = datetime_key_text(value)
177
185
  if text is None:
178
186
  raise ValueError(f"a datetime schema key must have a value, got {value!r}")
187
+ from scidb.model.log import Log
188
+
189
+ Log.debug(
190
+ f"[bridge] datetime key from MATLAB: {type(value).__name__} "
191
+ f"tzinfo={getattr(value, 'tzinfo', None)!r} -> {text!r}",
192
+ layer="matlab",
193
+ )
179
194
  return text
@@ -8,7 +8,7 @@ batch cache) is module state here, keyed by an integer handle.
8
8
  """
9
9
 
10
10
  from .convert import is_datetime_value, split_flat_to_lists
11
- from .crossing import matlab_entry
11
+ from .crossing import datetime_keys_as_text, matlab_entry
12
12
  from .wire import (
13
13
  _locations_from_matlab,
14
14
  _make_matlab_fn_sentinel,
@@ -579,6 +579,11 @@ def for_each_prepare(
579
579
  "rid_rename_map": rid_rename_map,
580
580
  "where": where,
581
581
  "endpoint_kind": endpoint_kind,
582
+ # The run's record (scidb.provenance.run_summary): for_each_save feeds
583
+ # it the MATLAB loop's events and writes it. `loop_mark` is the newest
584
+ # scifor plan token before this run's loop is planned.
585
+ "run_recorder": _new_run_recorder(state.fn_name, locations, where_arg, skip_computed, save),
586
+ "loop_mark": _loop_mark(),
582
587
  }
583
588
 
584
589
  from scidb.model.log import Log as _BridgeLog
@@ -752,6 +757,39 @@ def for_each_describe_loaded_input(val):
752
757
  return {"kind": "raw", "value": val}
753
758
 
754
759
 
760
+ def _new_run_recorder(fn_name, locations, where, skip_computed, save):
761
+ from scidb.run import external_loop
762
+
763
+ return external_loop.RunRecorder(
764
+ str(fn_name),
765
+ locations=locations,
766
+ where=where,
767
+ # on_error is MATLAB's own option; it never reaches prepare.
768
+ on_error=None,
769
+ skip_computed=bool(skip_computed),
770
+ save=bool(save),
771
+ language="matlab",
772
+ )
773
+
774
+
775
+ def _loop_mark() -> int:
776
+ from scifor import matlab_loop
777
+
778
+ return matlab_loop.last_token()
779
+
780
+
781
+ def _observe_matlab_loop(recorder, loop_mark: int) -> bool:
782
+ """Feed *recorder* the events of the MATLAB loop that ran since
783
+ *loop_mark*. False when no loop reached its summary (nothing ran, or the
784
+ loop raised): there is then no run to record."""
785
+ from scifor import matlab_loop
786
+
787
+ events = matlab_loop.take_run_events_after(int(loop_mark))
788
+ for info in events:
789
+ recorder.observe(info)
790
+ return bool(events)
791
+
792
+
755
793
  @matlab_entry
756
794
  def for_each_save(
757
795
  handle,
@@ -887,17 +925,37 @@ def for_each_save(
887
925
  f"columns={list(result_tbl.columns)}"
888
926
  )
889
927
 
890
- result_tbl = external_loop.save_resolved(
891
- state=state,
892
- result_tbl=result_tbl,
893
- # state.inputs, not the cached spec: prepare folded any constant-fed
894
- # glue chain into the values (the version keys keep the RAW value and
895
- # the glue's identity). Same rule as scidb.for_each's own save call.
896
- inputs=state.inputs if state.inputs is not None else inputs,
897
- outputs=outputs,
898
- save=bool(save),
899
- db=db if db is not None and not isinstance(db, type(None)) else None,
900
- )
928
+ # The run's record: only when the MATLAB loop reached its summary (a
929
+ # cleanup call after nothing ran, or after the loop raised, records
930
+ # nothing). Written in a finally, after the save, like the Python path.
931
+ recorder = cached.get("run_recorder")
932
+ loop_ran = recorder is not None and _observe_matlab_loop(recorder, cached.get("loop_mark", 0))
933
+ if loop_ran:
934
+ state.run_recorder = recorder
935
+ save_db = db if db is not None and not isinstance(db, type(None)) else None
936
+ try:
937
+ result_tbl = external_loop.save_resolved(
938
+ state=state,
939
+ result_tbl=result_tbl,
940
+ # state.inputs, not the cached spec: prepare folded any constant-fed
941
+ # glue chain into the values (the version keys keep the RAW value and
942
+ # the glue's identity). Same rule as scidb.for_each's own save call.
943
+ inputs=state.inputs if state.inputs is not None else inputs,
944
+ outputs=outputs,
945
+ save=bool(save),
946
+ db=save_db,
947
+ )
948
+ finally:
949
+ if loop_ran:
950
+ from scidb.store.database import database_or_none as _database_or_none
951
+
952
+ recorder.finish(
953
+ save_db if save_db is not None else _database_or_none(),
954
+ output_types=state.output_types,
955
+ up_to_date=state.skip_computed_count,
956
+ )
957
+ else:
958
+ _Log.debug(f"[bridge] for_each_save: handle={handle}: no finished loop, run not recorded")
901
959
 
902
960
  if introspect and result_tbl is not None and not result_tbl.empty:
903
961
  import json as _json
@@ -1419,7 +1477,9 @@ def wrap_batch_bridge(py_vars_list):
1419
1477
  record_ids.append(v.record_id or "")
1420
1478
  content_hashes.append(v.content_hash or "")
1421
1479
  meta = v.metadata
1422
- meta_dicts.append(dict(meta) if meta is not None else {})
1480
+ # A date key reaches MATLAB as its exact schema-key text, never a
1481
+ # Timestamp (not JSON, and a MATLAB datetime would lose the named zone).
1482
+ meta_dicts.append(datetime_keys_as_text(meta) if meta is not None else {})
1423
1483
  branch_params_list.append(json.dumps(v.branch_params or {}))
1424
1484
  data.append(v.data)
1425
1485
 
@@ -180,9 +180,18 @@ def _reconstruct_input_for_keys(spec):
180
180
  if kind == "variant":
181
181
  from scidb.model.variant import Variant
182
182
 
183
+ from scidb.model.log import Log
184
+
185
+ # MATLAB ships every name-value pair as given (fn=, code_version=,
186
+ # run_options= included) and keeps nesting; Variant owns their meaning.
183
187
  inner = _reconstruct_input_for_keys(spec["inner"])
184
- branch_params = dict(spec.get("branch_params", {}) or {})
185
- return Variant(inner, **branch_params)
188
+ pairs = dict(spec.get("branch_params", {}) or {})
189
+ variant = Variant(inner, **pairs)
190
+ Log.debug(
191
+ f"[bridge] Variant from MATLAB: pairs={pairs!r} -> pins={variant.branch_params!r}",
192
+ layer="matlab",
193
+ )
194
+ return variant
186
195
  if kind == "merge":
187
196
  from scifor import Merge
188
197
 
@@ -0,0 +1,18 @@
1
+ function text = datetime_key_to_python(dt)
2
+ %DATETIME_KEY_TO_PYTHON A scalar MATLAB datetime schema key as its key text.
3
+ %
4
+ % text = datetime_key_to_python(dt)
5
+ % returns the ONE spelling of a date/datetime key (Python owns it:
6
+ % scicanonicalhash.datetime_key_text), e.g.
7
+ % 2026-07-09T15:12:00-05:00[America/Chicago]
8
+ %
9
+ % Every converter of metadata name-value pairs (metadata_to_pydict for
10
+ % load, metadata_to_pykwargs for save, delete, versions...) calls this, so
11
+ % a key saved and a key loaded by the same datetime spell the same. A bare
12
+ % datetime handed to Python as a keyword would be converted by MATLAB
13
+ % itself, which turns a named zone into a fixed offset (R2024a) and the
14
+ % value would then be saved at a different address.
15
+
16
+ text = py.scimatlab.bridge.datetime_key_text_of( ...
17
+ scidb.internal.datetime_to_python(dt, 'scalar'));
18
+ end
@@ -34,8 +34,7 @@ function py_dict = metadata_to_pydict(varargin)
34
34
  py_dict{key} = py.str(val);
35
35
  elseif isdatetime(val) && isscalar(val)
36
36
  % The one spelling of a date key (Python owns it).
37
- py_dict{key} = py.scimatlab.bridge.datetime_key_text_of( ...
38
- scidb.internal.datetime_to_python(val, 'scalar'));
37
+ py_dict{key} = scidb.internal.datetime_key_to_python(val);
39
38
  elseif isstruct(val)
40
39
  % Structs may contain arrays that aren't JSON-serializable on
41
40
  % the Python side. Encode the whole struct as a JSON string so
@@ -28,6 +28,10 @@ function kwargs = metadata_to_pykwargs(varargin)
28
28
  elseif isnumeric(val) && isscalar(val)
29
29
  % Whole numbers → py.int (scidb.internal.number_to_python)
30
30
  val = scidb.internal.number_to_python(val);
31
+ elseif isdatetime(val) && isscalar(val)
32
+ % A date key crosses as its exact text, never as a raw datetime:
33
+ % MATLAB would convert that itself and drop a named zone.
34
+ val = scidb.internal.datetime_key_to_python(val);
31
35
  elseif isstruct(val)
32
36
  % Structs become JSON strings so they can be stored as
33
37
  % version keys (e.g. config structs).
@@ -532,6 +532,7 @@ classdef BaseVariable < dynamicprops
532
532
  % generator returned by DatabaseManager.load() in Python. A
533
533
  % specific record_id resolves to a single record (n==1); passing
534
534
  % version_id straight through lets scidb's load() dispatch on it.
535
+ where = scidb.all_of(where); % a cell means AND, as in for_each
535
536
  if isempty(where)
536
537
  bulk = py.scimatlab.bridge.load_and_extract( ...
537
538
  py_class, py_metadata, ...
@@ -168,7 +168,7 @@ function py_obj = constituent_to_py(spec)
168
168
  if isa(spec, 'scidb.Fixed')
169
169
  inner = constituent_to_py(spec.var_type);
170
170
  kv = struct_to_pykwargs(spec.fixed_metadata);
171
- py_obj = py.scidb.fixed.Fixed(inner, pyargs(kv{:}));
171
+ py_obj = py.scifor.Fixed(inner, pyargs(kv{:}));
172
172
 
173
173
  elseif isa(spec, 'scidb.Variant')
174
174
  inner = constituent_to_py(spec.var_type);
@@ -172,7 +172,7 @@ classdef Pipeline < handle
172
172
  function run_all(obj, varargin)
173
173
  %RUN_ALL Run own steps + their ancestors in dependency order.
174
174
  % Options: 'skip_computed' (default true).
175
- obj.drive('all', '', false, [], obj.opt_skip(varargin{:}));
175
+ obj.drive('all', '', false, obj.opt_skip(varargin{:}));
176
176
  end
177
177
 
178
178
  function run_until(obj, target, varargin)
@@ -23,10 +23,24 @@ classdef Variant
23
23
  % branch_params are namespaced per producing function (e.g. bandpass.low_hz);
24
24
  % a bare name (low_hz) is matched by suffix at load time.
25
25
  %
26
+ % Three names are options, not branch params, exactly as in Python:
27
+ %
28
+ % scidb.Variant(X, fn="bandpass", low_hz=20) % pins bandpass.low_hz
29
+ % scidb.Variant(X, code_version="v1") % or "latest"
30
+ % scidb.Variant(X, run_options="distribute=true")
31
+ %
32
+ % MATLAB stores every name-value pair as given, and Python's
33
+ % scidb.Variant (scidb/src/scidb/model/variant.py) decides what each one
34
+ % means: the bridge rebuilds Variant(inner, **pairs). A nested Variant is
35
+ % kept nested, not merged here, so Python's merge (and its fn= namespacing,
36
+ % which applies only to its own level) is the one rule. A conflicting
37
+ % value in a nested Variant raises when for_each runs.
38
+ %
26
39
  % Properties:
27
40
  % var_type - Variable instance (e.g. FilteredEMG()), a column
28
41
  % selection (FilteredEMG("col")), or a scidb.Fixed
29
- % branch_params - Struct of branch_param key/value pairs to pin
42
+ % branch_params - Struct of the pairs to pin (branch params, plus fn,
43
+ % code_version, run_options when given)
30
44
  %
31
45
  % Example:
32
46
  % % Run fn over only the low_hz=20 variant of FilteredEMG
@@ -36,7 +50,7 @@ classdef Variant
36
50
  % subject=[1 2]);
37
51
 
38
52
  properties (SetAccess = private)
39
- var_type % BaseVariable instance / column selection / scidb.Fixed
53
+ var_type % BaseVariable / column selection / scidb.Fixed / scidb.Variant
40
54
  branch_params struct % branch_param pins
41
55
  end
42
56
 
@@ -48,10 +62,11 @@ classdef Variant
48
62
  %
49
63
  % Arguments:
50
64
  % var_type - A BaseVariable instance, a column selection
51
- % (MyVar("col")), or a scidb.Fixed wrapper.
65
+ % (MyVar("col")), a scidb.Fixed or a scidb.Variant.
52
66
  %
53
67
  % Name-Value Arguments:
54
- % branch_param keys and their pinned values
68
+ % branch_param keys and their pinned values, plus the options
69
+ % fn, code_version and run_options (see the class help)
55
70
 
56
71
  if isa(var_type, 'scidb.Merge')
57
72
  error('scidb:Variant', ...
@@ -61,14 +76,22 @@ classdef Variant
61
76
  'constituent instead: Merge(Variant(A, low_hz=20), B).']);
62
77
  end
63
78
 
79
+ if isa(var_type, 'scifor.EachOf')
80
+ error('scidb:Variant', ...
81
+ ['Variant cannot wrap an EachOf. EachOf must stay the ', ...
82
+ 'outermost wrapper: EachOf(Variant(A, low_hz=20), ', ...
83
+ 'Variant(A, low_hz=50)).']);
84
+ end
85
+
64
86
  if mod(numel(varargin), 2) ~= 0
65
87
  error('scidb:Variant', ...
66
88
  'Variant branch_params must be name-value pairs.');
67
89
  end
68
90
  if isempty(varargin)
69
91
  error('scidb:Variant', ...
70
- ['Variant requires at least one branch_param to pin, ', ...
71
- 'e.g. scidb.Variant(FilteredEMG(), low_hz=20).']);
92
+ ['Variant requires at least one branch_param, ', ...
93
+ 'code_version or run_options to pin, e.g. ', ...
94
+ 'scidb.Variant(FilteredEMG(), low_hz=20).']);
72
95
  end
73
96
 
74
97
  s = struct();
@@ -76,23 +99,6 @@ classdef Variant
76
99
  s.(string(varargin{i})) = varargin{i+1};
77
100
  end
78
101
 
79
- % Nested Variant: merge the dicts; raise on conflicting key value.
80
- if isa(var_type, 'scidb.Variant')
81
- inner_bp = var_type.branch_params;
82
- inner_fields = fieldnames(inner_bp);
83
- for i = 1:numel(inner_fields)
84
- k = inner_fields{i};
85
- if isfield(s, k) && ~isequal(s.(k), inner_bp.(k))
86
- error('scidb:Variant', ...
87
- 'Conflicting branch_param "%s" in nested Variant.', k);
88
- end
89
- if ~isfield(s, k)
90
- s.(k) = inner_bp.(k);
91
- end
92
- end
93
- var_type = var_type.var_type;
94
- end
95
-
96
102
  obj.var_type = var_type;
97
103
  obj.branch_params = s;
98
104
  end
@@ -0,0 +1,38 @@
1
+ function result = all_of(filters)
2
+ %SCIDB.ALL_OF Combine filters with AND; a where= list means all of them.
3
+ %
4
+ % F = scidb.all_of({Age() > 80, Sex() == "M"})
5
+ %
6
+ % where={A, B} is one run that every filter must pass, the same as
7
+ % where=A & B. (Separate runs, one per filter, are where=scidb.EachOf(A, B).)
8
+ % A value that is not a cell is returned unchanged, so callers can pass
9
+ % whatever the user wrote. An empty cell is no filter ([]).
10
+ %
11
+ % The MATLAB twin of Python's scidb.all_of. The AND itself is done by
12
+ % scidb.Filter's & operator, which delegates to Python.
13
+
14
+ if ~iscell(filters)
15
+ result = filters;
16
+ return;
17
+ end
18
+ result = [];
19
+ for i = 1:numel(filters)
20
+ item = filters{i};
21
+ if iscell(item)
22
+ item = scidb.all_of(item);
23
+ end
24
+ if isempty(item)
25
+ continue;
26
+ end
27
+ if ~isa(item, 'scidb.Filter')
28
+ error('scidb:WhereListEntry', ...
29
+ 'where= list entries must be filters (e.g. Age() > 80), got %s.', ...
30
+ class(item));
31
+ end
32
+ if isempty(result)
33
+ result = item;
34
+ else
35
+ result = result & item;
36
+ end
37
+ end
38
+ end
@@ -10,6 +10,11 @@ function db = configure_database(dataset_db_path, dataset_schema_keys, options)
10
10
  % dataset_db_path - Path to the DuckDB database file (string)
11
11
  % dataset_schema_keys - Metadata keys defining the dataset schema
12
12
  % (string array, e.g. ["subject", "session"])
13
+ % A BRANCHED dataset is a cell array with one string
14
+ % array per branch, e.g.
15
+ % {["brand","category","item"], ["brand","location","person"]}
16
+ % (the key tree is stored in the database; a
17
+ % string array is one branch).
13
18
  % schema_key_types - Optional struct declaring per-key types, e.g.
14
19
  % struct('trial', 'numeric'). 'numeric' keys
15
20
  % canonicalize every spelling of the same number
@@ -34,18 +39,32 @@ function db = configure_database(dataset_db_path, dataset_schema_keys, options)
34
39
 
35
40
  arguments
36
41
  dataset_db_path string
37
- dataset_schema_keys string
42
+ dataset_schema_keys
38
43
  options.schema_key_types struct = struct()
39
44
  end
40
45
 
41
- % Convert keys to row vector
42
- if size(dataset_schema_keys,1) > 1
43
- dataset_schema_keys = dataset_schema_keys';
46
+ % One branch (a string array) or one string array per branch (a cell).
47
+ % py_schema_keys is what Python gets: a list of keys, or a list of lists.
48
+ % dataset_schema_keys becomes the FLAT row of keys, parents first, for
49
+ % scifor's MATLAB-side copy of the schema.
50
+ if iscell(dataset_schema_keys)
51
+ py_schema_keys = py.list();
52
+ flat = strings(1, 0);
53
+ for i = 1:numel(dataset_schema_keys)
54
+ branch = string(dataset_schema_keys{i});
55
+ branch = branch(:)';
56
+ py_schema_keys.append(py.list(cellstr(branch)));
57
+ flat = [flat, branch(~ismember(branch, flat))]; %#ok<AGROW>
58
+ end
59
+ dataset_schema_keys = flat;
60
+ else
61
+ dataset_schema_keys = string(dataset_schema_keys);
62
+ if size(dataset_schema_keys,1) > 1
63
+ dataset_schema_keys = dataset_schema_keys';
64
+ end
65
+ py_schema_keys = py.list(cellstr(dataset_schema_keys));
44
66
  end
45
67
 
46
- % Convert MATLAB string array to Python list of strings
47
- py_schema_keys = py.list(cellstr(dataset_schema_keys));
48
-
49
68
  dataset_db_path = char(dataset_db_path);
50
69
  if ~scidb.isabsolute(dataset_db_path)
51
70
  dataset_db_path = fullfile(pwd, dataset_db_path);
@@ -114,7 +114,7 @@ function result_tbl = for_each(fn, inputs, outputs, varargin)
114
114
  dry_run = opts.dry_run;
115
115
  do_save = opts.save;
116
116
  as_table_raw = opts.as_table;
117
- where_filter = opts.where;
117
+ where_filter = scidb.all_of(opts.where); % a cell means AND
118
118
 
119
119
  % --- Resolve function name + source hash (needed by Step 0's log
120
120
  % lines and error messages, so this runs ahead of everything else,
@@ -887,6 +887,15 @@ function result_tbl = for_each(fn, inputs, outputs, varargin)
887
887
  if all(~isnan(num) | ismissing(string(col)))
888
888
  result_tbl.(k) = cast(num, orig_class);
889
889
  end
890
+ elseif isnumeric(col) && ~isa(col, orig_class)
891
+ % Already numeric (the loop restores a key to the
892
+ % iterable's own class, always double): a key the
893
+ % caller passed as int32 must not come back double.
894
+ % Only when the cast loses nothing.
895
+ cast_col = cast(col, orig_class);
896
+ if isequaln(double(cast_col), double(col))
897
+ result_tbl.(k) = cast_col;
898
+ end
890
899
  end
891
900
  case 'logical'
892
901
  if isstring(col) || iscellstr(col)
@@ -540,7 +540,11 @@ end
540
540
 
541
541
  function [values, numbers] = describe_values(v, numbers)
542
542
  %DESCRIBE_VALUES One metadata iterable: numbers, texts, or mixed items.
543
- if isnumeric(v) || islogical(v)
543
+ if islogical(v)
544
+ % Logicals stay BOOLEANS on the wire: as numbers, k=true arrives as 1.0
545
+ % and a text key column "true" never matches it (key-match case 11).
546
+ values = struct('items', {num2cell(v(:)')});
547
+ elseif isnumeric(v)
544
548
  [ref, numbers] = push_numbers(numbers, double(v(:)));
545
549
  values = struct('numbers', ref);
546
550
  elseif isstring(v)
@@ -35,7 +35,10 @@ function [result, dropped] = merge_tables(parts, schema_keys, varargin)
35
35
  if isempty(labels)
36
36
  labels = "merge[" + string(0:numel(parts) - 1) + "]";
37
37
  end
38
- schema_keys = string(schema_keys);
38
+ % A ROW of keys: `for x = array` loops over COLUMNS, so a column of keys
39
+ % (what string(cellstr(jsondecode(...))) gives) would be one iteration
40
+ % holding every key.
41
+ schema_keys = reshape(string(schema_keys), 1, []);
39
42
 
40
43
  if isempty(parts)
41
44
  error('scifor:Merge', 'Merge has no constituents.');
@@ -46,7 +49,7 @@ function [result, dropped] = merge_tables(parts, schema_keys, varargin)
46
49
  for i = 1:numel(parts)
47
50
  if numel(drop) >= i && drop(i)
48
51
  [parts{i}, d] = drop_constant(parts{i}, schema_keys);
49
- names = string(fieldnames(d))';
52
+ names = reshape(string(fieldnames(d)), 1, []);
50
53
  for k = names
51
54
  if isfield(dropped, char(k))
52
55
  if ~isequaln(dropped.(char(k)), d.(char(k)))
@@ -62,7 +65,9 @@ function [result, dropped] = merge_tables(parts, schema_keys, varargin)
62
65
  parts{i} = select_columns(parts{i}, string(cols{i}), labels(i));
63
66
  end
64
67
  end
65
- for k = unique(conflicted)
68
+ % reshape: unique() of an empty string array is 0x1, which a `for` loop
69
+ % runs ONCE (one empty column), and rmfield(dropped, '') then fails.
70
+ for k = reshape(unique(conflicted), 1, [])
66
71
  dropped = rmfield(dropped, char(k));
67
72
  end
68
73
 
@@ -83,7 +88,7 @@ function [tbl, dropped] = drop_constant(tbl, schema_keys)
83
88
  dropped = struct();
84
89
  cols = string(tbl.Properties.VariableNames);
85
90
  to_drop = string.empty;
86
- for sk = schema_keys(ismember(schema_keys, cols))
91
+ for sk = reshape(schema_keys(ismember(schema_keys, cols)), 1, [])
87
92
  col = tbl.(char(sk));
88
93
  txt = key_text(col);
89
94
  if height(tbl) <= 1 || all(txt == txt(1))
File without changes
File without changes