diff --git a/plot_serializer/matplotlib/serializer.py b/plot_serializer/matplotlib/serializer.py index 957c4fed112fad63f44bb10d87501be85493fb61..6cd93f3c1eea0bb8aa826ed2ce5f1ec3cef12f74 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 018b898e457c982b53b1e7b6dd87ec31234ef90b..58c669bc1343b91931b323f7a78100021fde1249 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 69329b037b44c38b06963e4ce8dc8e5b7310fab4..643e31d4f40cc14556291abedabc3e3e9b79022b 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 26c2d2cfa88a0072b8b8bfc80cf006bfda5a8cb0..c2b688fe8e416c37a4109f9bc6d4237108c52837 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 d72e85afcb4e938faa88424d96c31a2746cde771..35dba2b5b6055f6aa7a4c084a8b0ebf1529d3932 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 e6499ba8c6400b9901ce4f1b8e49957c133ce712..4490649a73a702972d6dfa4db7c828cec0dd4552 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 e01b9a617f093281d89b63bfed7c98635ea38203..26844012e56bcd94766514416c3d773125d10b94 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 3adc1f6e80d59a74e47d354846858b47333e2484..4026d9d0c11c9e87d4802a1ad9d8857a6d435452 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 8bfcd5283a44963f86c5efe1ca7799267597e26a..5eb4d42545ca7769b4f5a7d45ca9d6cbf7055b6b 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 da65180aaef40f31d68f6fe298d11054b1889831..8f2631501c212ce7f192a09a88249f3da88e38a1 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 6aa29d4eb0f818e70bc2b625fa83c801447a046e..fd8573af6c04bcdaba3bcc356bd8865801c10e6e 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)