Skip to content

Commit 3d40e81

Browse files
committed
make lint, fix error in readme-examplse.ipynb
1 parent 5fee627 commit 3d40e81

File tree

4 files changed

+337
-125
lines changed

4 files changed

+337
-125
lines changed

examples/readme-examples.ipynb

Lines changed: 318 additions & 112 deletions
Large diffs are not rendered by default.

forestplot/dataframe_utils.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import numpy as np
77
import pandas as pd
88

9-
offline = os.getenv('FORESTPLOT_OFFLINE')
9+
offline = os.getenv("FORESTPLOT_OFFLINE")
10+
1011

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

126127
def load_data(
127128
name: str,
128-
data_path: Path = Path("./examples/data/"),
129-
**param_dict: Optional[Any]
130-
) -> pd.core.frame.DataFrame:
129+
data_path: Union[Path, str] = Path("./examples/data/"),
130+
**param_dict: Optional[Any],
131+
) -> pd.core.frame.DataFrame:
131132
"""
132133
Load example dataset for quickstart.
133134
@@ -151,14 +152,16 @@ def load_data(
151152
available_data = ["mortality", "sleep", "sleep-untruncated"]
152153
name = name.lower().strip()
153154
if name in available_data:
154-
data = Path(data_path) / f"{name}.csv"
155-
if not data.is_file():
156-
if offline:
157-
raise AssertionError(f"{data} not found. Working offline (FORESTPLOT_OFFLINE={offline}).")
158-
data = (
159-
f"https://raw.githubusercontent.com/lsys/forestplot/main/examples/data/{name}.csv"
155+
data_path = Path(data_path) / f"{name}.csv"
156+
if data_path.is_file():
157+
df = pd.read_csv(data_path, **param_dict)
158+
elif offline:
159+
raise AssertionError(
160+
f"{data_path} not found. Working offline (FORESTPLOT_OFFLINE={offline})."
160161
)
161-
df = pd.read_csv(data, **param_dict)
162+
else:
163+
url = f"https://github.com/LSYS/forestplot/tree/main/examples/data/{name}.csv"
164+
df = pd.read_csv(url, **param_dict)
162165
if name == "sleep":
163166
df["n"] = df["n"].astype("str")
164167
return df

forestplot/graph_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88

99
warnings.filterwarnings("ignore")
1010

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

1517
def draw_ci(
1618
dataframe: pd.core.frame.DataFrame,

tests/test_plot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33
from pathlib import Path
4+
45
import pandas as pd
56
from matplotlib.pyplot import Axes
67

0 commit comments

Comments
 (0)