Skip to content

Commit

Permalink
make lint (happy), fix error in readme-examples.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
EythorE committed Oct 10, 2023
1 parent 5fee627 commit 10bc9b6
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 125 deletions.
430 changes: 318 additions & 112 deletions examples/readme-examples.ipynb

Large diffs are not rendered by default.

25 changes: 14 additions & 11 deletions forestplot/dataframe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import numpy as np
import pandas as pd

offline = os.getenv('FORESTPLOT_OFFLINE')
offline = os.getenv("FORESTPLOT_OFFLINE")


def insert_groups(
dataframe: pd.core.frame.DataFrame, groupvar: str, varlabel: str
Expand Down Expand Up @@ -125,9 +126,9 @@ def insert_empty_row(dataframe: pd.core.frame.DataFrame) -> pd.core.frame.DataFr

def load_data(
name: str,
data_path: Path = Path("./examples/data/"),
**param_dict: Optional[Any]
) -> pd.core.frame.DataFrame:
data_path: Union[Path, str] = Path("./examples/data/"),
**param_dict: Optional[Any],
) -> pd.core.frame.DataFrame:
"""
Load example dataset for quickstart.
Expand All @@ -151,14 +152,16 @@ def load_data(
available_data = ["mortality", "sleep", "sleep-untruncated"]
name = name.lower().strip()
if name in available_data:
data = Path(data_path) / f"{name}.csv"
if not data.is_file():
if offline:
raise AssertionError(f"{data} not found. Working offline (FORESTPLOT_OFFLINE={offline}).")
data = (
f"https://raw.githubusercontent.com/lsys/forestplot/main/examples/data/{name}.csv"
data_path = Path(data_path) / f"{name}.csv"
if data_path.is_file():
df = pd.read_csv(data_path, **param_dict)
elif offline:
raise AssertionError(
f"{data_path} not found. Working offline (FORESTPLOT_OFFLINE={offline})."
)
df = pd.read_csv(data, **param_dict)
else:
url = f"https://github.com/LSYS/forestplot/tree/main/examples/data/{name}.csv"
df = pd.read_csv(url, **param_dict)
if name == "sleep":
df["n"] = df["n"].astype("str")
return df
Expand Down
6 changes: 4 additions & 2 deletions forestplot/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

warnings.filterwarnings("ignore")

def _get_pad(ax: Axes, **kwargs) -> float:

def _get_pad(ax: Axes, **kwargs: Optional[Any]) -> float:
extrapad = kwargs.get("extrapad", 0.05)
return ax.get_xlim()[1] + extrapad*(ax.get_xlim()[1] - ax.get_xlim()[0])
return ax.get_xlim()[1] + extrapad * (ax.get_xlim()[1] - ax.get_xlim()[0])


def draw_ci(
dataframe: pd.core.frame.DataFrame,
Expand Down
1 change: 1 addition & 0 deletions tests/test_plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# coding: utf-8
from pathlib import Path

import pandas as pd
from matplotlib.pyplot import Axes

Expand Down

0 comments on commit 10bc9b6

Please sign in to comment.