Tests fail with tikzplotlib 0.9.3 and matplotlib 3.2.2
Aikhjarto opened this issue · comments
With the latest release 0.9.3 some incompatibilities with matplotlib 3.2.2 where introduced which make two unit-tests fail, namely test/test_logplot_base.py
and test/test_pandas_dataframe.py
.
General question: Should tikzplotlib support older version of matplotlib?
Steps to reproduce
Add matplotlib <3.3.0
to tox.ini and run tests.
diff --git a/tox.ini b/tox.ini
index 751d216..771b211 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,5 +8,6 @@ deps =
pandas
pytest
pytest-cov
+ matplotlib<3.3.0
commands =
pytest --cov {envsitepackagesdir}/tikzplotlib --cov-report xml --cov-report term
Then run tox
. Full log:
.package create: /home/$USER/src/tikzplotlib/.tox/.package
.package installdeps: setuptools>=42, wheel
py3 create: /home/$USER/src/tikzplotlib/.tox/py3
py3 installdeps: exdown, pandas, pytest, pytest-cov, matplotlib<3.3.0
py3 inst: /home/$USER/src/tikzplotlib/.tox/.tmp/package/1/tikzplotlib-0.9.3.tar.gz
py3 installed: attrs==19.3.0,coverage==5.2.1,cycler==0.10.0,exdown==0.7.0,importlib-metadata==1.7.0,kiwisolver==1.2.0,matplotlib==3.2.2,more-itertools==8.4.0,numpy==1.19.1,packaging==20.4,pandas==1.0.5,Pillow==7.2.0,pluggy==0.13.1,py==1.9.0,pyparsing==2.4.7,pytest==5.4.3,pytest-cov==2.10.0,python-dateutil==2.8.1,pytz==2020.1,six==1.15.0,tikzplotlib @ file:///home/$USER/src/tikzplotlib/.tox/.tmp/package/1/tikzplotlib-0.9.3.tar.gz,wcwidth==0.2.5,zipp==3.1.0
py3 run-test-pre: PYTHONHASHSEED='1208807351'
py3 run-test: commands[0] | pytest --cov /home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/tikzplotlib --cov-report xml --cov-report term
===================================================================================== test session starts =====================================================================================
platform linux -- Python 3.7.2, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
cachedir: .tox/py3/.pytest_cache
rootdir: /home/$USER/src/tikzplotlib
plugins: cov-2.10.0
collected 98 items
test/test_annotate.py . [ 1%]
test/test_axvline.py . [ 2%]
test/test_barchart.py . [ 3%]
test/test_barchart_errorbars.py . [ 4%]
test/test_barchart_legend.py . [ 5%]
test/test_basic_sin.py . [ 6%]
test/test_boxplot.py . [ 7%]
test/test_cleanfigure.py ....................... [ 30%]
test/test_colorbars.py . [ 31%]
test/test_context.py . [ 32%]
test/test_contourf.py . [ 33%]
test/test_custom_collection.py . [ 34%]
test/test_datetime.py . [ 35%]
test/test_datetime_paths.py . [ 36%]
test/test_deterministic_output.py . [ 37%]
test/test_dual_axis.py . [ 38%]
test/test_errorband.py . [ 39%]
test/test_errorbar.py . [ 40%]
test/test_escape_chars.py . [ 41%]
test/test_externalize_tables.py . [ 42%]
test/test_fancy_colorbar.py . [ 43%]
test/test_fancybox.py . [ 44%]
test/test_fillstyle.py . [ 45%]
test/test_hatch.py . [ 46%]
test/test_heat.py . [ 47%]
test/test_histogram.py . [ 48%]
test/test_image_plot_lower.py . [ 50%]
test/test_legend_best_location.py . [ 51%]
test/test_legend_columns.py . [ 52%]
test/test_legend_labels.py . [ 53%]
test/test_legend_line_scatter.py . [ 54%]
test/test_legends.py . [ 55%]
test/test_legends2.py . [ 56%]
test/test_line_collection.py . [ 57%]
test/test_line_color_marker.py . [ 58%]
test/test_line_dashes.py . [ 59%]
test/test_line_set_data.py . [ 60%]
test/test_loglogplot.py . [ 61%]
test/test_logplot.py . [ 62%]
test/test_logplot_base.py F [ 63%]
test/test_marker.py . [ 64%]
test/test_noise.py . [ 65%]
test/test_noise2.py . [ 66%]
test/test_pandas_dataframe.py F [ 67%]
test/test_patch_styles.py . [ 68%]
test/test_patches.py . [ 69%]
test/test_quadmesh.py . [ 70%]
test/test_readme.py . [ 71%]
test/test_rotated_labels.py ................... [ 90%]
test/test_scatter.py . [ 91%]
test/test_scatter_colormap.py . [ 92%]
test/test_sharex_and_y.py . [ 93%]
test/test_steps.py . [ 94%]
test/test_subplot4x4.py . [ 95%]
test/test_subplots.py . [ 96%]
test/test_text_overlay.py . [ 97%]
test/test_tick_positions.py . [ 98%]
test/test_viridis.py . [100%]
========================================================================================== FAILURES ===========================================================================================
____________________________________________________________________________________________ test _____________________________________________________________________________________________
def test():
> assert_equality(plot, __file__[:-3] + "_reference.tex")
/home/$USER/src/tikzplotlib/test/test_logplot_base.py:18:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/$USER/src/tikzplotlib/test/helpers.py:36: in assert_equality
plot()
/home/$USER/src/tikzplotlib/test/test_logplot_base.py:10: in plot
ax.semilogy(a, color="blue", lw=0.25, base=2)
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_axes.py:1876: in semilogy
l = self.plot(*args, **kwargs)
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_axes.py:1647: in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_base.py:216: in __call__
yield from self._plot_args(this, kwargs)
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_base.py:364: in _plot_args
for j in range(max(ncx, ncy))]
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_base.py:364: in <listcomp>
for j in range(max(ncx, ncy))]
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/axes/_base.py:255: in _makeline
seg = mlines.Line2D(x, y, **kw)
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/lines.py:400: in __init__
self.update(kwargs)
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/artist.py:1006: in update
ret = [_update_property(self, k, v) for k, v in props.items()]
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/artist.py:1006: in <listcomp>
ret = [_update_property(self, k, v) for k, v in props.items()]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <matplotlib.lines.Line2D object at 0x7f00ea8af780>, k = 'base', v = 2
def _update_property(self, k, v):
"""Sorting out how to update property (setter or setattr).
Parameters
----------
k : str
The name of property to update
v : obj
The value to assign to the property
Returns
-------
ret : obj or None
If using a `set_*` method return it's return, else None.
"""
k = k.lower()
# white list attributes we want to be able to update through
# art.update, art.set, setp
if k in {'axes'}:
return setattr(self, k, v)
else:
func = getattr(self, 'set_' + k, None)
if not callable(func):
raise AttributeError('{!r} object has no property {!r}'
> .format(type(self).__name__, k))
E AttributeError: 'Line2D' object has no property 'base'
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/matplotlib/artist.py:1002: AttributeError
____________________________________________________________________________________________ test _____________________________________________________________________________________________
def test():
> assert_equality(plot, __file__[:-3] + "_reference.tex")
/home/$USER/src/tikzplotlib/test/test_pandas_dataframe.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
plot = <function plot at 0x7f00f42df158>, filename = '/home/$USER/src/tikzplotlib/test/test_pandas_dataframe_reference.tex', assert_compilation = True, flavor = 'latex'
extra_get_tikz_code_args = {}
code = '\\begin{tikzpicture}\n\n\\definecolor{color0}{rgb}{0.12156863,0.46666667,0.70588235}\n\n\\begin{axis}[\nlog basis y={...rk=*, mark size=3, mark options={solid}, only marks]\ntable {%\n0 1\n1 2\n2 3\n};\n\\end{axis}\n\n\\end{tikzpicture}\n'
this_dir = '/home/$USER/src/tikzplotlib/test', f = <_io.TextIOWrapper name='/home/$USER/src/tikzplotlib/test/test_pandas_dataframe_reference.tex' mode='r' encoding='utf-8'>
reference = '\\begin{tikzpicture}\n\n\\definecolor{color0}{rgb}{0.12156863,0.46666667,0.70588235}\n\n\\begin{axis}[\ntick align=ou...rk=*, mark size=3, mark options={solid}, only marks]\ntable {%\n0 1\n1 2\n2 3\n};\n\\end{axis}\n\n\\end{tikzpicture}\n'
def assert_equality(
plot, filename, assert_compilation=True, flavor="latex", **extra_get_tikz_code_args
):
plot()
code = tikzplotlib.get_tikz_code(
include_disclaimer=False,
float_format=".8g",
flavor=flavor,
**extra_get_tikz_code_args,
)
plt.close()
this_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(this_dir, filename), encoding="utf-8") as f:
reference = f.read()
> assert reference == code, _unidiff_output(reference, code)
E AssertionError: ---
E +++
E @@ -3,6 +3,7 @@
E \definecolor{color0}{rgb}{0.12156863,0.46666667,0.70588235}
E
E \begin{axis}[
E +log basis y={10},
E tick align=outside,
E tick pos=left,
E x grid style={white!69.019608!black},
E @@ -11,7 +12,8 @@
E xtick={0,1,2},
E xticklabels={one,two,three},
E y grid style={white!69.019608!black},
E -ymin=0.9, ymax=3.1,
E +ymin=0.94655082, ymax=3.1694019,
E +ymode=log,
E ytick style={color=black}
E ]
E \addplot [semithick, color0, mark=*, mark size=3, mark options={solid}, only marks]
/home/$USER/src/tikzplotlib/test/helpers.py:48: AssertionError
====================================================================================== warnings summary =======================================================================================
test/test_cleanfigure.py::Test_plottypes::test_logplot
test/test_cleanfigure.py::Test_plottypes::test_semilogplot
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/tikzplotlib/_cleanfigure.py:610: RuntimeWarning: invalid value encountered in log10
xData = np.log10(xData)
test/test_cleanfigure.py::Test_plottypes::test_logplot
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/tikzplotlib/_cleanfigure.py:613: RuntimeWarning: invalid value encountered in log10
yData = np.log10(yData)
test/test_cleanfigure.py::Test_plottypes::test_contour3D
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
return array(a, dtype, copy=False, order=order, subok=True)
test/test_hatch.py::test
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/tikzplotlib/_hatches.py:69: UserWarning: tikzplotlib: Hatch '//' cannot be rendered. Only single character hatches are supported, e.g., {'/', '\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}. Hatch '/' will be used.
+ f"Hatch '{hatch[0]}' will be used."
test/test_hatch.py::test
/home/$USER/src/tikzplotlib/.tox/py3/lib/python3.7/site-packages/tikzplotlib/_hatches.py:76: UserWarning: tikzplotlib: The hatches ['o', 'O'] do not have good PGF counterparts.
+ " counterparts."
test/test_legend_best_location.py::test
/home/$USER/src/tikzplotlib/test/test_legend_best_location.py:56: UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x7f00ea8a5e80>, <matplotlib.lines.Line2D object at 0x7f00ea8af6d8>] instances.
A proxy artist may be used instead.
See: http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
axes[8].legend((loc,), ("C",), loc=0)
test/test_legend_best_location.py::test
/home/$USER/src/tikzplotlib/test/test_legend_best_location.py:56: UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x7f00eb0d2630>, <matplotlib.lines.Line2D object at 0x7f00eb4097f0>] instances.
A proxy artist may be used instead.
See: http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists
axes[8].legend((loc,), ("C",), loc=0)
-- Docs: https://docs.pytest.org/en/latest/warnings.html
----------- coverage: platform linux, python 3.7.2-final-0 -----------
Name Stmts Miss Cover
--------------------------------------------------------------------------------------
.tox/py3/lib/python3.7/site-packages/tikzplotlib/__about__.py 8 2 75%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/__init__.py 4 0 100%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_axes.py 429 94 78%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_cleanfigure.py 475 30 94%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_color.py 29 0 100%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_files.py 21 3 86%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_hatches.py 28 3 89%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_image.py 25 1 96%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_legend.py 77 6 92%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_line2d.py 165 8 95%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_markers.py 21 3 86%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_patch.py 104 0 100%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_path.py 193 20 90%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_quadmesh.py 23 0 100%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_save.py 175 19 89%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_text.py 150 24 84%
.tox/py3/lib/python3.7/site-packages/tikzplotlib/_util.py 21 0 100%
--------------------------------------------------------------------------------------
TOTAL 1948 213 89%
Coverage XML written to file coverage.xml
=================================================================================== short test summary info ===================================================================================
FAILED test/test_logplot_base.py::test - AttributeError: 'Line2D' object has no property 'base'
FAILED test/test_pandas_dataframe.py::test - AssertionError: ---
==================================================================== 2 failed, 96 passed, 8 warnings in 161.17s (0:02:41) =====================================================================
ERROR: InvocationError for command /home/$USER/src/tikzplotlib/.tox/py3/bin/pytest --cov .tox/py3/lib/python3.7/site-packages/tikzplotlib --cov-report xml --cov-report term (exited with code 1)
___________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR: py3: commands failed
General question: Should tikzplotlib support older version of matplotlib?
More recent versions are more important, so if we have to break one, break the older one. If there's a PR that adds support for an older version without breaking the newer ones: Great.
I'm inclined to close this issue because I will not work on it. PRs are very welcome though.
In fact, the trivial solution to this issue is to raise the version requirement for matplotlib in setup.cfg
to >= 3.3.0
(now it its 1.4.0)
Line 31 in b6adba9
Well, most of tpl will continue to work for versions prior to it, but it'd be okay with a PR raising the requirements, too.
Yes, I agree.
Fixing it for matplotlib 3.2.2 shouldn't be too much work. Unfortunately, I'm a bit busy right now. So don't expect a PR soon.
Sure, whenever works.