From 12c96175724247c09be51d20d51514e53f0235b0 Mon Sep 17 00:00:00 2001 From: Julius <juliusflorstedt@gmail.com> Date: Sun, 2 Feb 2025 22:00:46 +0100 Subject: [PATCH] added doc, fixed timing bug in tests, fixed boxplot bug --- plot_serializer/matplotlib/serializer.py | 2 +- tests_automatic/test_bar_automatic.py | 7 ++++--- tests_automatic/test_box_automatic.py | 11 +++++++---- tests_automatic/test_errorbar_automatic.py | 7 ++++--- tests_automatic/test_hist_automatic.py | 7 ++++--- tests_automatic/test_line3d_automatic.py | 7 ++++--- tests_automatic/test_line_automatic.py | 7 ++++--- tests_automatic/test_pie_automatic.py | 8 +++++--- tests_automatic/test_scatter3d_automatic.py | 7 ++++--- tests_automatic/test_scatter_automatic.py | 7 ++++--- tests_automatic/test_surface3d_automatic.py | 7 ++++--- 11 files changed, 45 insertions(+), 32 deletions(-) diff --git a/plot_serializer/matplotlib/serializer.py b/plot_serializer/matplotlib/serializer.py index 957c4fe..6cd93f3 100644 --- a/plot_serializer/matplotlib/serializer.py +++ b/plot_serializer/matplotlib/serializer.py @@ -444,7 +444,7 @@ class _AxesProxy(Proxy[MplAxes]): conf_intervals = itertools.repeat(None) for dataset, label, umedian, cintervals in zip(x, labels, usermedians, conf_intervals): - x = np.ma.asarray(x) + x = np.ma.asarray(x, dtype="object") x = x.data[~x.mask].ravel() boxes.append( Box( diff --git a/tests_automatic/test_bar_automatic.py b/tests_automatic/test_bar_automatic.py index 018b898..58c669b 100644 --- a/tests_automatic/test_bar_automatic.py +++ b/tests_automatic/test_bar_automatic.py @@ -33,15 +33,16 @@ def test_bar_properties( x: Any, heights: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.bar(x, heights) except Exception as _e: - plt.close() + pass else: serializer_ax.bar(x, heights) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_box_automatic.py b/tests_automatic/test_box_automatic.py index 69329b0..643e31d 100644 --- a/tests_automatic/test_box_automatic.py +++ b/tests_automatic/test_box_automatic.py @@ -1,10 +1,11 @@ from typing import Any import numpy as np -from hypothesis import given +from hypothesis import given, settings from hypothesis import strategies as st from hypothesis.extra.numpy import arrays from matplotlib import pyplot as plt +from matplotlib.pylab import f from plot_serializer.matplotlib.serializer import MatplotlibSerializer @@ -49,6 +50,7 @@ tick_labels_strategy = st.one_of(st.none(), st.lists(st.text(), min_size=1)) conf_intervals=conf_intervals_strategy, tick_labels=tick_labels_strategy, ) +@settings(deadline=500) def test_box_properties( x: Any, notch: Any, @@ -58,7 +60,6 @@ def test_box_properties( conf_intervals: Any, tick_labels: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() @@ -73,7 +74,7 @@ def test_box_properties( tick_labels=tick_labels, ) except Exception as _e: - plt.close() + pass else: serializer_ax.boxplot( x=x, @@ -85,4 +86,6 @@ def test_box_properties( tick_labels=tick_labels, ) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_errorbar_automatic.py b/tests_automatic/test_errorbar_automatic.py index 26c2d2c..c2b688f 100644 --- a/tests_automatic/test_errorbar_automatic.py +++ b/tests_automatic/test_errorbar_automatic.py @@ -50,15 +50,16 @@ def test_bar_properties( marker: Any, label: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.errorbar(x, y, xerr=xerr, yerr=yerr, marker=marker, label=label) except Exception as _e: - plt.close() + pass else: serializer_ax.errorbar(x, y, xerr=xerr, yerr=yerr, marker=marker, label=label) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_hist_automatic.py b/tests_automatic/test_hist_automatic.py index d72e85a..35dba2b 100644 --- a/tests_automatic/test_hist_automatic.py +++ b/tests_automatic/test_hist_automatic.py @@ -38,15 +38,16 @@ def test_hist_properties( densitiy: Any, culumative: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.hist(x, bins=bins, label=label, density=densitiy, cumulative=culumative) except Exception as _e: - plt.close() + pass else: serializer_ax.hist(x, bins=bins, label=label, density=densitiy, cumulative=culumative) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_line3d_automatic.py b/tests_automatic/test_line3d_automatic.py index e6499ba..4490649 100644 --- a/tests_automatic/test_line3d_automatic.py +++ b/tests_automatic/test_line3d_automatic.py @@ -39,15 +39,16 @@ def test_line_properties( label: Any, linewidth: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.plot(x, y, z, label=label, linewidth=linewidth) except Exception as _e: - plt.close() + pass else: serializer_ax.plot(x, y, z, label=label, linewidth=linewidth) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_line_automatic.py b/tests_automatic/test_line_automatic.py index e01b9a6..2684401 100644 --- a/tests_automatic/test_line_automatic.py +++ b/tests_automatic/test_line_automatic.py @@ -32,15 +32,16 @@ def test_line_properties( label: Any, linewidth: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.plot(x, y, label=label, linewidth=linewidth) except Exception as _e: - plt.close() + pass else: serializer_ax.plot(x, y, label=label, linewidth=linewidth) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_pie_automatic.py b/tests_automatic/test_pie_automatic.py index 3adc1f6..4026d9d 100644 --- a/tests_automatic/test_pie_automatic.py +++ b/tests_automatic/test_pie_automatic.py @@ -1,3 +1,4 @@ +import time from typing import Any import numpy as np @@ -31,15 +32,16 @@ def test_pie_properties( labels: Any, radius: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.pie(x, explode=explode, labels=labels, radius=radius) except Exception as _e: - plt.close() + pass else: serializer_ax.pie(x, explode=explode, labels=labels, radius=radius) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_scatter3d_automatic.py b/tests_automatic/test_scatter3d_automatic.py index 8bfcd52..5eb4d42 100644 --- a/tests_automatic/test_scatter3d_automatic.py +++ b/tests_automatic/test_scatter3d_automatic.py @@ -43,15 +43,16 @@ def test_scatter3d_properties( s: Any, label: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots(subplot_kw={"projection": "3d"}) _fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) try: ax.scatter(x, y, z, s=s, label=label) # type: ignore except Exception as _e: - plt.close() + pass else: serializer_ax.scatter(x, y, z, s=s, label=label) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_scatter_automatic.py b/tests_automatic/test_scatter_automatic.py index da65180..8f26315 100644 --- a/tests_automatic/test_scatter_automatic.py +++ b/tests_automatic/test_scatter_automatic.py @@ -36,15 +36,16 @@ def test_scatter_properties( s: Any, label: Any, ) -> None: - plt.close() serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots() _fig, ax = plt.subplots() try: ax.scatter(x, y, s=s, label=label) except Exception as _e: - plt.close() + pass else: serializer_ax.scatter(x, y, s=s, label=label) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) diff --git a/tests_automatic/test_surface3d_automatic.py b/tests_automatic/test_surface3d_automatic.py index 6aa29d4..fd8573a 100644 --- a/tests_automatic/test_surface3d_automatic.py +++ b/tests_automatic/test_surface3d_automatic.py @@ -34,7 +34,6 @@ def matrix_triplet_strategy(draw, min_dim=1, max_dim=10, min_value=0, max_value= def test_surface_properties( matrix_triplet: Any, ) -> None: - plt.close() x, y, z = matrix_triplet serializer = MatplotlibSerializer() _, serializer_ax = serializer.subplots(subplot_kw={"projection": "3d"}) @@ -42,8 +41,10 @@ def test_surface_properties( try: ax.plot_surface(x, y, z) # type: ignore except Exception as _e: - plt.close() + pass else: serializer_ax.plot_surface(x, y, z) assert serializer.to_json() != "{}", "Serialized JSON is empty check input" - plt.close() + finally: + plt.close(_) + plt.close(_fig) -- GitLab