Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/165 factories for newest layout widgets #227

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test_install/
__pycache__/
.mypy_cache/
.pytest_cache/
.ruff_cache/
.ipynb_checkpoints/

# Spotlight licenses
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ init-playbook: ## Locally install all playbook dev dependencies

.PHONY: clean
clean: ## clean project
rm -fr build/ .pytest_cache/ .mypy_cache/
-rm -rf node_modules
rm -rf build/ .pytest_cache/ .ruff_cache/ .mypy_cache/
rm -rf node_modules

.PHONY: audit
audit: ## Audit project dependencies
Expand Down
861 changes: 443 additions & 418 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ packaging = "^21.3"
nbmake = "^1.3.0"
selenium = "^4.1.3, <4.10"
diffimg = "^0.3.0"
lesscpy = "^0.15.0"
safety = "^1.10.3"
typer = "^0.4.1"
pre-commit = "^2.19.0"
Expand Down
74 changes: 74 additions & 0 deletions renumics/spotlight/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
)
from .lenses import Lens
from .widgets import (
ConfusionMatrix,
ConfusionMatrixConfig,
Histogram,
HistogramConfig,
Inspector,
InspectorConfig,
Issues,
MetricWidget,
MetricWidgetConfig,
NumInspectorColumns as _NumInspectorColumns,
PCANormalization as _PCANormalization,
ReductionMethod as _ReductionMethod,
Expand All @@ -43,6 +47,9 @@
TableView as _TableView,
UmapMetric as _UmapMetric,
Widget as _Widget,
WordCloud,
WordCloudConfig,
WordCloudScaling as _WordCloudScaling,
)


Expand Down Expand Up @@ -361,3 +368,70 @@ def issues(name: Optional[str] = None) -> Issues:
"""

return Issues(name=name)


def wordcloud(
name: Optional[str] = None,
column: Optional[str] = None,
min_word_length: Optional[int] = None,
stop_words: Optional[Iterable[str]] = None,
scaling: Optional[_WordCloudScaling] = None,
max_word_count: Optional[int] = None,
filter: Optional[bool] = None,
) -> WordCloud:
"""
Add configured confusion matrix to Spotlight layout.
"""
if min_word_length is not None and min_word_length < 1:
raise ValueError(
f"`min_word_length` argument should be positive, but value "
f"{min_word_length} received."
)
if max_word_count is not None and max_word_count < 1:
raise ValueError(
f"`max_word_count` argument should be positive, but value "
f"{max_word_count} received."
)
return WordCloud(
name=name,
config=WordCloudConfig(
column=column,
min_word_length=min_word_length,
stop_words=None if stop_words is None else list(stop_words),
scaling=scaling,
max_word_count=max_word_count,
filter=filter,
),
)


def confusion_matrix(
name: Optional[str] = None,
x_column: Optional[str] = None,
y_column: Optional[str] = None,
) -> ConfusionMatrix:
"""
Add configured confusion matrix to Spotlight layout.
"""
return ConfusionMatrix(
name=name,
config=ConfusionMatrixConfig(x_column=x_column, y_column=y_column),
)


def metric(
name: Optional[str] = None,
metric: Optional[str] = None,
columns: Optional[Union[str, Iterable[Optional[str]]]] = None,
) -> MetricWidget:
"""
Add configured metric widget to Spotlight layout.
"""
metric_columns: List[Optional[str]] = []
if isinstance(columns, str):
metric_columns.append(columns)
elif columns is not None:
metric_columns.extend(columns)
return MetricWidget(
name=name, config=MetricWidgetConfig(metric=metric, columns=metric_columns)
)
29 changes: 27 additions & 2 deletions renumics/spotlight/layout/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,38 @@ class Issues(Widget):
type: Literal["IssuesWidget"] = "IssuesWidget"


WordCloudScaling = Literal["log", "linear", "sqrt"]


class WordCloudConfig(WidgetConfig):
"""
Config for the Word Cloud Widget.
"""

column: Optional[str] = Field(None, alias="cloudByColumnKey")
min_word_length: Optional[int] = Field(None, alias="minWordLength")
stop_words: Optional[List[str]] = Field(None, alias="stopwords")
scaling: Optional[WordCloudScaling] = Field(None, alias="scaling")
max_word_count: Optional[int] = Field(None, alias="wordCount")
filter: Optional[bool] = Field(None, alias="hideFiltered")


class WordCloud(Widget):
"""
Word Cloud Widget.
"""

type: Literal["wordcloud"] = "wordcloud"
config: Optional[WordCloudConfig] = None


class ConfusionMatrixConfig(WidgetConfig):
"""
Config for the Confusion Matrix Widget.
"""

x_column: Optional[str] = Field(default_factory=None, alias="xColumn")
y_column: Optional[str] = Field(default_factory=None, alias="yColumn")
x_column: Optional[str] = Field(None, alias="xColumn")
y_column: Optional[str] = Field(None, alias="yColumn")


class ConfusionMatrix(Widget):
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/MetricsWidget/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const METRICS: Record<string, Metric> = {
accuracy: {
signature: {
X: ['bool', 'int', 'Category'],
y: ['bool', 'int', 'Category'],
Y: ['bool', 'int', 'Category'],
},
compute: ([actualValues, assignedValues]) => {
const all = actualValues.length;
Expand Down