What’s New in Astropy 7.0?#


Astropy 7.0 is a major release that adds significant new functionality since the 6.1 release.

In particular, this release includes:

In addition to these major changes, Astropy v7.0 includes a large number of smaller improvements and bug fixes, which are described in the Full Changelog. By the numbers:

  • X issues have been closed since v6.0

  • X pull requests have been merged since v6.0

  • X distinct people have contributed code

Quantity.to_string supports formatter for formatting#

The to_string() method now supports a formatter parameter. This feature supports both Python’s format specification mini-language via format strings and custom formatting through callables. This enables users to have explicit and consistent control over the numerical representation of quantities, accommodating a wide range of formatting needs.

Previously, the method primarily relied on the precision parameter for format control, which dictated the number of significant digits and did not provide much freedom in the latex format.


>>> from astropy import units as u
>>> q = u.Quantity(123.456, u.m)
>>> custom_format = lambda x: f"\\approx {float(x):.1f}"
>>> q.to_string(formatter=custom_format, format='latex')
'$\\approx 123.5 \\; \\mathrm{m}$'
>>> q.to_string(formatter='.3e', format='latex')
'$1.235 \\times 10^{2} \\; \\mathrm{m}$'
>>> q.to_string(precision=3, format='latex')
'$123 \\; \\mathrm{m}$'

Change default type for meta attribute to dict and update ECSV writer#

We have changed the default type for the meta attribute in Table and Column (and subclasses) from OrderedDict to dict. Since Python 3.8 the dict class is ordered by default, so there is no need to use OrderedDict.

In addition, the ECSV table writer in ASCII Tables (astropy.io.ascii) was updated to consistently write the meta attribute as an ordered map using the !!omap tag. This convention conforms to the ECSV specification and is supported by existing ECSV readers. Previously the meta attribute could be written as an ordinary YAML map, which is not guaranteed to preserve the order of the keys.

Full change log#

To see a detailed list of all changes in version v7.0, including changes in API, please see the Full Changelog.