Source: gammapy Version: 1.1-5 Severity: normal gammapy is failing tests against matplotlib 3.8 from experimental
Possibly astropy is at fault rather than gammapy. 237s _____________________________ test_plot_at_energy ______________________________ 237s 237s self = <Quantity 1. 1 / (GeV s sr)>, unit = Unit(dimensionless) 237s equivalencies = [] 237s 237s def to_value(self, unit=None, equivalencies=[]): 237s """ 237s The numerical value, possibly in a different unit. 237s 237s Parameters 237s ---------- 237s unit : unit-like, optional 237s The unit in which the value should be given. If not given or `None`, 237s use the current unit. 237s 237s equivalencies : list of tuple, optional 237s A list of equivalence pairs to try if the units are not directly 237s convertible (see :ref:`astropy:unit_equivalencies`). If not provided 237s or ``[]``, class default equivalencies will be used (none for 237s `~astropy.units.Quantity`, but may be set for subclasses). 237s If `None`, no equivalencies will be applied at all, not even any 237s set globally or within a context. 237s 237s Returns 237s ------- 237s value : ndarray or scalar 237s The value in the units specified. For arrays, this will be a view 237s of the data if no unit conversion was necessary. 237s 237s See Also 237s -------- 237s to : Get a new instance in a different unit. 237s """ 237s if unit is None or unit is self.unit: 237s value = self.view(np.ndarray) 237s elif not self.dtype.names: 237s # For non-structured, we attempt a short-cut, where we just get 237s # the scale. If that is 1, we do not have to do anything. 237s unit = Unit(unit) 237s # We want a view if the unit does not change. One could check 237s # with "==", but that calculates the scale that we need anyway. 237s # TODO: would be better for `unit.to` to have an in-place flag. 237s try: 237s > scale = self.unit._to(unit) 237s 237s /usr/lib/python3/dist-packages/astropy/units/quantity.py:987: 237s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 237s 237s self = Unit("1 / (GeV s sr)"), other = Unit(dimensionless) 237s 237s def _to(self, other): 237s """ 237s Returns the scale to the specified unit. 237s 237s See `to`, except that a Unit object should be given (i.e., no 237s string), and that all defaults are used, i.e., no 237s equivalencies and value=1. 237s """ 237s # There are many cases where we just want to ensure a Quantity is 237s # of a particular unit, without checking whether it's already in 237s # a particular unit. If we're being asked to convert from a unit 237s # to itself, we can short-circuit all of this. 237s if self is other: 237s return 1.0 237s 237s # Don't presume decomposition is possible; e.g., 237s # conversion to function units is through equivalencies. 237s if isinstance(other, UnitBase): 237s self_decomposed = self.decompose() 237s other_decomposed = other.decompose() 237s 237s # Check quickly whether equivalent. This is faster than 237s # `is_equivalent`, because it doesn't generate the entire 237s # physical type list of both units. In other words it "fails 237s # fast". 237s if self_decomposed.powers == other_decomposed.powers and all( 237s self_base is other_base 237s for (self_base, other_base) in zip( 237s self_decomposed.bases, other_decomposed.bases 237s ) 237s ): 237s return self_decomposed.scale / other_decomposed.scale 237s 237s > raise UnitConversionError(f"'{self!r}' is not a scaled version of '{other!r}'") 237s E astropy.units.core.UnitConversionError: 'Unit("1 / (GeV s sr)")' is not a scaled version of 'Unit(dimensionless)' 237s 237s /usr/lib/python3/dist-packages/astropy/units/core.py:1160: UnitConversionError 237s 237s During handling of the above exception, another exception occurred: 237s 237s self = <Quantity 1. 1 / (GeV s sr)> 237s 237s def __float__(self): 237s try: 237s > return float(self.to_value(dimensionless_unscaled)) 237s 237s /usr/lib/python3/dist-packages/astropy/units/quantity.py:1355: 237s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 237s /usr/lib/python3/dist-packages/astropy/units/quantity.py:990: in to_value 237s value = self._to_value(unit, equivalencies) 237s /usr/lib/python3/dist-packages/astropy/units/quantity.py:896: in _to_value 237s return self.unit.to( 237s /usr/lib/python3/dist-packages/astropy/units/core.py:1196: in to 237s return self._get_converter(Unit(other), equivalencies)(value) 237s /usr/lib/python3/dist-packages/astropy/units/core.py:1125: in _get_converter 237s raise exc 237s /usr/lib/python3/dist-packages/astropy/units/core.py:1108: in _get_converter 237s return self._apply_equivalencies( 237s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 237s 237s self = Unit("1 / (GeV s sr)"), unit = Unit("1 / (GeV s sr)") 237s other = Unit(dimensionless), equivalencies = [] 237s 237s def _apply_equivalencies(self, unit, other, equivalencies): 237s """ 237s Internal function (used from `_get_converter`) to apply 237s equivalence pairs. 237s """ 237s 237s def make_converter(scale1, func, scale2): 237s def convert(v): 237s return func(_condition_arg(v) / scale1) * scale2 237s 237s return convert 237s 237s for funit, tunit, a, b in equivalencies: 237s if tunit is None: 237s ratio = other.decompose() / unit.decompose() 237s try: 237s ratio_in_funit = ratio.decompose([funit]) 237s return make_converter(ratio_in_funit.scale, a, 1.0) 237s except UnitsError: 237s pass 237s else: 237s try: 237s scale1 = funit._to(unit) 237s scale2 = tunit._to(other) 237s return make_converter(scale1, a, scale2) 237s except UnitsError: 237s pass 237s try: 237s scale1 = tunit._to(unit) 237s scale2 = funit._to(other) 237s return make_converter(scale1, b, scale2) 237s except UnitsError: 237s pass 237s 237s def get_err_str(unit): 237s unit_str = unit.to_string("unscaled") 237s physical_type = unit.physical_type 237s if physical_type != "unknown": 237s unit_str = f"'{unit_str}' ({physical_type})" 237s else: 237s unit_str = f"'{unit_str}'" 237s return unit_str 237s 237s unit_str = get_err_str(unit) 237s other_str = get_err_str(other) 237s 237s > raise UnitConversionError(f"{unit_str} and {other_str} are not convertible") 237s E astropy.units.core.UnitConversionError: '1 / (GeV s sr)' and '' (dimensionless) are not convertible 237s 237s /usr/lib/python3/dist-packages/astropy/units/core.py:1086: UnitConversionError 237s 237s During handling of the above exception, another exception occurred: 237s 237s bkg_3d = <gammapy.irf.background.Background3D object at 0x7f9d2c4f6240> 237s 237s def test_plot_at_energy(bkg_3d): 237s with mpl_plot_check(): 237s > bkg_3d.plot_at_energy(energy=[5] * u.TeV) 237s 237s /usr/lib/python3/dist-packages/gammapy/irf/tests/test_background.py:136: 237s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 237s /usr/lib/python3/dist-packages/gammapy/irf/background.py:211: in plot_at_energy 237s cbar = ax.figure.colorbar(caxes, ax=ax, label=label, fraction=cfraction) 237s /usr/lib/python3/dist-packages/matplotlib/figure.py:1310: in colorbar 237s cb = cbar.Colorbar(cax, mappable, **{ 237s /usr/lib/python3/dist-packages/matplotlib/colorbar.py:395: in __init__ 237s self._reset_locator_formatter_scale() 237s /usr/lib/python3/dist-packages/matplotlib/colorbar.py:1159: in _reset_locator_formatter_scale 237s self._process_values() 237s /usr/lib/python3/dist-packages/matplotlib/colorbar.py:1093: in _process_values 237s self.norm.vmin, self.norm.vmax = mtransforms.nonsingular( 237s /usr/lib/python3/dist-packages/matplotlib/transforms.py:2855: in nonsingular 237s vmin, vmax = map(float, [vmin, vmax]) 237s _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 237s 237s self = <Quantity 1. 1 / (GeV s sr)> 237s 237s def __float__(self): 237s try: 237s return float(self.to_value(dimensionless_unscaled)) 237s except (UnitsError, TypeError): 237s > raise TypeError( 237s "only dimensionless scalar quantities can be " 237s "converted to Python scalars" 237s ) 237s E TypeError: only dimensionless scalar quantities can be converted to Python scalars 237s 237s /usr/lib/python3/dist-packages/astropy/units/quantity.py:1357: TypeError