framework-py 0.1.0.dev25__py3-none-any.whl → 0.1.0.dev27__py3-none-any.whl

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.
framework/__init__.py CHANGED
@@ -131,6 +131,8 @@ from framework.security import AuditResult, git_security_audit
131
131
  from framework.settings import settings, settings_read, settings_write
132
132
  from framework.skill_pull import pull_skills, push_skills
133
133
  from framework.skill_sync import skills_sync
134
+ from framework.snippets import load_ipython_extension as load_ipython_extension
135
+ from framework.snippets import snippet
134
136
  from framework.spec.check import spec_check
135
137
  from framework.spec.merge import SpecError
136
138
  from framework.spec.resolve import ResolvedSpec, spec_resolve
@@ -274,6 +276,7 @@ __all__ = [
274
276
  "settings_write",
275
277
  "show_table",
276
278
  "skills_sync",
279
+ "snippet",
277
280
  "spec_check",
278
281
  "spec_resolve",
279
282
  "status",
framework/_artifacts.py CHANGED
@@ -278,6 +278,8 @@ def as_frame(source: Any) -> pd.DataFrame | None:
278
278
  name = "value" if source.name is None or source.name == "" else str(source.name)
279
279
  return source.to_frame(name)
280
280
  if isinstance(source, np.ndarray):
281
+ if _axes_array(source):
282
+ return None
281
283
  return _numpy_frame(source)
282
284
  if _has_class(source, "polars", "DataFrame", "Series"):
283
285
  if _has_class(source, "polars", "Series"):
@@ -709,11 +711,14 @@ class _Design:
709
711
  self.predictors.append(name)
710
712
  return next(iter(used)) if len(used) == 1 else None
711
713
 
712
- def match(self, names: Sequence[str], factors: Sequence[Sequence[_Part]]) -> None:
714
+ def match(
715
+ self, names: Sequence[str], factors: Sequence[Sequence[_Part]], prefix: str = ""
716
+ ) -> None:
713
717
  """Map each design column to the parts whose names join to its name."""
714
718
  candidates: dict[str, tuple[_Part, ...]] = {}
715
719
  for combination in itertools.product(*factors):
716
- candidates.setdefault(":".join(part.name for part in combination), combination)
720
+ name = prefix + ":".join(part.name for part in combination)
721
+ candidates.setdefault(name, combination)
717
722
  for name in names:
718
723
  parts = candidates.get(name)
719
724
  if parts is None or not all(part.mappable for part in parts):
@@ -1308,11 +1313,51 @@ def _structured(source: Any) -> dict[str, Any] | None:
1308
1313
  return _test_document(source)
1309
1314
  if _from(source, "statsmodels"):
1310
1315
  raise FrameworkError("This statsmodels result does not expose coefficient statistics.")
1316
+ return _bayesian_document(source)
1317
+
1318
+
1319
+ def _bayesian_document(source: Any) -> dict[str, Any] | None:
1320
+ from framework import _bayesian
1321
+
1322
+ if isinstance(source, _bayesian.BambiFit):
1323
+ return _bayesian.bambi_document(source)
1324
+ if _bayesian.is_posterior(source):
1325
+ return _bayesian.posterior_document(source)
1326
+ if _bayesian.is_bambi_model(source):
1327
+ raise FrameworkError(
1328
+ "Publish the InferenceData that fit() returned, with the model: "
1329
+ "publish(idata, model=model)."
1330
+ )
1311
1331
  return None
1312
1332
 
1313
1333
 
1334
+ def _axes_array(source: Any) -> bool:
1335
+ """Whether an array holds matplotlib Axes, as ArviZ 0.x multi-panel plots return."""
1336
+ return (
1337
+ isinstance(source, np.ndarray)
1338
+ and source.dtype == object
1339
+ and source.size > 0
1340
+ and all(_from(item, "matplotlib") for item in source.flat)
1341
+ )
1342
+
1343
+
1344
+ def _plot_collection(source: Any) -> Any:
1345
+ """Return the backend figure an ArviZ 1.x PlotCollection draws on, or the source."""
1346
+ if not _has_class(source, "arviz_plots", "PlotCollection"):
1347
+ return source
1348
+ try:
1349
+ figure = source.get_viz("figure")
1350
+ except Exception:
1351
+ return source
1352
+ if hasattr(figure, "item") and getattr(figure, "ndim", 1) == 0:
1353
+ figure = figure.item()
1354
+ return source if figure is None else figure
1355
+
1356
+
1314
1357
  def _figure(source: Any) -> Any:
1315
1358
  """Return the matplotlib Figure behind an Axes, Figure, or seaborn grid."""
1359
+ if _axes_array(source):
1360
+ source = next(iter(source.flat))
1316
1361
  figure = source
1317
1362
  for _ in range(3):
1318
1363
  if callable(getattr(figure, "savefig", None)):
@@ -1322,6 +1367,8 @@ def _figure(source: Any) -> Any:
1322
1367
 
1323
1368
 
1324
1369
  def is_figure(source: Any) -> bool:
1370
+ if _axes_array(source):
1371
+ return True
1325
1372
  return _from(source, "matplotlib", "seaborn") and _figure(source) is not None
1326
1373
 
1327
1374
 
@@ -1365,6 +1412,7 @@ def _styler_html(source: Any, directory: Path) -> Path:
1365
1412
 
1366
1413
  def rendered(source: Any, directory: Path, cloud: bool) -> Path | None:
1367
1414
  """Write figures, formatted tables, and charts to their file formats, or return None."""
1415
+ source = _plot_collection(source)
1368
1416
  exporters: list[tuple[Callable[[Any], bool], Callable[[Any, Path], Path]]] = [
1369
1417
  (is_figure, lambda s, d: save_figure(s, d, svg=cloud)),
1370
1418
  (lambda s: _has_class(s, "pandas", "Styler"), _styler_html),