Skip to content

Commit

Permalink
test(datasets): add outputs to matplotlib doctests (#449)
Browse files Browse the repository at this point in the history
* test(datasets): add outputs to matplotlib doctests

Signed-off-by: Deepyaman Datta <[email protected]>

* Update Makefile

Signed-off-by: Deepyaman Datta <[email protected]>

* Reformat code example, line length is short enough

* Update kedro-datasets/kedro_datasets/matplotlib/matplotlib_writer.py

Signed-off-by: Deepyaman Datta <[email protected]>

---------

Signed-off-by: Deepyaman Datta <[email protected]>
  • Loading branch information
deepyaman authored Nov 28, 2023
1 parent 9dedaad commit e91fdbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ dataset-doctests:
# TODO(deepyaman): Fix as many doctests as possible (so that they run).
cd kedro-datasets && pytest kedro_datasets --doctest-modules --doctest-continue-on-failure --no-cov \
--ignore kedro_datasets/databricks/managed_table_dataset.py \
--ignore kedro_datasets/matplotlib/matplotlib_writer.py \
--ignore kedro_datasets/pandas/deltatable_dataset.py \
--ignore kedro_datasets/pandas/gbq_dataset.py \
--ignore kedro_datasets/pandas/sql_dataset.py \
Expand Down
25 changes: 17 additions & 8 deletions kedro-datasets/kedro_datasets/matplotlib/matplotlib_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ class MatplotlibWriter(
>>> from kedro_datasets.matplotlib import MatplotlibWriter
>>>
>>> fig = plt.figure()
>>> plt.plot([1, 2, 3])
>>> plot_writer = MatplotlibWriter(filepath="data/08_reporting/output_plot.png")
>>> plt.plot([1, 2, 3]) # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at 0x...>]
>>> plot_writer = MatplotlibWriter(filepath=tmp_path / "data/08_reporting/output_plot.png")
>>> plt.close()
>>> plot_writer.save(fig)
Expand All @@ -57,10 +58,10 @@ class MatplotlibWriter(
>>> from kedro_datasets.matplotlib import MatplotlibWriter
>>>
>>> fig = plt.figure()
>>> plt.plot([1, 2, 3])
>>> plt.plot([1, 2, 3]) # doctest: +ELLIPSIS
[<matplotlib.lines.Line2D object at 0x...>]
>>> pdf_plot_writer = MatplotlibWriter(
... filepath="data/08_reporting/output_plot.pdf",
... save_args={"format": "pdf"},
... filepath=tmp_path / "data/08_reporting/output_plot.pdf", save_args={"format": "pdf"}
... )
>>> plt.close()
>>> pdf_plot_writer.save(fig)
Expand All @@ -77,8 +78,11 @@ class MatplotlibWriter(
... plots_dict[f"{colour}.png"] = plt.figure()
... plt.plot([1, 2, 3], color=colour)
...
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.close("all")
>>> dict_plot_writer = MatplotlibWriter(filepath="data/08_reporting/plots")
>>> dict_plot_writer = MatplotlibWriter(filepath=tmp_path / "data/08_reporting/plots")
>>> dict_plot_writer.save(plots_dict)
Example saving multiple plots in a folder, using a list:
Expand All @@ -89,12 +93,17 @@ class MatplotlibWriter(
>>> from kedro_datasets.matplotlib import MatplotlibWriter
>>>
>>> plots_list = []
>>> for i in range(5):
>>> for i in range(5): # doctest: +ELLIPSIS
... plots_list.append(plt.figure())
... plt.plot([i, i + 1, i + 2])
...
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.close("all")
>>> list_plot_writer = MatplotlibWriter(filepath="data/08_reporting/plots")
>>> list_plot_writer = MatplotlibWriter(filepath=tmp_path / "data/08_reporting/plots")
>>> list_plot_writer.save(plots_list)
"""
Expand Down

0 comments on commit e91fdbc

Please sign in to comment.