Skip to content

Commit 0f4034c

Browse files
authored
Fix/MetricsApp display (#169)
- Fixed `MetricsApp` `display` method - Added `nbformat` to dependencies
1 parent ff38526 commit 0f4034c

File tree

7 files changed

+294
-34
lines changed

7 files changed

+294
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Added
1212
- `Debias` mechanism for classification, ranking and auc metrics. New parameter `is_debiased` to `calc_from_confusion_df`, `calc_per_user_from_confusion_df` methods of classification metrics, `calc_from_fitted`, `calc_per_user_from_fitted` methods of auc and rankning (`MAP`) metrics, `calc_from_merged`, `calc_per_user_from_merged` methods of ranking (`NDCG`, `MRR`) metrics. ([#152](https://github.com/MobileTeleSystems/RecTools/pull/152))
13+
- `nbformat >= 4.2.0` dependency to `[visuals]` extra ([#169](https://github.com/MobileTeleSystems/RecTools/pull/169))
14+
15+
### Fixed
16+
- `display()` method in `MetricsApp` ([#169](https://github.com/MobileTeleSystems/RecTools/pull/169))
1317

1418
## [0.7.0] - 29.07.2024
1519

CONTRIBUTING.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Pull Request Process
3333
#. Create a virtual environment and install dependencies including all
3434
extras and development dependencies.
3535

36-
#. Make sure you have ``python3`` and ``poetry==1.4.0`` installed
36+
#. Make sure you have ``python>=3.8`` and ``poetry>=1.5.0`` installed
3737
#. Deactivate any active virtual environments. Deactivate conda ``base``
3838
environment if applicable
3939
#. Run ``make install`` command which will create a virtual env and

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ See [recommender baselines extended tutorial](https://github.com/MobileTeleSyste
125125
[Contributing guide](CONTRIBUTING.rst)
126126

127127
To install all requirements
128-
- you must have `python3` and `poetry==1.4.0` installed
128+
- you must have `python>=3.8` and `poetry>=1.5.0` installed
129129
- make sure you have no active virtual environments (deactivate conda `base` if applicable)
130130
- run
131131
```

poetry.lock

Lines changed: 277 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ pytorch-lightning = {version = ">=1.6.0, <3.0.0", optional = true}
8484

8585
ipywidgets = {version = ">=7.7,<8.2", optional = true}
8686
plotly = {version="^5.22.0", optional = true}
87+
nbformat = {version = ">=4.2.0", optional = true}
8788

8889

8990
[tool.poetry.extras]
9091
lightfm = ["rectools-lightfm"]
9192
nmslib = ["nmslib"]
9293
torch = ["torch", "pytorch-lightning"]
93-
visuals = ["ipywidgets", "plotly"]
94+
visuals = ["ipywidgets", "plotly", "nbformat"]
9495
all = [
9596
"rectools-lightfm",
9697
"nmslib",
9798
"torch", "pytorch-lightning",
98-
"ipywidgets", "plotly",
99+
"ipywidgets", "plotly", "nbformat",
99100
]
100101

101102

rectools/visuals/metrics_app.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,10 @@ def display(self) -> None:
337337
options=self.meta_names,
338338
)
339339

340-
# Initialize go.FigureWidget initial chart state
341-
if not self.fig.data:
342-
chart_data = self._create_chart_data(use_avg, fold_i)
343-
legend_title = f"{meta_feature.value}, {DEFAULT_LEGEND_TITLE}" if use_meta.value else DEFAULT_LEGEND_TITLE
344-
self.fig = self._create_chart_figure(
345-
chart_data, metric_x.value, metric_y.value, Columns.Model, legend_title
346-
)
347-
fig_widget = go.FigureWidget(data=self.fig.data, layout=self.fig.layout)
340+
chart_data = self._create_chart_data(use_avg, fold_i)
341+
legend_title = f"{meta_feature.value}, {DEFAULT_LEGEND_TITLE}" if use_meta.value else DEFAULT_LEGEND_TITLE
342+
self.fig = self._create_chart_figure(chart_data, metric_x.value, metric_y.value, Columns.Model, legend_title)
343+
fig_widget = go.FigureWidget(data=self.fig.data, layout=self.fig.layout)
348344

349345
def update(event: tp.Callable[..., tp.Any]) -> None: # pragma: no cover
350346
self._update_figure_widget(fig_widget, metric_x, metric_y, use_avg, fold_i, meta_feature, use_meta)

tests/visuals/test_metrics_app.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import typing as tp
16-
from unittest.mock import MagicMock, patch
1716

1817
import pandas as pd
1918
import pytest
@@ -97,27 +96,13 @@ def test_happy_path(
9796
show_legend: bool,
9897
auto_display: bool,
9998
scatter_kwargs: tp.Optional[tp.Dict[str, tp.Any]],
100-
) -> None:
101-
with patch("rectools.visuals.metrics_app.MetricsApp.display", MagicMock()):
102-
app = MetricsApp.construct(
103-
models_metrics=models_metrics,
104-
models_metadata=model_metadata,
105-
show_legend=show_legend,
106-
auto_display=auto_display,
107-
scatter_kwargs=scatter_kwargs,
108-
)
109-
_ = app.fig
110-
111-
@pytest.mark.parametrize("model_metadata", (None, DF_METAINFO))
112-
def test_display(
113-
self,
114-
model_metadata: tp.Optional[pd.DataFrame],
11599
) -> None:
116100
app = MetricsApp.construct(
117-
models_metrics=DF_METRICS,
101+
models_metrics=models_metrics,
118102
models_metadata=model_metadata,
119-
show_legend=True,
120-
auto_display=False,
103+
show_legend=show_legend,
104+
auto_display=auto_display,
105+
scatter_kwargs=scatter_kwargs,
121106
)
122107
app.display()
123108

0 commit comments

Comments
 (0)