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

Fixed optional dependencies being imported #317

Merged
merged 1 commit into from
Jan 16, 2025
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
4 changes: 2 additions & 2 deletions python/pdstools/adm/Plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_nonperforming_models(df: pl.LazyFrame):
num_models = subset.select(pl.first().count()).collect().item()
if num_models > 0:
bottomleft = get_nonperforming_models(subset)
newtext = f"{num_models} models: {bottomleft} ({round(bottomleft/num_models*100, 2)}%) at (50,0)"
newtext = f"{num_models} models: {bottomleft} ({round(bottomleft / num_models * 100, 2)}%) at (50,0)"
fig.layout.annotations[i].text += f"<br><sup>{newtext}</sup>"
if len(fig.data) > i:
fig.data[i].marker.size *= bubble_size
Expand All @@ -139,7 +139,7 @@ def get_nonperforming_models(df: pl.LazyFrame):
return fig
num_models = df.select(pl.first().len()).collect().item()
bottomleft = get_nonperforming_models(df)
newtext = f"{num_models} models: {bottomleft} ({round(bottomleft/num_models*100, 2)}%) at (50,0)"
newtext = f"{num_models} models: {bottomleft} ({round(bottomleft / num_models * 100, 2)}%) at (50,0)"
fig.layout.title.text += f"<br><sup>{newtext}</sup>"
fig.data[0].marker.size *= bubble_size
return fig
Expand Down
2 changes: 1 addition & 1 deletion python/pdstools/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "pdstools[app]>=4.0",
# "pdstools[app]>=4.0.3",
# ]
# ///

Expand Down
33 changes: 28 additions & 5 deletions python/pdstools/ih/Plots.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import logging
from datetime import timedelta
from typing import TYPE_CHECKING, Dict, List, Optional, Union

import polars as pl
import plotly as plotly
import plotly.express as px
import plotly.graph_objs as go
from plotly.subplots import make_subplots

from ..utils.types import QUERY
from ..utils import cdh_utils
from ..utils.namespaces import LazyNamespace
from ..utils.types import QUERY

logger = logging.getLogger(__name__)
if TYPE_CHECKING:
from .IH import IH as IH_Class
try:
import plotly as plotly
import plotly.express as px


except ImportError as e: # pragma: no cover
logger.debug(f"Failed to import optional dependencies: {e}")


class Plots(LazyNamespace):
Expand All @@ -31,6 +37,10 @@ def overall_gauges(
# facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.graph_objects as go
from plotly.subplots import make_subplots

plot_data = self.ih.aggregates.summary_success_rates(
by=[condition, by], query=query
)
Expand Down Expand Up @@ -115,6 +125,8 @@ def response_count_tree_map(
# facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.express as px

if by is None:
by = [
Expand Down Expand Up @@ -160,6 +172,9 @@ def success_rate_tree_map(
# facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.express as px

if by is None:
by = [
f
Expand Down Expand Up @@ -289,6 +304,9 @@ def success_rate(
facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.express as px

plot_data = self.ih.aggregates.summary_success_rates(
every=every, by=facet, query=query
)
Expand Down Expand Up @@ -324,6 +342,9 @@ def response_count(
facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.express as px

plot_data = self.ih.aggregates.ih.aggregates.summary_outcomes(
every=every, by=facet, query=query
).collect()
Expand Down Expand Up @@ -356,6 +377,8 @@ def model_performance_trend(
facet: Optional[str] = None,
return_df: Optional[bool] = False,
):
import plotly as plotly
import plotly.express as px

plot_data = (
self.ih.aggregates._summary_interactions(
Expand Down
32 changes: 23 additions & 9 deletions python/pdstools/utils/report_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import datetime
import json
import logging
import re
import traceback
import shutil
import subprocess
import logging
import traceback
from pathlib import Path
from typing import Dict, List, Optional, Union, Tuple
from IPython.display import display, Markdown
from great_tables import GT, style, loc
from typing import Dict, List, Optional, Tuple, Union

import polars as pl

from ..adm.CDH_Guidelines import CDHGuidelines
from ..utils.show_versions import show_versions
from ..utils.types import QUERY
import polars as pl
import datetime
import json

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,6 +77,8 @@ def get_pandoc_with_version(verbose: bool = True) -> Tuple[Path, str]:


def quarto_print(text):
from IPython.display import Markdown, display

display(Markdown(text))


Expand Down Expand Up @@ -132,6 +134,8 @@ def polars_subset_to_existing_cols(all_columns, cols):


def rag_background_styler(rag: Optional[str] = None):
from great_tables import style

if rag is not None and len(rag) > 0:
rag_upper = rag[0].upper()
if rag_upper == "R":
Expand All @@ -146,6 +150,8 @@ def rag_background_styler(rag: Optional[str] = None):


def rag_background_styler_dense(rag: Optional[str] = None):
from great_tables import style

if rag is not None and len(rag) > 0:
rag_upper = rag[0].upper()
if rag_upper == "R":
Expand All @@ -160,6 +166,8 @@ def rag_background_styler_dense(rag: Optional[str] = None):


def rag_textcolor_styler(rag: Optional[str] = None):
from great_tables import style

if rag is not None and len(rag) > 0:
rag_upper = rag[0].upper()
if rag_upper == "R":
Expand All @@ -185,6 +193,8 @@ def table_standard_formatting(
highlight_configurations: List[str] = [],
rag_styler: callable = rag_background_styler,
):
from great_tables import GT, loc

def apply_style(gt, rag, rows):
style = rag_styler(rag)
if style is not None:
Expand Down Expand Up @@ -316,8 +326,12 @@ def simplify_name(x: str) -> str:


def table_style_predictor_count(
gt: GT, flds, cdh_guidelines=CDHGuidelines(), rag_styler=rag_textcolor_styler
gt, flds, cdh_guidelines=CDHGuidelines(), rag_styler=rag_textcolor_styler
):
from great_tables import GT, loc

if not isinstance(gt, GT):
raise ValueError("gt argument should be a Great Table")
for col in flds:
gt = gt.tab_style(
style=rag_styler("amber"),
Expand Down
Loading