Skip to content

Commit f72a23f

Browse files
committed
Merge branch 'copilot/implement-waterfall-graph-function' of https://github.com/sdpython/teachpyx into copilot/implement-waterfall-graph-function
2 parents c0c69a6 + c22383e commit f72a23f

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

_doc/api/tools/pandas.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
teachpyx.tools.pandas
33
=====================
44

5+
Example
6+
-------
7+
8+
.. plot::
9+
10+
import pandas
11+
import matplotlib.pyplot as plt
12+
from teachpyx.tools.pandas import plot_waterfall
13+
14+
plt.close("all")
15+
16+
df = pandas.DataFrame({"name": ["A", "B", "C"], "delta": [10, -3, 5]})
17+
ax, _ = plot_waterfall(df, "delta", "name", total_label="TOTAL")
18+
ax.set_title("Example waterfall")
19+
plt.xticks(rotation=30, ha="right")
20+
plt.tight_layout()
21+
plt.show()
22+
523
.. automodule:: teachpyx.tools.pandas
624
:members:
725
:no-undoc-members:

teachpyx/tools/pandas.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ def plot_waterfall(
7777
if len(colors) != 3:
7878
raise ValueError(f"colors must contain 3 values, not {len(colors)}.")
7979

80-
try:
81-
values = pandas.to_numeric(data[value_column], errors="raise").astype(float)
82-
except ValueError as exc:
83-
raise ValueError(
84-
f"Column {value_column!r} cannot be converted to numeric values."
85-
) from exc
80+
values = pandas.to_numeric(data[value_column], errors="raise").astype(float)
8681
labels = data[label_column] if label_column is not None else data.index
8782
labels = labels.astype(str)
8883

0 commit comments

Comments
 (0)