Skip to content

v2.11.0

Choose a tag to compare

@roytsmart roytsmart released this 21 Sep 21:30
· 22 commits to main since this release
429698f

Python 3.12

This release requires Python 3.12, where v2.10.0 asked only for 3.10 (#123). Installing on 3.10 or 3.11 now resolves to v2.10.0 rather than failing, so nothing breaks, but those interpreters stop receiving new versions. The test matrix runs every supported version on all three operating systems, 3.12 through 3.14 (#243).

Units in plotting

named_arrays.plt.pcolormesh could not take astropy.units.Quantity coordinates at all: its grid arithmetic does not survive them, and a mesh containing NaNs failed even with astropy.visualization.quantity_support enabled, since the colour normalization cannot handle a masked Quantity. The same survey found stairs, imshow's extent, axvline, axhline, axvspan, axhspan, set_xlim and set_ylim rejecting one as well, while plot, scatter and fill accepted one only because matplotlib quietly dropped the unit (#244).

Every function in named_arrays.plt which draws, or sets a coordinate, now enables quantity_support on its first use and leaves it on. A Quantity is converted to the unit of its axis and labels that axis, a later plot on the same axes is converted to the unit already recorded, and an incompatible unit raises rather than drawing mismatched numbers.

This is a behaviour change. Code which mixed incompatible units on one axes drew silently before and raises now. The quantity_support() call disappears from the examples throughout the documentation, since it is no longer needed.

The colours of matplotlib carry no unit, so mesh and image data are still drawn as bare values in their own unit, with vmin and vmax converted to that unit first.

Integrating and differentiating

numpy.trapezoid, numpy.average and numpy.gradient are supported by scalars, uncertain scalars, vectors and matrices (#246). Each follows the pattern of numpy.diff: the scalar implementation broadcasts its arguments by axis name, uncertain scalars apply it to the nominal value and the distribution, and vectors apply it per component. trapezoid and gradient require axis, as numpy.roll does, since there is no positional order to work along.

Function arrays gain numpy.gradient through a new gradient method, the counterpart to the existing integrate (#247). The spacing that numpy.gradient takes as an argument is already present in a function array, so the derivative is that of the outputs with respect to the inputs. A vertex axis, where the inputs are bin edges, differentiates against the cell centres, and a vector input names the variable with component, as integrate does.

Unlike numpy.gradient, the coordinates may vary along axes other than the one being differentiated along (#250). That is what a distorted grid gives, and what the distribution of an uncertain coordinate always is, so numpy.gradient now accepts an uncertain coordinate where it previously raised and numpy.trapezoid did not. Calls that numpy can express take the same route as before and run at the same speed.

Other changes

  • Add PolarVectorArray, a 2D Cartesian vector given by its polar coordinates (#240).
  • Import heavy optional dependencies lazily, which cuts import named_arrays to roughly a quarter of its former cost (#242).
  • Keep the unit that the weights carry when resampling united values, which regrid_from_weights previously dropped (#249).
  • Fix numpy.count_nonzero, which was listed as supported but raised on every array type (#245).
  • Accept astropy.units.Quantity arguments in named_arrays.arange, which previously rejected them (#245).
  • Accept plain numbers as the coordinates of named_arrays.plt.text (#245).
  • Thread device through the regridding wrappers (#241).
  • Shorten the representation of a large array, and show its shape (#234).
  • Document which functions each array type supports, generated from the dispatch tables themselves (#238).