BUG: plotting with Numpy array subclasses is slow with Matplotlib 3.1.0 (regression) #14274
Labels
Release critical
For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
topic: units and array ducktypes
Milestone
Bug summary
Astropy implements a
ConversionInterface
so as to be able to plot quantities with units (represented by the astropy Quantity class, which is a Numpy array subclass). However, this functionality is broken with Matplotlib 3.1 as it looks like Matplotlib now tries to iterate over every element of the array we are trying to plot.Code for reproduction
Actual outcome
Python hangs.
Expected outcome
This was previously very efficient.
The commit that broke this was 9eac832 (sorry @jklymak!) - and in particular the issue is that Quantity is an instance of
collections.abc.Iterable
, so the first 'if' statement doesn't get executed and instead Matplotlib iterates over all values. Actually what is strange is that this should also cause slowdown for plain numpy arrays, which are also instances of Iterable, and this might happen, but isn't as noticeable. What is different here is that the Quantity initializer is slow enough that this is noticeable.We didn't notice this sooner as this was only really tested with large arrays in the docs, which aren't run against Matplotlib dev...
The text was updated successfully, but these errors were encountered: