Skip to content

Commit

Permalink
feat: infer specification alignment (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth committed May 17, 2024
1 parent 7f6cfe8 commit 3ad9d75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions opvious/modeling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import dataclasses
import logging
import os
import pandas as pd
from typing import Any, Iterable, Literal, Mapping, Optional, Sequence, Union

Expand Down Expand Up @@ -289,7 +290,9 @@ def definition_counts(self) -> pd.DataFrame:
grouped: Any = df.groupby(["title", "category"])["text"].count()
return grouped.unstack(["category"]).fillna(0).astype(int)

def specification(self, align=True) -> LocalSpecification:
def specification(
self, align: Optional[bool] = None
) -> LocalSpecification:
"""Generates the model's specification
This specification can be used to interact with :class:`.Client`
Expand All @@ -300,6 +303,8 @@ def specification(self, align=True) -> LocalSpecification:
environment. This can be disabled to enable pretty printing in
environments which do not support them (e.g. Colab).
"""
if align is None:
align = not os.getenv("COLAB_RELEASE_TAG")
grouped = collections.defaultdict(list)
for s in self.statements():
grouped[s.title].append(s.text)
Expand All @@ -319,4 +324,4 @@ def specification(self, align=True) -> LocalSpecification:
def _format_contents(contents, align):
if align:
return f"$$\n\\begin{{align*}}\n{contents}\\end{{align*}}\n$$"
return f"$$\n{contents.replace('&', '')}\n$$"
return f"$$\n{contents.replace('&', '')}$$"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "opvious"
version = "0.18.7rc1"
version = "0.18.8rc1"
description = "Opvious Python SDK"
authors = ["Opvious Engineering <oss@opvious.io>"]
readme = "README.md"
Expand Down

0 comments on commit 3ad9d75

Please sign in to comment.