Question: # do this here to prevent a series of complicated circular imports         from .builtin_frames import ITRS         return ITRS(x=self.x, y=self.y, z=self.z, obstime=obstime)        if location is None:            # No location provided, return geocentric ITRS coordinates            return ITRS(x=self.x, y=self.y, z=self.z, obstime=obstime)        else:            return ITRS(                self.x - location.x,                self.y - location.y,                self.z - location.z,                copy=False,                obstime=obstime,                location=location,            )      itrs = property(         get_itrs,


Question: """  # Import to register with the I/O machineryfrom . import cosmology, ecsv, html, mapping, model, row, table, yamlfrom . import cosmology, ecsv, html, mapping, model, row, table, yaml, latexdiff --git a/astropy/cosmology/io/latex.py b/astropy/cosmology/io/latex.pynew file mode 100644-- /dev/null++ b/astropy/cosmology/io/latex.py

Register Cosmology can now read and write to files. It would be nice to register with a method for exporting a Cosmology to a Latex table. There are good examples of IO with Cosmology at and documentation at I'm thinking the H0(..., format='latex')`.


Question: <ins>import astropy.units as ufrom astropy.cosmology.connect import readwrite_registryfrom astropy.cosmology.core import Cosmologyfrom astropy.cosmology.parameter import Parameterfrom astropy.table import QTablefrom .table import to_table_FORMAT_TABLE = {    "H0": "$$H_0$$",    "Om0": "$$\\Omega_{m,0}$$",    "Ode0": "$$\\Omega_{\\Lambda,0}$$",    "Tcmb0": "$$T_{0}$$",    "Neff": "$$N_{eff}$$",    "m_nu": "$$m_{nu}$$",    "Ob0": "$$\\Omega_{b,0}$$",    "w0": "$$w_{0}$$",    "wa": "$$w_{a}$$",    "wz": "$$w_{z}$$",    "wp": "$$w_{p}$$",    "zp": "$$z_{p}$$",}def write_latex(    cosmology, file, *, overwrite=False, cls=QTable, latex_names=True, **kwargs):    r"""Serialize the |Cosmology| into a LaTeX.    Parameters    ----------    cosmology : `~astropy.cosmology.Cosmology` subclass instance    file : path-like or file-like        Location to save the serialized cosmology.    overwrite : bool        Whether to overwrite the file, if it exists.    cls : type, optional keyword-only        Astropy :class:`~astropy.table.Table` (sub)class to use when writing.        Default is :class:`~astropy.table.QTable`.    latex_names : bool, optional keyword-only        Whether to use LaTeX names for the parameters. Default is `True`.    **kwargs        Passed to ``cls.write``    Raises    ------    TypeError        If kwarg (optional) 'cls' is not a subclass of `astropy.table.Table`    """    # Check that the format is 'latex' (or not specified)    format = kwargs.pop("format", "latex")    if format != "latex":        raise ValueError(f"format must be 'latex', not {format}")    # Set cosmology_in_meta as false for now since there is no metadata being kept    table = to_table(cosmology, cls=cls, cosmology_in_meta=False)    cosmo_cls = type(cosmology)    for name, col in table.columns.copy().items():        param = getattr(cosmo_cls, name, None)        if not isinstance(param, Parameter) or param.unit in (None, u.one):            continue        # Get column to correct unit        table[name] <<= param.unit    # Convert parameter names to LaTeX format    if latex_names:        new_names = [_FORMAT_TABLE.get(k, k) for k in cosmology.__parameters__]        table.rename_columns(cosmology.__parameters__, new_names)    table.write(file, overwrite=overwrite, format="latex", **kwargs)# ===================================================================# Registerreadwrite_registry.register_writer("latex", Cosmology, write_latex)</ins>


Question: warn_unknown_attrs("TABLE", extra.keys(), config, pos)      def __repr__(self):        return repr(self.to_table())        s = repr(self.to_table())        if s.startswith("<Table"):            s = "<VO" + s[1:]        return s      def __bytes__(self):         return bytes(self.to_table())

BUG: change representation of vs table.Table More often than not it's rather confusing (and annoying) that a VOTable and a Table look exactly the same, but obviously, they don't behave the same way and don't have the same methods available, etc. I would suggest to change the votable case of to something else, e.g. .


Question: raise ValueError("Cannot create index without at least one column")         elif len(columns) == 1:             col = columns[0]            row_index = Column(col.argsort())            row_index = Column(col.argsort(kind="stable"))             data = Table([col[row_index]])         else:             num_rows = len(columns[0])

TST: testtablegroupby[True] and testgroupbymasked[True] failed with numpy 1.25rc1 I see this in the predeps job that pulls in numpy 1.25rc1. Example log: Hard to discern between the other 100+ failures from and I do not understand why we didn't catch this earlier in devdeps. , does this look familiar to you? TST: testtablegroupby[True] and testgroupbymasked[True] failed with numpy 1.25rc1 I see this in the predeps job that pulls in numpy 1.25rc1. Example log: Hard to discern between the other 100+ failures from and I do not understand why we didn't catch this earlier in devdeps. , does this look familiar to you?


Question: try:                 lines = table[np.lexsort(sort_columns)]             except TypeError:  # arbitrary mixins might not work with lexsort                lines = table[table.argsort()]                lines = table[table.argsort(kind="stable")]             data = lines[lines.colnames[:-1]]             row_index = lines[lines.colnames[-1]] diff --git a/astropy/time/core.py b/astropy/time/core.py-- a/astropy/time/core.py++ b/astropy/time/core.py


Question: return dt.argmax(axis, out)     def argsort(self, axis=-1):    def argsort(self, axis=-1, kind="stable"):         """Returns the indices that would sort the time array.         This is similar to :meth:`~numpy.ndarray.argsort`, but adapted to ensure        that the full precision given by the two doubles ``jd1`` and ``jd2``        is used, and that corresponding attributes are copied.  Internally,        it uses :func:`~numpy.lexsort`, and hence no sort method can be chosen.        This is similar to :meth:`~numpy.ndarray.argsort`, but adapted to ensure that        the full precision given by the two doubles ``jd1`` and ``jd2`` is used, and        that corresponding attributes are copied.  Internally, it uses        :func:`~numpy.lexsort`, and hence no sort method can be chosen.        Parameters        ----------        axis : int, optional            Axis along which to sort. Default is -1, which means sort along the last            axis.        kind : 'stable', optional            Sorting is done with :func:`~numpy.lexsort` so this argument is ignored, but            kept for compatibility with :func:`~numpy.argsort`. The sorting is stable,            meaning that the order of equal elements is preserved.        Returns        -------        indices : ndarray            An array of indices that sort the time array.         """         # For procedure, see comment on argmin.         jd1, jd2 = self.jd1, self.jd2


Question: TypeError         If kwarg (optional) 'cls' is not a subclass of `astropy.table.Table`     """    # Check that the format is 'latex' (or not specified)    # Check that the format is 'latex', 'ascii.latex' (or not specified)     format = kwargs.pop("format", "latex")    if format != "latex":        raise ValueError(f"format must be 'latex', not {format}")    if format not in ("latex", "ascii.latex"):        raise ValueError(f"format must be 'latex' or 'ascii.latex', not {format}")      # Set cosmology_in_meta as false for now since there is no metadata being kept     table = to_table(cosmology, cls=cls, cosmology_in_meta=False)

Add registration label ‘’ to Cosmology IO The Cosmology write methods that leverage Table should have the same keys. Table has both “latex” and “”, so too should Cosmology. Register the method a second time, under No response


Question: # Register  readwrite_registry.register_writer("latex", Cosmology, write_latex)<ins>readwrite_registry.register_writer("ascii.latex", Cosmology, write_latex)</ins>


Question: )         )     # TODO: don't use represent_mixins_as_columns here, but instead ensure that    # keys_sort.argsort(kind="stable") works for all columns (including mixins).     # If there is not already an available index and table_keys is a Table then ensure     # that all cols (including mixins) are in a form that can sorted with the code below.     if not table_index and isinstance(table_keys, Table):        table_keys = represent_mixins_as_columns(table_keys)        table_keys_sort = represent_mixins_as_columns(table_keys)    else:        table_keys_sort = table_keys      # Get the argsort index `idx_sort`, accounting for particulars     try:

QTable: Group keys don't have a unit When grouping a QTable with a column that contains a quantity, the keys only contain a float with a value, but not the full quantity: The keys should be complete, i.e. for a quantity column it should be a quantity with the proper unit. No response Linux-6.1.0-9-amd64-x86_64-with-glibc2.36 (Debian bookworm) Python 3.11.4 (main, Jun 7 2023, 10:13:09) [GCC 12.2.0] astropy 5.2.1 (also checked with 5.3) Numpy 1.24.2 pyerfa 2.0.0.3 Scipy 1.10.1 Matplotlib 3.6.3


Question: if table_index is not None:             idx_sort = table_index.sorted_data()         else:            idx_sort = table_keys.argsort(kind="mergesort")            idx_sort = table_keys_sort.argsort(kind="stable")         stable_sort = True     except TypeError:        # TODO: is this still needed?         # Some versions (likely 1.6 and earlier) of numpy don't support         # 'mergesort' for all data types.  MacOSX (Darwin) doesn't have a stable         # sort by default, nor does Windows, while Linux does (or appears to).        idx_sort = table_keys.argsort()        idx_sort = table_keys_sort.argsort()         stable_sort = platform.system() not in ("Darwin", "Windows")      # Finally do the actual sort of table_keys values


Question: from .serialize import represent_mixins_as_columns     from .table import Table     if isinstance(keys, Table):        keys = represent_mixins_as_columns(keys)        keys = keys.as_array()    # TODO: don't use represent_mixins_as_columns here, but instead ensure that    # keys_sort.argsort(kind="stable") works for all columns (including mixins).     if not isinstance(keys, np.ndarray):        raise TypeError(f"Keys input must be numpy array, but got {type(keys)}")    if isinstance(keys, Table):        keys_sort = represent_mixins_as_columns(keys)    else:        keys_sort = keys     if len(keys) != len(column):    if len(keys_sort) != len(column):         raise ValueError(             "Input keys array length {} does not match column length {}".format(                 len(keys), len(column)             )         )     idx_sort = keys.argsort()    try:        idx_sort = keys_sort.argsort(kind="stable")    except AttributeError:        raise TypeError(            f"keys input ({keys.__class__.__name__}) must have an `argsort` method"        )     keys = keys[idx_sort]      # Get all keys


Question: The scaling of the energy density of dark energy with redshift.             Returns `float` if the input is scalar.         References        ----------        .. [1] Linder, E. (2003). Exploring the Expansion History of the Universe.               Physics Review Letters, 90(9), 091301.         Notes         -----         The scaling factor, I, is defined by :math:`\rho(z) = \rho_0 I`,        and in this case is given by        and in this case is given by ([1]_)          .. math::             I = \left(1 + z\right)^{3 \left(1 + w_0 - w_z\right)}                     \exp \left(-3 w_z z\right)                     \exp \left(3 w_z z\right)         """         z = aszarr(z)        zp1 = z + 1.0  # (converts z [unit] -> z [dimensionless])        return zp1 ** (3.0 * (1.0 + self._w0 - self._wz)) * exp(-3.0 * self._wz * z)        return (z + 1.0) ** (3.0 * (1.0 + self._w0 - self._wz)) * exp(            3.0 * self._wz * z        )   class Flatw0wzCDM(FlatFLRWMixin, w0wzCDM):

Error in distance calculations for w0wz Cosmologies I believe that the equation used to calculate the dedensityscale in is incorrect. Line 205 has After manually calculating the integral/checking wolfram, I don't think it should be a negative in the exponent and should read: package from '...' run '...' error occurs. import platform; print(platform.platform()) import sys; print("Python", sys.version) import astropy; print("astropy", astropy.version) import numpy; print("Numpy", numpy.version) import erfa; print("pyerfa", erfa.version) import scipy; print("Scipy", scipy.version) import matplotlib; print("Matplotlib", matplotlib.version)


Question: elif self.mask is None and operand is not None:             # Make a copy so there is no reference in the result.             return deepcopy(operand.mask)        elif operand is None:        elif operand.mask is None:             return deepcopy(self.mask)         else:            # Now lets calculate the resulting mask (operation enforces copy)            # Now let's calculate the resulting mask (operation enforces copy)             return handle_mask(self.mask, operand.mask, **kwds)      def _arithmetic_wcs(self, operation, operand, compare_wcs, **kwds):

In v5.3, NDDataRef mask propagation fails when one of the operand does not have a mask This applies to v5.3. It looks like when one of the operand does not have a mask, the mask propagation when doing arithmetic, in particular with fails. This is not a problem in v5.2. I don't know enough about how all that works, but it seems from the error that the operand without a mask is set as a mask of None's and then the bitwise_or tries to operate on an integer and a None and fails. When one of the operand does not have mask, the mask that exists should just be copied over to the output. Or whatever was done in that situation in v5.2 where there's no problem. This is with v5.3. With v5.2, there are no errors. import sys; print("Python", sys.version) Python 3.10.11 (main, May 10 2023, 19:07:22) [Clang 14.0.6 ] import astropy; print("astropy", astropy.version) astropy 5.3 import numpy; print("Numpy", numpy.version) Numpy 1.24.3 import erfa; print("pyerfa", erfa.version) pyerfa 2.0.0.3 import scipy; print("Scipy", scipy.version) Scipy 1.10.1 import matplotlib; print("Matplotlib", matplotlib.version) Matplotlib 3.7.1


Question: # Replace exponent separator in floating point numbers         if 'D' in format:            output_field.replace(encode_ascii('E'), encode_ascii('D'))            output_field[:] = output_field.replace(b'E', b'D')   def _get_recarray_field(array, key):

Possible bug in related to D exponents I came across the following code in : I think this may be incorrect because as far as I can tell (it returns a copy). Commenting out this code doesn't cause any tests to fail so I think this code isn't being tested anyway.


Question: <Quantity 0.510998927603161 MeV>  """import itertoolsimport inspectfrom contextlib import contextmanager  # Hack to make circular imports with units work try:

Context manager for constant versions For some use cases it would be helpful to have a context manager to set the version set of the constants. E.g., something like `


Question: except ImportError:     pass from .constant import Constant, EMConstantfrom . import sifrom . import cgsfrom . import codata2014, iau2015from .constant import Constant, EMConstant  # noqafrom . import si  # noqafrom . import cgs  # noqafrom . import codata2014, iau2015  # noqafrom . import utils as _utils  # for updating the constants module docstring _lines = [


Question: '========== ============== ================ =========================', ] for _nm, _c in itertools.chain(sorted(vars(codata2014).items()),                               sorted(vars(iau2015).items())):    if isinstance(_c, Constant) and _c.abbrev not in locals():        locals()[_c.abbrev] = _c.__class__(_c.abbrev, _c.name, _c.value,                                           _c._unit_string, _c.uncertainty,                                           _c.reference)        _lines.append('{0:^10} {1:^14.9g} {2:^16} {3}'.format(            _c.abbrev, _c.value, _c._unit_string, _c.name))# NOTE: Update this when default changes._utils._set_c(codata2014, iau2015, inspect.getmodule(inspect.currentframe()),              not_in_module_only=True, doclines=_lines, set_class=True)  _lines.append(_lines[1])  if __doc__ is not None:     __doc__ += '\n'.join(_lines) del _lines, _nm, _c# TODO: Re-implement in a way that is more consistent with astropy.units.#       See https://github.com/astropy/astropy/pull/7008 discussions.@contextmanagerdef set_enabled_constants(modname):    """    Context manager to temporarily set values in the ``constants``    namespace to an older version.    See :ref:`astropy-constants-prior` for usage.    Parameters    ----------    modname : {'astropyconst13'}        Name of the module containing an older version.    """    # Re-import here because these were deleted from namespace on init.    import inspect    import warnings    from . import utils as _utils    # NOTE: Update this when default changes.    if modname == 'astropyconst13':        from .astropyconst13 import codata2010 as codata        from .astropyconst13 import iau2012 as iaudata    else:        raise ValueError(            'Context manager does not currently handle {}'.format(modname))    module = inspect.getmodule(inspect.currentframe())    # Ignore warnings about "Constant xxx already has a definition..."    with warnings.catch_warnings():        warnings.simplefilter('ignore')        _utils._set_c(codata, iaudata, module,                      not_in_module_only=False, set_class=True)    try:        yield    finally:        with warnings.catch_warnings():            warnings.simplefilter('ignore')            # NOTE: Update this when default changes.            _utils._set_c(codata2014, iau2015, module,                          not_in_module_only=False, set_class=True)# Clean up namespacedel inspectdel contextmanagerdel _utilsdel _linesdiff --git a/astropy/constants/astropyconst13.py b/astropy/constants/astropyconst13.py-- a/astropy/constants/astropyconst13.py++ b/astropy/constants/astropyconst13.py


Question: See :mod:`astropy.constants` for a complete listing of constants defined in Astropy. """import itertoolsfrom .constant import Constantimport inspectfrom . import utils as _utils from . import codata2010, iau2012 for _nm, _c in itertools.chain(sorted(vars(codata2010).items()),                               sorted(vars(iau2012).items())):    if (isinstance(_c, Constant) and _c.abbrev not in locals()):        locals()[_c.abbrev] = _c_utils._set_c(codata2010, iau2012, inspect.getmodule(inspect.currentframe()))# Clean up namespacedel inspectdel _utilsdiff --git a/astropy/constants/astropyconst20.py b/astropy/constants/astropyconst20.py-- a/astropy/constants/astropyconst20.py++ b/astropy/constants/astropyconst20.py


Question: Astronomical and physics constants for Astropy v2.0.  See :mod:`astropy.constants` for a complete listing of constants defined in Astropy. """import itertoolsfrom .constant import Constantimport inspectfrom . import utils as _utils from . import codata2014, iau2015 for _nm, _c in itertools.chain(sorted(vars(codata2014).items()),                               sorted(vars(iau2015).items())):    if (isinstance(_c, Constant) and _c.abbrev not in locals()):        locals()[_c.abbrev] = _c_utils._set_c(codata2014, iau2015, inspect.getmodule(inspect.currentframe()))# Clean up namespacedel inspectdel _utilsdiff --git a/astropy/constants/utils.py b/astropy/constants/utils.pynew file mode 100644-- /dev/null++ b/astropy/constants/utils.py


Question: <ins># Licensed under a 3-clause BSD style license - see LICENSE.rst"""Utility functions for ``constants`` sub-package."""import itertools__all__ = []def _get_c(codata, iaudata, module, not_in_module_only=True):    """    Generator to return a Constant object.    Parameters    ----------    codata, iaudata : obj        Modules containing CODATA and IAU constants of interest.    module : obj        Namespace module of interest.    not_in_module_only : bool        If ``True``, ignore constants that are already in the        namespace of ``module``.    Returns    -------    _c : Constant        Constant object to process.    """    from .constant import Constant    for _nm, _c in itertools.chain(sorted(vars(codata).items()),                                   sorted(vars(iaudata).items())):        if not isinstance(_c, Constant):            continue        elif (not not_in_module_only) or (_c.abbrev not in module.__dict__):            yield _cdef _set_c(codata, iaudata, module, not_in_module_only=True, doclines=None,           set_class=False):    """    Set constants in a given module namespace.    Parameters    ----------    codata, iaudata : obj        Modules containing CODATA and IAU constants of interest.    module : obj        Namespace module to modify with the given ``codata`` and ``iaudata``.    not_in_module_only : bool        If ``True``, constants that are already in the namespace        of ``module`` will not be modified.    doclines : list or `None`        If a list is given, this list will be modified in-place to include        documentation of modified constants. This can be used to update        docstring of ``module``.    set_class : bool        Namespace of ``module`` is populated with ``_c.__class__``        instead of just ``_c`` from :func:`_get_c`.    """    for _c in _get_c(codata, iaudata, module,                     not_in_module_only=not_in_module_only):        if set_class:            value = _c.__class__(_c.abbrev, _c.name, _c.value,                                 _c._unit_string, _c.uncertainty,                                 _c.reference)        else:            value = _c        setattr(module, _c.abbrev, value)        if doclines is not None:            doclines.append('{0:^10} {1:^14.9g} {2:^16} {3}'.format(                _c.abbrev, _c.value, _c._unit_string, _c.name))</ins>


Question: A "grab bag" of relatively small general-purpose utilities that don't have a clear module/package to live in. """<del></del> import abc import contextlib import difflib

InheritDocstrings metaclass doesn't work for properties Inside the InheritDocstrings metaclass it uses which returns for properties.


Question: from collections import defaultdict, OrderedDict  <del></del> __all__ = ['isiterable', 'silence', 'format_exception', 'NumpyRNGContext',            'find_api_page', 'is_path_hidden', 'walk_skip_hidden',            'JsonCustomEncoder', 'indent', 'InheritDocstrings',


Question: not key.startswith('_'))          for key, val in dct.items():            if (inspect.isfunction(val) and                is_public_member(key) and                val.__doc__ is None):            if ((inspect.isfunction(val) or inspect.isdatadescriptor(val)) and                    is_public_member(key) and                    val.__doc__ is None):                 for base in cls.__mro__[1:]:                     super_method = getattr(base, key, None)                     if super_method is not None:


Question: # Call the original function with any equivalencies in force.             with add_enabled_equivalencies(self.equivalencies):                 return_ = wrapped_function(*func_args, **func_kwargs)            if wrapped_signature.return_annotation is not inspect.Signature.empty:            if wrapped_signature.return_annotation not in (inspect.Signature.empty, None):                 return return_.to(wrapped_signature.return_annotation)             else:                 return return_

units.quantityinput decorator fails for constructors with type hinted return value -None I am using the decorator with typing hints for constructors, however when I add the correct return value for the constructor () then I get an exception, because has no attribute . The issue can be reproduced with the following file: which results in the following error: This has been tested on Fedora 27 with python 3.6.3, astropy 2.0.2 and numpy 1.13.3 all from Fedora's repository. The issue can be circumvented by not adding the return type typing hint. Unfortunately, then a static type checker cannot infer that this function returns nothing. Maybe the decorator could explicitly check whether None is returned and then omit the unit check.


Question: import copy import operatorfrom datetime import datetimefrom datetime import datetime, timedelta  import numpy as np

should support conversion to Because of the inheritance has a method which is useless. It should have a method which returns a object or objects. Conversion to (for ) and (for ) would also be great.


Question: other = getattr(other, out.scale)         else:             if other.scale is None:                    out._set_scale('tai')                out._set_scale('tai')             else:                 if self.scale not in TIME_TYPES[other.scale]:                     raise TypeError("Cannot add Time and TimeDelta instances "


Question: The allowed values for ``format`` can be listed with::        >>> list(TimeDelta.FORMATS)      ['sec', 'jd']      ['sec', 'jd', 'datetime']      Note that for time differences, the scale can be among three groups:     geocentric ('tai', 'tt', 'tcg'), barycentric ('tcb', 'tdb'), and rotational


Question: info = TimeDeltaInfo()      def __init__(self, val, val2=None, format=None, scale=None, copy=False):<ins>        if isinstance(val, timedelta) and not format:            format = 'datetime'</ins>         if isinstance(val, TimeDelta):             if scale is not None:                 self._set_scale(scale)


Question: out.SCALES = self.SCALES         return out     def to_datetime(self):        """        Convert to ``datetime.timedelta`` object.        """        tm = self.replicate(format='datetime')        return tm._shaped_like_input(tm._time.value)     def _set_scale(self, scale):         """         This is the key routine that actually does time scale conversions.diff --git a/astropy/time/formats.py b/astropy/time/formats.py-- a/astropy/time/formats.py++ b/astropy/time/formats.py


Question: 'TimeDeltaFormat', 'TimeDeltaSec', 'TimeDeltaJD',            'TimeEpochDateString', 'TimeBesselianEpochString',            'TimeJulianEpochString', 'TIME_FORMATS', 'TIME_DELTA_FORMATS',           'TimezoneInfo']           'TimezoneInfo', 'TimeDeltaDatetime']  __doctest_skip__ = ['TimePlotDate']


Question: unit = 1.  <ins>class TimeDeltaDatetime(TimeDeltaFormat, TimeUnique):    """Time delta in datetime.timedelta"""    name = 'datetime'    def _check_val_type(self, val1, val2):        # Note: don't care about val2 for this class        if not all(isinstance(val, datetime.timedelta) for val in val1.flat):            raise TypeError('Input values for {0} class must be '                            'datetime.timedelta objects'.format(self.name))        return val1, None    def set_jds(self, val1, val2):        self._check_scale(self._scale)  # Validate scale.        iterator = np.nditer([val1, None],                             flags=['refs_ok'],                             op_dtypes=[object] + [np.double])        for val, sec in iterator:            sec[...] = val.item().total_seconds()        self.jd1, self.jd2 = day_frac(iterator.operands[-1], 0.0,                                      divisor=erfa.DAYSEC)    @property    def value(self):        iterator = np.nditer([self.jd1 + self.jd2, None],                             flags=['refs_ok'],                             op_dtypes=[self.jd1.dtype] + [object])        for jd, out in iterator:            out[...] = datetime.timedelta(days=jd.item())        return self.mask_if_needed(iterator.operands[-1])</ins> from .core import Time, TIME_SCALES, TIME_DELTA_SCALES, ScaleValueError


Question: import inspect<ins>import re</ins> import types import importlib from distutils.version import LooseVersion

minversion failures The change in PR causes to fail in certain cases, e.g.: apparently because of a bug in LooseVersion (): Note that without the ".3" it doesn't fail: and using pkgresources.parseversion (which was removed) works: CC:


Question: else:         have_version = resolve_name(module.__name__, version_path) <ins>    # LooseVersion raises a TypeError when strings like dev, rc1 are part    # of the version number. Match the dotted numbers only. Regex taken    # from PEP440, https://www.python.org/dev/peps/pep-0440/, Appendix B    expr = '^([1-9]\\d*!)?(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))*'    m = re.match(expr, version)    if m:        version = m.group(0)</ins>     if inclusive:         return LooseVersion(have_version) >= LooseVersion(version)     else:


Question: # set up the weighting     mad = median_absolute_deviation(data, axis=axis)    if axis is None and mad == 0.:        return M  # return median if data is a constant array     if axis is not None:         mad = np.expand_dims(mad, axis=axis)        const_mask = (mad == 0.)        mad[const_mask] = 1.  # prevent divide by zero     u = d / (c * mad)      # now remove the outlier points

biweightlocation of a constant array returns nan Currently the robust mean estimator returns for an array with zero variance. eg: This is primarily because of a 0/0 division in the code (case when the calculated mad of array in denominator becomes zero). Wouldn't it be better to catch this special case and return the median, instead of returning nan?


Question: u = (1 - u ** 2) ** 2     u[mask] = 0 <ins>    # along the input axis if data is constant, d will be zero, thus    # the median value will be returned along that axis</ins>     return M.squeeze() + (d * u).sum(axis=axis) / u.sum(axis=axis)


Question: # set up the weighting     mad = median_absolute_deviation(data, axis=axis)    if axis is None and mad == 0.:        return 0.  # return zero if data is a constant array     if axis is not None:         mad = np.expand_dims(mad, axis=axis)        const_mask = (mad == 0.)        mad[const_mask] = 1.  # prevent divide by zero     u = d / (c * mad)      # now remove the outlier points


Question: # set up the weighting     mad = median_absolute_deviation(data, axis=1)<ins>    const_mask = (mad == 0.)    mad[const_mask] = 1.  # prevent divide by zero</ins>     u = (d.T / (c * mad)).T      # now remove the outlier points


Question: """          def _return_list_of_arrays(axes, origin):<ins>            if any([x.size == 0 for x in axes]):                return axes</ins>             try:                 axes = np.broadcast_arrays(*axes)             except ValueError:

Issue when passing empty lists/arrays to WCS transformations The following should not fail but instead should return empty lists/arrays:


Question: raise ValueError(                     "When providing two arguments, the array must be "                     "of shape (N, {0})".format(self.naxis))<ins>            if 0 in xy.shape:                return xy</ins>             if ra_dec_order and sky == 'input':                 xy = self._denormalize_sky(xy)             result = func(xy, origin)


Question: raise TypeError(                     "When providing two arguments, they must be "                     "(coords[N][{0}], origin)".format(self.naxis))            if self.naxis == 1 and len(xy.shape) == 1:            if xy.shape == () or len(xy.shape) == 1:                 return _return_list_of_arrays([xy], origin)             return _return_single_array(xy, origin)

Issue when transforming a single scalar coordinate with a 1D WCS The following example illustrates a bug when dealing with single scalar coordinates in 1D WCSes: - would you have a chance to look at this?


Question: __doctest_skip__ = ['WCS.all_world2pix'] <ins>NAXIS_DEPRECATE_MESSAGE = """Private attributes "_naxis1" and "naxis2" have been deprecated since v3.1.Instead use the "pixel_shape" property which returns a list of NAXISj keyword values."""</ins>  if _wcs is not None:     _parsed_version = _wcs.__version__.split('.')

Record data size in the WCS object It is clear that there are practical reasons to have a record of the original data size in the WCS object. This in the past has been recorded in public attributes and and subsequently in the private and . There's along thread on why this should or should not be done in . More recently expanded this attribute to more than 2 axes. It also broke the ability to set the private attributes which was subsequently fixed in as a stop gap measure. We need to fix this permanently starting with v 1.3. There are two proposed ways to do it. public attributes, populated by the FITS header keywords. a subclass of which adds those and leave the original WCS to represent strictly the FITS WCS standard and nothing more. Either way a deprecation process will accompany the change. The purpose of this issue is to collect votes. I don't want to start a new long discussion. Keep in mind that is available for reference and only share new arguments. Since 1.3 is approaching we need to make a fast decision. So please share your preference here and volunteer for the work if possible.


Question: try:                     # classes that inherit from WCS and define naxis1/2                     # do not require a header parameter                    naxis1 = self._naxis1                    naxis2 = self._naxis2                except AttributeError:                    naxis1, naxis2 = self.pixel_shape                except (AttributeError, TypeError):                     warnings.warn("Need a valid header in order to calculate footprint\n", AstropyUserWarning)                     return None             else:


Question: f.write(comments)             f.write('{}\n'.format(coordsys))             f.write('polygon(')            self.calc_footprint().tofile(f, sep=',')            f.write(') # color={0}, width={1:d} \n'.format(color, width))            ftpr = self.calc_footprint()            if ftpr is not None:                ftpr.tofile(f, sep=',')                f.write(') # color={0}, width={1:d} \n'.format(color, width))      @property     def _naxis1(self):        warnings.warn(NAXIS_DEPRECATE_MESSAGE, AstropyDeprecationWarning)         return self._naxis[0]      @_naxis1.setter     def _naxis1(self, value):        warnings.warn(NAXIS_DEPRECATE_MESSAGE, AstropyDeprecationWarning)         self._naxis[0] = value      @property     def _naxis2(self):        warnings.warn(NAXIS_DEPRECATE_MESSAGE, AstropyDeprecationWarning)         return self._naxis[1]      @_naxis2.setter     def _naxis2(self, value):        warnings.warn(NAXIS_DEPRECATE_MESSAGE, AstropyDeprecationWarning)         self._naxis[1] = value      def _get_naxis(self, header=None):


Question: frequency : `~astropy.units.Quantity` with spectral units         The observed `spectral` equivalent `~astropy.units.Unit` (e.g.,         frequency or wavelength)    T_cmb :  `~astropy.units.Quantity` with temperature units (default Planck15 value)        The CMB temperature at z=0    T_cmb :  `~astropy.units.Quantity` with temperature units or None        The CMB temperature at z=0.  If `None`, the default cosmology will be        used to get this temperature.      Notes     -----

Cosmologies used in equivalencies The thermodynamic temperature equivalency appears to default to the Planck 2015 cosmology value: whereas in the equivalency in , the default cosmology is used: and this is currently WMAP9. This seems inconsistent, so can we try and make things more consistent for the 3.1 release? (I see this as bug-like, so I think it can be addressed after feature freeze). Note that this is related to - if we change the default cosmology to Planck 2015, then we can change the equivalency to use the default cosmology without changing results (for now).


Question: Planck HFI 143 GHz::          >>> from astropy import units as u        >>> from astropy.cosmology import Planck15         >>> freq = 143 * u.GHz        >>> equiv = u.thermodynamic_temperature(freq)        >>> equiv = u.thermodynamic_temperature(freq, Planck15.Tcmb0)         >>> (1. * u.mK).to(u.MJy / u.sr, equivalencies=equiv)  # doctest: +FLOAT_CMP         <Quantity 0.37993172 MJy / sr>


Question: nu = frequency.to(si.GHz, spectral())      if T_cmb is None:        from ..cosmology import Planck15        T_cmb = Planck15.Tcmb0        from ..cosmology import default_cosmology        T_cmb = default_cosmology.get().Tcmb0      def f(nu, T_cmb=T_cmb):         x = _si.h * nu / _si.k_B / T_cmb


Question: def p_factor_fits(p):             '''             factor_fits : UINT power OPEN_PAREN signed_int CLOSE_PAREN                        | UINT power OPEN_PAREN UINT CLOSE_PAREN                         | UINT power signed_int                        | UINT power UINT                         | UINT SIGN UINT                         | UINT OPEN_PAREN signed_int CLOSE_PAREN             '''diff --git a/astropy/units/format/generic_parsetab.py b/astropy/units/format/generic_parsetab.py-- a/astropy/units/format/generic_parsetab.py++ b/astropy/units/format/generic_parsetab.py

FITS-standard unit parsing fails on some types of exponents Why don't these work: When these all do: The non-working versions give e.g.: which is not how I would interpret the . Tested on 2.0.7 and 3.0.3


Question: _lr_method = 'LALR' _lr_signature = 'DOUBLE_STAR STAR PERIOD SOLIDUS CARET OPEN_PAREN CLOSE_PAREN FUNCNAME UNIT SIGN UINT UFLOAT\n            main : product_of_units\n                 | factor product_of_units\n                 | factor product product_of_units\n                 | division_product_of_units\n                 | factor division_product_of_units\n                 | factor product division_product_of_units\n                 | inverse_unit\n                 | factor inverse_unit\n                 | factor product inverse_unit\n                 | factor\n            \n            division_product_of_units : division_product_of_units division product_of_units\n                                      | product_of_units\n            \n            inverse_unit : division unit_expression\n            \n            factor : factor_fits\n                   | factor_float\n                   | factor_int\n            \n            factor_float : signed_float\n                         | signed_float UINT signed_int\n                         | signed_float UINT power numeric_power\n            \n            factor_int : UINT\n                       | UINT signed_int\n                       | UINT power numeric_power\n                       | UINT UINT signed_int\n                       | UINT UINT power numeric_power\n            \n            factor_fits : UINT power OPEN_PAREN signed_int CLOSE_PAREN\n                        | UINT power signed_int\n                        | UINT SIGN UINT\n                        | UINT OPEN_PAREN signed_int CLOSE_PAREN\n            \n            product_of_units : unit_expression product product_of_units\n                             | unit_expression product_of_units\n                             | unit_expression\n            \n            unit_expression : function\n                            | unit_with_power\n                            | OPEN_PAREN product_of_units CLOSE_PAREN\n            \n            unit_with_power : UNIT power numeric_power\n                            | UNIT numeric_power\n                            | UNIT\n            \n            numeric_power : sign UINT\n                          | OPEN_PAREN paren_expr CLOSE_PAREN\n            \n            paren_expr : sign UINT\n                       | signed_float\n                       | frac\n            \n            frac : sign UINT division sign UINT\n            \n            sign : SIGN\n                 |\n            \n            product : STAR\n                    | PERIOD\n            \n            division : SOLIDUS\n            \n            power : DOUBLE_STAR\n                  | CARET\n            \n            signed_int : SIGN UINT\n            \n            signed_float : sign UINT\n                         | sign UFLOAT\n            \n            function_name : FUNCNAME\n            \n            function : function_name OPEN_PAREN main CLOSE_PAREN\n            '_lr_signature = 'DOUBLE_STAR STAR PERIOD SOLIDUS CARET OPEN_PAREN CLOSE_PAREN FUNCNAME UNIT SIGN UINT UFLOAT\n            main : product_of_units\n                 | factor product_of_units\n                 | factor product product_of_units\n                 | division_product_of_units\n                 | factor division_product_of_units\n                 | factor product division_product_of_units\n                 | inverse_unit\n                 | factor inverse_unit\n                 | factor product inverse_unit\n                 | factor\n            \n            division_product_of_units : division_product_of_units division product_of_units\n                                      | product_of_units\n            \n            inverse_unit : division unit_expression\n            \n            factor : factor_fits\n                   | factor_float\n                   | factor_int\n            \n            factor_float : signed_float\n                         | signed_float UINT signed_int\n                         | signed_float UINT power numeric_power\n            \n            factor_int : UINT\n                       | UINT signed_int\n                       | UINT power numeric_power\n                       | UINT UINT signed_int\n                       | UINT UINT power numeric_power\n            \n            factor_fits : UINT power OPEN_PAREN signed_int CLOSE_PAREN\n                        | UINT power OPEN_PAREN UINT CLOSE_PAREN\n                        | UINT power signed_int\n                        | UINT power UINT\n                        | UINT SIGN UINT\n                        | UINT OPEN_PAREN signed_int CLOSE_PAREN\n            \n            product_of_units : unit_expression product product_of_units\n                             | unit_expression product_of_units\n                             | unit_expression\n            \n            unit_expression : function\n                            | unit_with_power\n                            | OPEN_PAREN product_of_units CLOSE_PAREN\n            \n            unit_with_power : UNIT power numeric_power\n                            | UNIT numeric_power\n                            | UNIT\n            \n            numeric_power : sign UINT\n                          | OPEN_PAREN paren_expr CLOSE_PAREN\n            \n            paren_expr : sign UINT\n                       | signed_float\n                       | frac\n            \n            frac : sign UINT division sign UINT\n            \n            sign : SIGN\n                 |\n            \n            product : STAR\n                    | PERIOD\n            \n            division : SOLIDUS\n            \n            power : DOUBLE_STAR\n                  | CARET\n            \n            signed_int : SIGN UINT\n            \n            signed_float : sign UINT\n                         | sign UFLOAT\n            \n            function_name : FUNCNAME\n            \n            function : function_name OPEN_PAREN main CLOSE_PAREN\n            '     _lr_action_items = {'OPEN_PAREN':([0,3,6,7,8,9,10,11,12,13,14,16,17,18,19,21,23,26,27,28,29,34,36,38,39,41,42,43,46,47,53,54,55,58,59,62,63,64,66,67,72,73,75,76,77,78,80,],[13,13,13,-14,-15,-16,13,-32,-33,13,35,-17,-48,41,45,-54,13,-46,-47,13,13,57,-21,-49,-50,13,45,-36,-52,-53,-34,-23,45,-26,-22,-27,-18,45,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'UINT':([0,14,15,16,17,19,20,34,37,38,39,41,42,44,45,46,47,55,56,57,60,64,69,81,82,],[14,33,-44,40,-48,-45,46,-45,62,-49,-50,14,-45,67,-45,-52,-53,-45,73,-45,73,-45,79,-45,83,]),'SOLIDUS':([0,2,3,4,6,7,8,9,11,12,14,16,19,22,23,24,26,27,30,36,41,43,46,47,48,49,51,52,53,54,58,59,62,63,66,67,72,73,75,76,77,78,79,80,],[17,-12,17,17,-31,-14,-15,-16,-32,-33,-20,-17,-37,-12,17,17,-46,-47,-30,-21,17,-36,-52,-53,-12,17,-11,-29,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,17,-25,]),'UNIT':([0,3,6,7,8,9,10,11,12,13,14,16,17,19,23,26,27,28,29,36,41,43,46,47,53,54,58,59,62,63,66,67,72,73,75,76,77,78,80,],[19,19,19,-14,-15,-16,19,-32,-33,19,-20,-17,-48,-37,19,-46,-47,19,19,-21,19,-36,-52,-53,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'FUNCNAME':([0,3,6,7,8,9,10,11,12,13,14,16,17,19,23,26,27,28,29,36,41,43,46,47,53,54,58,59,62,63,66,67,72,73,75,76,77,78,80,],[21,21,21,-14,-15,-16,21,-32,-33,21,-20,-17,-48,-37,21,-46,-47,21,21,-21,21,-36,-52,-53,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'SIGN':([0,14,17,19,33,34,35,38,39,40,41,42,45,55,57,64,81,],[15,37,-48,15,56,60,56,-49,-50,56,15,15,15,15,60,15,15,]),'UFLOAT':([0,15,20,41,45,57,60,69,],[-45,-44,47,-45,-45,-45,-44,47,]),'$end':([1,2,3,4,5,6,7,8,9,11,12,14,16,19,22,24,25,30,31,36,43,46,47,48,49,50,51,52,53,54,58,59,62,63,66,67,72,73,75,76,77,78,80,],[0,-1,-10,-4,-7,-31,-14,-15,-16,-32,-33,-20,-17,-37,-2,-5,-8,-30,-13,-21,-36,-52,-53,-3,-6,-9,-11,-29,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'CLOSE_PAREN':([2,3,4,5,6,7,8,9,11,12,14,16,19,22,24,25,30,31,32,36,43,46,47,48,49,50,51,52,53,54,58,59,61,62,63,65,66,67,68,70,71,72,73,74,75,76,77,78,79,80,83,],[-1,-10,-4,-7,-31,-14,-15,-16,-32,-33,-20,-17,-37,-2,-5,-8,-30,-13,53,-21,-36,-52,-53,-3,-6,-9,-11,-29,-34,-23,-26,-22,75,-27,-18,77,-35,-38,78,-41,-42,-24,-51,80,-28,-19,-55,-39,-40,-25,-43,]),'STAR':([3,6,7,8,9,11,12,14,16,19,36,43,46,47,53,54,58,59,62,63,66,67,72,73,75,76,77,78,80,],[26,26,-14,-15,-16,-32,-33,-20,-17,-37,-21,-36,-52,-53,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'PERIOD':([3,6,7,8,9,11,12,14,16,19,36,43,46,47,53,54,58,59,62,63,66,67,72,73,75,76,77,78,80,],[27,27,-14,-15,-16,-32,-33,-20,-17,-37,-21,-36,-52,-53,-34,-23,-26,-22,-27,-18,-35,-38,-24,-51,-28,-19,-55,-39,-25,]),'DOUBLE_STAR':([14,19,33,40,],[38,38,38,38,]),'CARET':([14,19,33,40,],[39,39,39,39,]),}_lr_action_items = {'OPEN_PAREN':([0,3,6,7,8,9,10,11,12,13,14,16,17,18,19,21,23,26,27,28,29,34,36,38,39,41,42,43,46,47,53,54,55,57,59,60,63,64,65,67,68,73,74,77,78,79,80,82,83,],[13,13,13,-14,-15,-16,13,-34,-35,13,35,-17,-50,41,45,-56,13,-48,-49,13,13,58,-21,-51,-52,13,45,-38,-54,-55,-36,-23,45,-28,-27,-22,-29,-18,45,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'UINT':([0,14,15,16,17,19,20,34,37,38,39,41,42,44,45,46,47,55,56,58,61,65,70,84,85,],[14,33,-46,40,-50,-47,46,57,63,-51,-52,14,-47,68,-47,-54,-55,-47,74,75,74,-47,81,-47,86,]),'SOLIDUS':([0,2,3,4,6,7,8,9,11,12,14,16,19,22,23,24,26,27,30,36,41,43,46,47,48,49,51,52,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,81,82,83,],[17,-12,17,17,-33,-14,-15,-16,-34,-35,-20,-17,-39,-12,17,17,-48,-49,-32,-21,17,-38,-54,-55,-12,17,-11,-31,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,17,-26,-25,]),'UNIT':([0,3,6,7,8,9,10,11,12,13,14,16,17,19,23,26,27,28,29,36,41,43,46,47,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,82,83,],[19,19,19,-14,-15,-16,19,-34,-35,19,-20,-17,-50,-39,19,-48,-49,19,19,-21,19,-38,-54,-55,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'FUNCNAME':([0,3,6,7,8,9,10,11,12,13,14,16,17,19,23,26,27,28,29,36,41,43,46,47,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,82,83,],[21,21,21,-14,-15,-16,21,-34,-35,21,-20,-17,-50,-39,21,-48,-49,21,21,-21,21,-38,-54,-55,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'SIGN':([0,14,17,19,33,34,35,38,39,40,41,42,45,55,58,65,84,],[15,37,-50,15,56,61,56,-51,-52,56,15,15,15,15,61,15,15,]),'UFLOAT':([0,15,20,41,45,58,61,70,],[-47,-46,47,-47,-47,-47,-46,47,]),'$end':([1,2,3,4,5,6,7,8,9,11,12,14,16,19,22,24,25,30,31,36,43,46,47,48,49,50,51,52,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,82,83,],[0,-1,-10,-4,-7,-33,-14,-15,-16,-34,-35,-20,-17,-39,-2,-5,-8,-32,-13,-21,-38,-54,-55,-3,-6,-9,-11,-31,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'CLOSE_PAREN':([2,3,4,5,6,7,8,9,11,12,14,16,19,22,24,25,30,31,32,36,43,46,47,48,49,50,51,52,53,54,57,59,60,62,63,64,66,67,68,69,71,72,73,74,75,76,77,78,79,80,81,82,83,86,],[-1,-10,-4,-7,-33,-14,-15,-16,-34,-35,-20,-17,-39,-2,-5,-8,-32,-13,53,-21,-38,-54,-55,-3,-6,-9,-11,-31,-36,-23,-28,-27,-22,77,-29,-18,79,-37,-40,80,-43,-44,-24,-53,82,83,-30,-19,-57,-41,-42,-26,-25,-45,]),'STAR':([3,6,7,8,9,11,12,14,16,19,36,43,46,47,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,82,83,],[26,26,-14,-15,-16,-34,-35,-20,-17,-39,-21,-38,-54,-55,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'PERIOD':([3,6,7,8,9,11,12,14,16,19,36,43,46,47,53,54,57,59,60,63,64,67,68,73,74,77,78,79,80,82,83,],[27,27,-14,-15,-16,-34,-35,-20,-17,-39,-21,-38,-54,-55,-36,-23,-28,-27,-22,-29,-18,-37,-40,-24,-53,-30,-19,-57,-41,-26,-25,]),'DOUBLE_STAR':([14,19,33,40,],[38,38,38,38,]),'CARET':([14,19,33,40,],[39,39,39,39,]),}  _lr_action = {} for _k, _v in _lr_action_items.items():


Question: ('factor_int -> UINT UINT signed_int','factor_int',3,'p_factor_int','generic.py',257),   ('factor_int -> UINT UINT power numeric_power','factor_int',4,'p_factor_int','generic.py',258),   ('factor_fits -> UINT power OPEN_PAREN signed_int CLOSE_PAREN','factor_fits',5,'p_factor_fits','generic.py',276),  ('factor_fits -> UINT power signed_int','factor_fits',3,'p_factor_fits','generic.py',277),  ('factor_fits -> UINT SIGN UINT','factor_fits',3,'p_factor_fits','generic.py',278),  ('factor_fits -> UINT OPEN_PAREN signed_int CLOSE_PAREN','factor_fits',4,'p_factor_fits','generic.py',279),  ('product_of_units -> unit_expression product product_of_units','product_of_units',3,'p_product_of_units','generic.py',298),  ('product_of_units -> unit_expression product_of_units','product_of_units',2,'p_product_of_units','generic.py',299),  ('product_of_units -> unit_expression','product_of_units',1,'p_product_of_units','generic.py',300),  ('unit_expression -> function','unit_expression',1,'p_unit_expression','generic.py',311),  ('unit_expression -> unit_with_power','unit_expression',1,'p_unit_expression','generic.py',312),  ('unit_expression -> OPEN_PAREN product_of_units CLOSE_PAREN','unit_expression',3,'p_unit_expression','generic.py',313),  ('unit_with_power -> UNIT power numeric_power','unit_with_power',3,'p_unit_with_power','generic.py',322),  ('unit_with_power -> UNIT numeric_power','unit_with_power',2,'p_unit_with_power','generic.py',323),  ('unit_with_power -> UNIT','unit_with_power',1,'p_unit_with_power','generic.py',324),  ('numeric_power -> sign UINT','numeric_power',2,'p_numeric_power','generic.py',335),  ('numeric_power -> OPEN_PAREN paren_expr CLOSE_PAREN','numeric_power',3,'p_numeric_power','generic.py',336),  ('paren_expr -> sign UINT','paren_expr',2,'p_paren_expr','generic.py',345),  ('paren_expr -> signed_float','paren_expr',1,'p_paren_expr','generic.py',346),  ('paren_expr -> frac','paren_expr',1,'p_paren_expr','generic.py',347),  ('frac -> sign UINT division sign UINT','frac',5,'p_frac','generic.py',356),  ('sign -> SIGN','sign',1,'p_sign','generic.py',362),  ('sign -> <empty>','sign',0,'p_sign','generic.py',363),  ('product -> STAR','product',1,'p_product','generic.py',372),  ('product -> PERIOD','product',1,'p_product','generic.py',373),  ('division -> SOLIDUS','division',1,'p_division','generic.py',379),  ('power -> DOUBLE_STAR','power',1,'p_power','generic.py',385),  ('power -> CARET','power',1,'p_power','generic.py',386),  ('signed_int -> SIGN UINT','signed_int',2,'p_signed_int','generic.py',392),  ('signed_float -> sign UINT','signed_float',2,'p_signed_float','generic.py',398),  ('signed_float -> sign UFLOAT','signed_float',2,'p_signed_float','generic.py',399),  ('function_name -> FUNCNAME','function_name',1,'p_function_name','generic.py',405),  ('function -> function_name OPEN_PAREN main CLOSE_PAREN','function',4,'p_function','generic.py',411),  ('factor_fits -> UINT power OPEN_PAREN UINT CLOSE_PAREN','factor_fits',5,'p_factor_fits','generic.py',277),  ('factor_fits -> UINT power signed_int','factor_fits',3,'p_factor_fits','generic.py',278),  ('factor_fits -> UINT power UINT','factor_fits',3,'p_factor_fits','generic.py',279),  ('factor_fits -> UINT SIGN UINT','factor_fits',3,'p_factor_fits','generic.py',280),  ('factor_fits -> UINT OPEN_PAREN signed_int CLOSE_PAREN','factor_fits',4,'p_factor_fits','generic.py',281),  ('product_of_units -> unit_expression product product_of_units','product_of_units',3,'p_product_of_units','generic.py',300),  ('product_of_units -> unit_expression product_of_units','product_of_units',2,'p_product_of_units','generic.py',301),  ('product_of_units -> unit_expression','product_of_units',1,'p_product_of_units','generic.py',302),  ('unit_expression -> function','unit_expression',1,'p_unit_expression','generic.py',313),  ('unit_expression -> unit_with_power','unit_expression',1,'p_unit_expression','generic.py',314),  ('unit_expression -> OPEN_PAREN product_of_units CLOSE_PAREN','unit_expression',3,'p_unit_expression','generic.py',315),  ('unit_with_power -> UNIT power numeric_power','unit_with_power',3,'p_unit_with_power','generic.py',324),  ('unit_with_power -> UNIT numeric_power','unit_with_power',2,'p_unit_with_power','generic.py',325),  ('unit_with_power -> UNIT','unit_with_power',1,'p_unit_with_power','generic.py',326),  ('numeric_power -> sign UINT','numeric_power',2,'p_numeric_power','generic.py',337),  ('numeric_power -> OPEN_PAREN paren_expr CLOSE_PAREN','numeric_power',3,'p_numeric_power','generic.py',338),  ('paren_expr -> sign UINT','paren_expr',2,'p_paren_expr','generic.py',347),  ('paren_expr -> signed_float','paren_expr',1,'p_paren_expr','generic.py',348),  ('paren_expr -> frac','paren_expr',1,'p_paren_expr','generic.py',349),  ('frac -> sign UINT division sign UINT','frac',5,'p_frac','generic.py',358),  ('sign -> SIGN','sign',1,'p_sign','generic.py',364),  ('sign -> <empty>','sign',0,'p_sign','generic.py',365),  ('product -> STAR','product',1,'p_product','generic.py',374),  ('product -> PERIOD','product',1,'p_product','generic.py',375),  ('division -> SOLIDUS','division',1,'p_division','generic.py',381),  ('power -> DOUBLE_STAR','power',1,'p_power','generic.py',387),  ('power -> CARET','power',1,'p_power','generic.py',388),  ('signed_int -> SIGN UINT','signed_int',2,'p_signed_int','generic.py',394),  ('signed_float -> sign UINT','signed_float',2,'p_signed_float','generic.py',400),  ('signed_float -> sign UFLOAT','signed_float',2,'p_signed_float','generic.py',401),  ('function_name -> FUNCNAME','function_name',1,'p_function_name','generic.py',407),  ('function -> function_name OPEN_PAREN main CLOSE_PAREN','function',4,'p_function','generic.py',413), ]


Question: "bases must be sequence of UnitBase instances")             powers = [validate_power(p) for p in powers]         if not decompose and len(bases) == 1:            # Short-cut; with one unit there's nothing to expand and gather.        if not decompose and len(bases) == 1 and powers[0] >= 0:            # Short-cut; with one unit there's nothing to expand and gather,            # as that has happened already when creating the unit.  But do only            # positive powers, since for negative powers we need to re-sort.             unit = bases[0]             power = powers[0]             if power == 1:

units: 's / m' and 's / m' are not convertible To paraphrase from , exceptions like (and a few other cases with first, second and third powers of second over meter, curiously) started popping up in our travis tests as seen at https://travis- . For a brief overview, running and getting into : I've managed to figure out that this is localized to 3.1. As suggested by on slack, I ran with and I was able to identify the first bad commit as I'm currently trying to find out the exact cause of this bug in that commit, but I figured it's best to submit this issue here before I accidentally close this tab or something.


Question: self._bases = unit.bases                 self._powers = [operator.mul(*resolve_fractions(p, power))                                 for p in unit.powers]<ins></ins>             self._scale = sanitize_scale(scale)         else:             # Regular case: use inputs as preliminary scale, bases, and powers,


Question: from astropy import cosmology         H0 = cosmology.default_cosmology.get().H0     h100_val_unit = Unit(H0.to((si.km/si.s)/astrophys.Mpc).value/100 * astrophys.littleh)    h100_val_unit = Unit(100/(H0.to_value((si.km/si.s)/astrophys.Mpc)) * astrophys.littleh)      return [(h100_val_unit, None)]

Problem with the part of unit equivalencies? In the newly equivalencies: We notice that the implementation of seems to be wrong, as highlighted in the following figure: ! If , and , should it be equivalent to 140 Mpc, instead of 70Mpc? I can reproduce this so it is not a typo...


Question: If ``ncp_prior`` is not explicitly defined, compute it from ``gamma``         or ``p0``.         """        if self.ncp_prior is not None:            return self.ncp_prior        elif self.gamma is not None:        if self.gamma is not None:             return -np.log(self.gamma)         elif self.p0 is not None:             return self.p0_prior(N)         else:            raise ValueError("``ncp_prior`` is not defined, and cannot compute "                             "it as neither ``gamma`` nor ``p0`` is defined.")            raise ValueError("``ncp_prior`` cannot be computed as neither "                             "``gamma`` nor ``p0`` is defined.")      def fit(self, t, x=None, sigma=None):         """Fit the Bayesian Blocks model given the specified fitness function.

ncpprior referenced before assignment in Bayesian Blocks There is a bug in the bayesian blocks algorithm of It's not a big deal so I show you below how to solve it directly. When I call: I get: You can fix this just by changing: adding an else sentence EDIT: Text formatting ncpprior referenced before assignment in Bayesian Blocks There is a bug in the bayesian blocks algorithm of It's not a big deal so I show you below how to solve it directly. When I call: I get: You can fix this just by changing: adding an else sentence EDIT: Text formatting


Question: # Compute ncp_prior if not defined         if self.ncp_prior is None:             ncp_prior = self.compute_ncp_prior(N)<ins>        else:            ncp_prior = self.ncp_prior</ins>         # ----------------------------------------------------------------         # Start with first data cell; add one cell at each iteration         # ----------------------------------------------------------------


Question: import numpy as np from astropy.units import (Unit, UnitBase, UnitsError, UnitTypeError,from astropy.units import (Unit, UnitBase, UnitsError, UnitTypeError, UnitConversionError,                            dimensionless_unscaled, Quantity)  __all__ = ['FunctionUnitBase', 'FunctionQuantity']

Adding/subtracting ABmag Quantities loses the "type" of magnitude The following code raises a , because it appears the math operation lost track of the "type" of magnitude. and are both , so I would expect their difference to also be an ABmag. prints the following, and then raises: If the is changed to , the exception is different:


Question: return self.function_unit.to(other_function_unit, value)          else:            # when other is not a function unit            return self.physical_unit.to(other, self.to_physical(value),                                         equivalencies)            try:                # when other is not a function unit                return self.physical_unit.to(other, self.to_physical(value),                                             equivalencies)            except UnitConversionError as e:                if self.function_unit == Unit('mag'):                    # One can get to raw magnitudes via math that strips the dimensions off.                    # Include extra information in the exception to remind users of this.                    msg = "Did you perhaps subtract magnitudes so the unit got lost?"                    e.args += (msg,)                    raise e                else:                    raise      def is_unity(self):         return False


Question: """          card = cls()        if isinstance(image, bytes):            # FITS supports only ASCII, but decode as latin1 and just take all            # bytes for now; if it results in mojibake due to e.g. UTF-8            # encoded data in a FITS header that's OK because it shouldn't be            # there in the first place            image = image.decode('latin1')         card._image = _pad(image)         card._verified = False         return carddiff --git a/astropy/io/fits/header.py b/astropy/io/fits/header.py-- a/astropy/io/fits/header.py++ b/astropy/io/fits/header.py

Header.fromstring does not accept Python 3 bytes According to , the method "...creates an HDU header from a byte string containing the entire header data." By "byte string" here it really means the type which on Python 2 could be raw binary data, but on Python 3 explicitly is not. In fact it does work on Python 3's unicode s, but here it assumes that the data can be ASCII-encoded. Its counterpart, will work with files opened in text or binary mode. So probably the simplest solution for now (as opposed to adding new methods or something like that) is to change to accept unicode or bytes string types. likely needs a similar treatment.


Question: END_CARD = 'END' + ' ' * 77  __doctest_skip__ = ['Header', 'Header.*']__doctest_skip__ = ['Header', 'Header.comments', 'Header.fromtextfile',                    'Header.totextfile', 'Header.set', 'Header.update']   class Header:


Question: Parameters         ----------        data : str           String containing the entire header.        data : str or bytes           String or bytes containing the entire header.  In the case of bytes           they will be decoded using latin-1 (only plain ASCII characters are           allowed in FITS headers but latin-1 allows us to retain any invalid           bytes that might appear in malformatted FITS files).          sep : str, optional             The string separating cards from each other, such as a newline.  By             default there is no card separator (as is the case in a raw FITS            file).            file).  In general this is only used in cases where a header was            printed as text (e.g. with newlines after each card) and you want            to create a new `Header` from it by copy/pasting.        Examples        --------        >>> from astropy.io.fits import Header        >>> hdr = Header({'SIMPLE': True})        >>> Header.fromstring(hdr.tostring()) == hdr        True        If you want to create a `Header` from printed text it's not necessary        to have the exact binary structure as it would appear in a FITS file,        with the full 80 byte card length.  Rather, each "card" can end in a        newline and does not have to be padded out to a full card length as        long as it "looks like" a FITS header:        >>> hdr = Header.fromstring(\"\"\"\\        ... SIMPLE  =                    T / conforms to FITS standard        ... BITPIX  =                    8 / array data type        ... NAXIS   =                    0 / number of array dimensions        ... EXTEND  =                    T        ... \"\"\", sep='\\n')        >>> hdr['SIMPLE']        True        >>> hdr['BITPIX']        8        >>> len(hdr)        4          Returns         -------


Question: # immediately at the separator         require_full_cardlength = set(sep).issubset(VALID_HEADER_CHARS) <ins>        if isinstance(data, bytes):            # FITS supports only ASCII, but decode as latin1 and just take all            # bytes for now; if it results in mojibake due to e.g. UTF-8            # encoded data in a FITS header that's OK because it shouldn't be            # there in the first place--accepting it here still gives us the            # opportunity to display warnings later during validation            CONTINUE = b'CONTINUE'            END = b'END'            end_card = END_CARD.encode('ascii')            sep = sep.encode('latin1')            empty = b''        else:            CONTINUE = 'CONTINUE'            END = 'END'            end_card = END_CARD            empty = ''</ins>         # Split the header into individual cards         idx = 0         image = []


Question: idx = end_idx + len(sep)              if image:                if next_image[:8] == 'CONTINUE':                if next_image[:8] == CONTINUE:                     image.append(next_image)                     continue                cards.append(Card.fromstring(''.join(image)))                cards.append(Card.fromstring(empty.join(image)))              if require_full_cardlength:                if next_image == END_CARD:                if next_image == end_card:                     image = []                     break             else:                if next_image.split(sep)[0].rstrip() == 'END':                if next_image.split(sep)[0].rstrip() == END:                     image = []                     break


Question: # Add the last image that was found before the end, if any         if image:            cards.append(Card.fromstring(''.join(image)))            cards.append(Card.fromstring(empty.join(image)))          return cls._fromcards(cards)


Question: def cumsum(self, axis=None, dtype=None, out=None):         return self._wrap_function(np.cumsum, axis, dtype, out=out)    def clip(self, a_min, a_max, out=None):        return self._wrap_function(np.clip, self._to_own_unit(a_min),                                   self._to_own_unit(a_max), out=out)diff --git a/astropy/units/quantity.py b/astropy/units/quantity.py-- a/astropy/units/quantity.py++ b/astropy/units/quantity.py

Support new clip ufunc Starting with numpy 1.17, will be based on a , which means we can ensure it works properly with . (Until we do so, we might also get failures.)


Question: UnitBase, UnitsError, UnitConversionError, UnitTypeError) from .utils import is_effectively_unity from .format.latex import Latexfrom astropy.utils.compat import NUMPY_LT_1_14, NUMPY_LT_1_16from astropy.utils.compat import NUMPY_LT_1_14, NUMPY_LT_1_16, NUMPY_LT_1_17 from astropy.utils.compat.misc import override__dir__ from astropy.utils.exceptions import AstropyDeprecationWarning, AstropyWarning from astropy.utils.misc import isiterable, InheritDocstrings


Question: kwargs['out'] = (out_array,) if function.nout == 1 else out_array          # Same for inputs, but here also convert if necessary.        arrays = [(converter(input_.value) if converter else                   getattr(input_, 'value', input_))                  for input_, converter in zip(inputs, converters)]        arrays = []        for input_, converter in zip(inputs, converters):            input_ = getattr(input_, 'value', input_)            arrays.append(converter(input_) if converter else input_)          # Call our superclass's __array_ufunc__         result = super().__array_ufunc__(function, method, *arrays, **kwargs)


Question: result = function(*args, **kwargs)         return self._result_as_quantity(result, unit, out)     def clip(self, a_min, a_max, out=None):        return self._wrap_function(np.clip, self._to_own_unit(a_min),                                   self._to_own_unit(a_max), out=out)    if NUMPY_LT_1_17:        def clip(self, a_min, a_max, out=None):            return self._wrap_function(np.clip, self._to_own_unit(a_min),                                       self._to_own_unit(a_max), out=out)      def trace(self, offset=0, axis1=0, axis2=1, dtype=None, out=None):         return self._wrap_function(np.trace, offset, axis1, axis2, dtype,diff --git a/astropy/units/quantity_helper/converters.py b/astropy/units/quantity_helper/converters.py-- a/astropy/units/quantity_helper/converters.py++ b/astropy/units/quantity_helper/converters.py


Question: converters, result_unit = ufunc_helper(function, *units)          if any(converter is False for converter in converters):            # for two-argument ufuncs with a quantity and a non-quantity,            # for multi-argument ufuncs with a quantity and a non-quantity,             # the quantity normally needs to be dimensionless, *except*             # if the non-quantity can have arbitrary unit, i.e., when it             # is all zero, infinity or NaN.  In that case, the non-quantity             # can just have the unit of the quantity             # (this allows, e.g., `q > 0.` independent of unit)            maybe_arbitrary_arg = args[converters.index(False)]             try:                if can_have_arbitrary_unit(maybe_arbitrary_arg):                    converters = [None, None]                else:                    raise UnitConversionError(                        "Can only apply '{0}' function to "                        "dimensionless quantities when other "                        "argument is not a quantity (unless the "                        "latter is all zero/infinity/nan)"                        .format(function.__name__))                # Don't fold this loop in the test above: this rare case                # should not make the common case slower.                for i, converter in enumerate(converters):                    if converter is not False:                        continue                    if can_have_arbitrary_unit(args[i]):                        converters[i] = None                    else:                        raise UnitConversionError(                            "Can only apply '{0}' function to "                            "dimensionless quantities when other "                            "argument is not a quantity (unless the "                            "latter is all zero/infinity/nan)"                            .format(function.__name__))             except TypeError:                 # _can_have_arbitrary_unit failed: arg could not be compared                 # with zero or checked to be finite. Then, ufunc will fail too.                 raise TypeError("Unsupported operand type(s) for ufunc {0}: "                                "'{1}' and '{2}'"                                .format(function.__name__,                                        args[0].__class__.__name__,                                        args[1].__class__.__name__))                                "'{1}'".format(function.__name__,                                               ','.join([arg.__class__.__name__                                                         for arg in args])))          # In the case of np.power and np.float_power, the unit itself needs to         # be modified by an amount that depends on one of the input values,diff --git a/astropy/units/quantity_helper/helpers.py b/astropy/units/quantity_helper/helpers.py-- a/astropy/units/quantity_helper/helpers.py++ b/astropy/units/quantity_helper/helpers.py


Question: return converters, (dimensionless_unscaled, result_unit)  <ins>def helper_clip(f, unit1, unit2, unit3):    # Treat the array being clipped as primary.    converters = [None]    if unit1 is None:        result_unit = dimensionless_unscaled        try:            converters += [(None if unit is None else                            get_converter(unit, dimensionless_unscaled))                           for unit in (unit2, unit3)]        except UnitsError:            raise UnitConversionError(                "Can only apply '{0}' function to quantities with "                "compatible dimensions".format(f.__name__))    else:        result_unit = unit1        for unit in unit2, unit3:            try:                converter = get_converter(_d(unit), result_unit)            except UnitsError:                if unit is None:                    # special case: OK if unitless number is zero, inf, nan                    converters.append(False)                else:                    raise UnitConversionError(                        "Can only apply '{0}' function to quantities with "                        "compatible dimensions".format(f.__name__))            else:                converters.append(converter)    return converters, result_unit</ins> # list of ufuncs: # http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs


Question: UFUNC_HELPERS[np.heaviside] = helper_heaviside UFUNC_HELPERS[np.float_power] = helper_power UFUNC_HELPERS[np.divmod] = helper_divmod# Check for clip ufunc; note that np.clip is a wrapper function, not the ufunc.if isinstance(getattr(np.core.umath, 'clip', None), np.ufunc):    UFUNC_HELPERS[np.core.umath.clip] = helper_clipdiff --git a/astropy/utils/compat/numpycompat.py b/astropy/utils/compat/numpycompat.py-- a/astropy/utils/compat/numpycompat.py++ b/astropy/utils/compat/numpycompat.py


Question: __all__ = ['NUMPY_LT_1_14', 'NUMPY_LT_1_14_1', 'NUMPY_LT_1_14_2',           'NUMPY_LT_1_16']           'NUMPY_LT_1_16', 'NUMPY_LT_1_17']  # TODO: It might also be nice to have aliases to these named for specific # features/bugs we're checking for (ex:


Question: NUMPY_LT_1_14_1 = not minversion('numpy', '1.14.1') NUMPY_LT_1_14_2 = not minversion('numpy', '1.14.2') NUMPY_LT_1_16 = not minversion('numpy', '1.16')<ins>NUMPY_LT_1_17 = not minversion('numpy', '1.17')</ins>


Question: dtype : ~numpy.dtype, optional         The dtype of the resulting Numpy array or scalar that will         hold the value.  If not provided, it is determined from the input,        except that any input that cannot represent float (integer and bool)        is converted to float.        except that any integer and (non-Quantity) object inputs are converted        to float by default.      copy : bool, optional         If `True` (default), then the value is copied.  Otherwise, a copy will

float16 quantities get upgraded to float64 automatically When trying to create a from a (not something I actually intended to do, I was experimenting while investigating other issue) it gets upgraded automatically to , which is something that does not happen with other float types: However: Somewhat related:


Question: if not copy:                     return value                 if not (np.can_cast(np.float32, value.dtype) or                        value.dtype.fields):                if value.dtype.kind in 'iu':                     dtype = float              return np.array(value, dtype=dtype, copy=copy, order=order,


Question: "Numpy numeric type.")          # by default, cast any integer, boolean, etc., to float        if dtype is None and (not (np.can_cast(np.float32, value.dtype)                                   or value.dtype.fields)                              or value.dtype.kind == 'O'):        if dtype is None and value.dtype.kind in 'iuO':             value = value.astype(float)          value = value.view(cls)


Question: <ins>from django.apps import apps</ins> from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS, connections from django.db.migrations.executor import MigrationExecutor

Misleading sqlmigrate "App 'apps.somethings' does not have migrations." error message Description This ticket is very similar to As shown above, validation should be sqlmigrate.


Question: # Resolve command-line arguments into a migration         app_label, migration_name = options['app_label'], options['migration_name']<ins>        # Validate app_label        try:            apps.get_app_config(app_label)        except LookupError as err:            raise CommandError(str(err))</ins>         if app_label not in executor.loader.migrated_apps:             raise CommandError("App '%s' does not have migrations" % app_label)         try:


Question: regex = _lazy_re_compile(         r'^(?:[a-z0-9\.\-\+]*)://'  # scheme is validated separately        r'(?:\S+(?::\S*)?@)?'  # user:pass authentication        r'(?:[^\s:@/]+(?::[^\s:@/]*)?@)?'  # user:pass authentication         r'(?:' + ipv4_re + '|' + ipv6_re + '|' + host_re + ')'         r'(?::\d{2,5})?'  # port         r'(?:[/?#][^\s]*)?'  # resource path

Make URLValidator reject invalid characters in the username and password Description (last modified by Tim Bell) Since , core.validators.URLValidator accepts URLs with usernames and passwords. RFC 1738 section 3.1 requires "Within the user and password field, any ":", " or "/" must be encoded"; however, those characters are currently accepted without being %-encoded. That allows certain invalid URLs to pass validation incorrectly. (The issue originates in Diego Perini's gist, from which the implementation in was derived.) An example URL that should be invalid is ; furthermore, many of the test cases in would be rendered valid under the current implementation by appending a query string of the form to them. I note Tim Graham's concern about adding complexity to the validation regex. However, I take the opposite position to Danilo Bargen about invalid URL edge cases: it's not fine if invalid URLs (even so-called "edge cases") are accepted when the regex could be fixed simply to reject them correctly. I also note that a URL of the form above was encountered in a production setting, so that this is a genuine use case, not merely an academic exercise. Pull request:  Make URLValidator reject invalid characters in the username and password Description (last modified by Tim Bell) Since , core.validators.URLValidator accepts URLs with usernames and passwords. RFC 1738 section 3.1 requires "Within the user and password field, any ":", " or "/" must be encoded"; however, those characters are currently accepted without being %-encoded. That allows certain invalid URLs to pass validation incorrectly. (The issue originates in Diego Perini's gist, from which the implementation in was derived.) An example URL that should be invalid is ; furthermore, many of the test cases in would be rendered valid under the current implementation by appending a query string of the form to them. I note Tim Graham's concern about adding complexity to the validation regex. However, I take the opposite position to Danilo Bargen about invalid URL edge cases: it's not fine if invalid URLs (even so-called "edge cases") are accepted when the regex could be fixed simply to reject them correctly. I also note that a URL of the form above was encountered in a production setting, so that this is a genuine use case, not merely an academic exercise. Pull request:


Question: """     show_last = {         '--version', '--verbosity', '--traceback', '--settings', '--pythonpath',        '--no-color',        '--no-color', '--force_color',     }      def _reordered_actions(self, actions):

Add an option to django-admin to always colorize output Description With Django management commands, it is currently possible disable colors with the --no-colors flag. What I'd like to have is basically the other side of the coin: a --force-colors flag that instructs Django to output ANSI color sequences in cases it would disable colors by default (typically, when the output is piped to another command, as documented). My real world use-case is the following one: I have a custom Django command to import data. I run this command myself, and I'd like to send a colored log (HTML seems perfect for this) to the data curators. I can use the  utility for this, but that doesn't work since Django disable colors when the output is piped. Other *nix commands have a special flag for this exact use-case, for example $ ls --color=always


Question: # Command-specific options not defined by the argument parser.     stealth_options = ()     def __init__(self, stdout=None, stderr=None, no_color=False):    def __init__(self, stdout=None, stderr=None, no_color=False, force_color=False):         self.stdout = OutputWrapper(stdout or sys.stdout)         self.stderr = OutputWrapper(stderr or sys.stderr)        if no_color and force_color:            raise CommandError("'no_color' and 'force_color' can't be used together.")         if no_color:             self.style = no_style()         else:            self.style = color_style()            self.style = color_style(force_color)             self.stderr.style_func = self.style.ERROR      def get_version(self):


Question: '--no-color', action='store_true',             help="Don't colorize the command output.",         )<ins>        parser.add_argument(            '--force-color', action='store_true',            help='Force colorization of the command output.',        )</ins>         self.add_arguments(parser)         return parser


Question: controlled by the ``requires_system_checks`` attribute, except if         force-skipped).         """        if options['no_color']:        if options['force_color'] and options['no_color']:            raise CommandError("The --no-color and --force-color options can't be used together.")        if options['force_color']:            self.style = color_style(force_color=True)        elif options['no_color']:             self.style = no_style()             self.stderr.style_func = None         if options.get('stdout'):diff --git a/django/core/management/color.py b/django/core/management/color.py-- a/django/core/management/color.py++ b/django/core/management/color.py


Question: return make_style('nocolor')  def color_style():def color_style(force_color=False):     """     Return a Style object from the Django color scheme.     """    if not supports_color():    if not force_color and not supports_color():         return no_style()     return make_style(os.environ.get('DJANGO_COLORS', ''))


Question: # Convert "-field" to "field".         fields = ((f[1:] if f.startswith('-') else f) for f in fields)         # Skip ordering in the format field1__field2 (FIXME: checking        # this format would be nice, but it's a little fiddly).        fields = (f for f in fields if LOOKUP_SEP not in f)        # Separate related field and non related fields.        _fields = []        related_fields = []        for f in fields:            if LOOKUP_SEP in f:                related_fields.append(f)            else:                _fields.append(f)        fields = _fields        # Check related fields.        for field in related_fields:            _cls = cls            fld = None            for part in field.split(LOOKUP_SEP):                try:                    fld = _cls._meta.get_field(part)                    if fld.is_relation:                        _cls = fld.get_path_info()[-1].to_opts.model                except (FieldDoesNotExist, AttributeError):                    if fld is None or fld.get_transform(part) is None:                        errors.append(                            checks.Error(                                "'ordering' refers to the nonexistent field, "                                "related field or lookup '%s'." % field,                                obj=cls,                                id='models.E015',                            )                        )          # Skip ordering on pk. This is always a valid order_by field         # but is an alias and therefore won't be found by opts.get_field.

Add validation of related fields and lookups in model Meta.ordering Description When the ordering class member in Meta of a model contains a field from a related model, and that field does not exist, django's makemigrations does not throw an error. However, if it is a direct field member of the same class, makemigrations does throw an error. Example below tested on Django 2.0.5 from import models class Agreement(models.Model): agreementid = models.AutoField(verbosename='ID', serialize=False, autocreated=True, primarykey=True) #class Meta: # generates error in makemigrations # app.Agreement: (models.E015) 'ordering' refers to the nonexistent field 'id'. # ordering = ['id'] class Order(models.Model): agreement = models.ForeignKey(Agreement, models.DONOTHING) class Meta: # does not generate error in makemigrations # but does so during runtime # e.g. [x for x in ()] ordering = ['agreement_id']


Question: from django.conf import settings, Settings, global_settings          # Because settings are imported lazily, we need to explicitly load them.        settings._setup()        if not settings.configured:            settings._setup()          user_settings = module_to_dict(settings._wrapped)         default = options['default']

diffsettings raises misleading exception message if using settings.configure() Description If, rather than using the env var DJANGOSETTINGSMODULE one uses settings.configure(...), attempting to call diffsettings can fail because it calls () unconditionally, with the exception Requested settings, but settings are not configured. You must either define the environment variable DJANGOSETTINGSMODULE or call settings.configure() before accessing settings. were the call instead: if not settings.configured: () things would work correctly.


Question: kind = None     tzinfo = None     def __init__(self, expression, output_field=None, tzinfo=None, **extra):    def __init__(self, expression, output_field=None, tzinfo=None, is_dst=None, **extra):         self.tzinfo = tzinfo        self.is_dst = is_dst         super().__init__(expression, output_field=output_field, **extra)      def as_sql(self, compiler, connection):

Trunc() should allow passing isdst resolution to avoid NonExistentTimeError/AmbiguousTimeError Description (last modified by Alexander Holmbäck) When Trunc() truncates to a nonexisting or ambiguous datetime, the exception raised by pytz remains unhandled. The expected behavior would, IMO, be to not check the validity of truncated dates. This test for example: import datetime import pytz from import Trunc from import TestCase from import timezone from .models import Log class TestTruncateToInvalidTime(TestCase): def testtruncatetodstendsstockholm(self): tzinfo = pytz.timezone('Europe/Stockholm') timestamp = datetime.datetime(2018, 10, 28, 2, tzinfo=tzinfo) (timestamp=timestamp) logs = Log.objects.annotate(day=Trunc('timestamp', 'hour')).all() timezone.activate(tzinfo) self.assertEqual(logs[0], 28) Results in the following error: ERROR: testtruncatetodstendsstockholm () Traceback (most recent call last): File "", line 47, in testtruncatetodstendsstockholm self.assertEqual(logs[0], 28) File "", line 303, in getitem qs.fetchall() File "", line 1190, in fetchall self.resultcache = list(self.iterableclass(self)) File "", line 64, in iter for row in compiler.resultsiter(results): File "", line 1013, in applyconverters value = converter(value, expression, connection) File "", line 225, in convertvalue value = timezone.makeaware(value, ) File "", line 270, in makeaware return timezone.localize(value, isdst=is_dst) File "/home/alex/.virtualenvs/djangodev/lib/python3.6/site-", line 363, in localize raise AmbiguousTimeError(dt) pytz.exceptions.AmbiguousTimeError: 2018-10-28 02:00:00


Question: pass             elif value is not None:                 value = value.replace(tzinfo=None)                value = timezone.make_aware(value, self.tzinfo)                value = timezone.make_aware(value, self.tzinfo, is_dst=self.is_dst)             elif not connection.features.has_zoneinfo_database:                 raise ValueError(                     'Database returned an invalid datetime value. Are time '


Question: class Trunc(TruncBase):     def __init__(self, expression, kind, output_field=None, tzinfo=None, **extra):    def __init__(self, expression, kind, output_field=None, tzinfo=None, is_dst=None, **extra):         self.kind = kind        super().__init__(expression, output_field=output_field, tzinfo=tzinfo, **extra)        super().__init__(            expression, output_field=output_field, tzinfo=tzinfo,            is_dst=is_dst, **extra        )   class TruncYear(TruncBase):


Question: from django.core.management.base import BaseCommand, CommandErrorimport sysfrom django.apps import appsfrom django.core.management.base import BaseCommand from django.db import DEFAULT_DB_ALIAS, connections from django.db.migrations.loader import MigrationLoader

Add app_label validation to showmigrations Description The app label validation was to some commands as above tickets. But showmigrations command doesn't contain it. So I think the validation should be to showmigrations command.


Question: return self.show_list(connection, options['app_label'])      def _validate_app_names(self, loader, app_names):        invalid_apps = []        has_bad_names = False         for app_name in app_names:            if app_name not in loader.migrated_apps:                invalid_apps.append(app_name)        if invalid_apps:            raise CommandError('No migrations present for: %s' % (', '.join(sorted(invalid_apps))))            try:                apps.get_app_config(app_name)            except LookupError as err:                self.stderr.write(str(err))                has_bad_names = True        if has_bad_names:            sys.exit(2)      def show_list(self, connection, app_names=None):         """


Question: self.stdout.write("[X]  %s.%s%s" % (node.key[0], node.key[1], deps))             else:                 self.stdout.write("[ ]  %s.%s%s" % (node.key[0], node.key[1], deps))<ins>        if not plan:            self.stdout.write('(no migrations)', self.style.ERROR)</ins>


Question: elif 'changed' in sub_message:                     sub_message['changed']['fields'] = get_text_list(                        sub_message['changed']['fields'], gettext('and')                        [gettext(field_name) for field_name in sub_message['changed']['fields']], gettext('and')                     )                     if 'name' in sub_message['changed']:                         sub_message['changed']['name'] = gettext(sub_message['changed']['name'])diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py-- a/django/contrib/admin/utils.py++ b/django/contrib/admin/utils.py

Models history doesn't use verbose names Description The history for a model object (within the admin section) should show human-readable messages, favoring verbose names over field names. However, this is not currently the case. For example, consider a model with the following class variable: pubdate = models.DateTimeField("date published") Changing the publication date for an object of that model, will display "Changed pubdate." in its admin history, rather than "Change date published." as one would expect (as older versions of Django did).


Question: Translations are deactivated so that strings are stored untranslated.     Translation happens later on LogEntry access.     """    # Evaluating `form.changed_data` prior to disabling translations is required    # to avoid fields affected by localization from being included incorrectly,    # e.g. where date formats differ such as MM/DD/YYYY vs DD/MM/YYYY.    changed_data = form.changed_data    with translation_override(None):        # Deactivate translations while fetching verbose_name for form        # field labels and using `field_name`, if verbose_name is not provided.        # Translations will happen later on LogEntry access.        changed_field_labels = _get_changed_field_labels_from_form(form, changed_data)     change_message = []     if add:         change_message.append({'added': {}})     elif form.changed_data:        change_message.append({'changed': {'fields': form.changed_data}})        change_message.append({'changed': {'fields': changed_field_labels}})     if formsets:         with translation_override(None):             for formset in formsets:


Question: 'changed': {                             'name': str(changed_object._meta.verbose_name),                             'object': str(changed_object),                            'fields': changed_fields,                            'fields': _get_changed_field_labels_from_form(formset.forms[0], changed_fields),                         }                     })                 for deleted_object in formset.deleted_objects:


Question: }                     })     return change_message<ins>def _get_changed_field_labels_from_form(form, changed_data):    changed_field_labels = []    for field_name in changed_data:        try:            verbose_field_name = form.fields[field_name].label or field_name        except KeyError:            verbose_field_name = field_name        changed_field_labels.append(str(verbose_field_name))    return changed_field_labels</ins>


Question: resolved.set_source_expressions([RawSQL('%d' % (idx + 1), ())])                         break                 else:                    raise DatabaseError('ORDER BY term does not match any column in the result set.')                    if col_alias:                        raise DatabaseError('ORDER BY term does not match any column in the result set.')                    # Add column used in ORDER BY clause without an alias to                    # the selected columns.                    self.query.add_select_col(src)                    resolved.set_source_expressions([RawSQL('%d' % len(self.query.select), ())])             sql, params = self.compile(resolved)             # Don't add the same column twice, but the order direction is             # not taken into account so we strip it. When this entire methoddiff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py-- a/django/db/models/sql/query.py++ b/django/db/models/sql/query.py

Union queryset with ordering breaks on ordering with derived querysets Description (last modified by Sergei Maertens) May be related to Simple reproduction (the exact models are not relevant I think): Dimension.objects.valueslist('id', flat=True) <QuerySet [10, 11, 12, 13, 14, 15, 16, 17, 18]qs = ( (pkin=[10, 11]) .union((pkin=[16, 17]) .orderby('order') ) qs <QuerySet [<Dimension: boeksoort, <Dimension: grootboek, <Dimension: kenteken, <Dimension: activa]qs.orderby().valueslist('pk', flat=True) <QuerySet [16, 11, 10, 17]qs [breaks] Traceback: Traceback (most recent call last): File "<input", line 1, in <moduleqs File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 248, in repr data = list(self[:REPROUTPUTSIZE + 1]) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 272, in iter self.fetchall() File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 1179, in fetchall self.resultcache = list(self.iterableclass(self)) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 53, in iter results = compiler.executesql(chunkedfetch=self.chunkedfetch, chunksize=self.chunksize) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 1068, in executesql cursor.execute(sql, params) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 100, in execute return super().execute(sql, params) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 68, in execute return self.executewithwrappers(sql, params, many=False, executor=self.execute) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 77, in executewithwrappers return executor(sql, params, many,


Question: resolved.set_source_expressions([RawSQL('%d' % (idx + 1), ())])                         break                 else:                    raise DatabaseError('ORDER BY term does not match any column in the result set.')                    if col_alias:                        raise DatabaseError('ORDER BY term does not match any column in the result set.')                    # Add column used in ORDER BY clause without an alias to                    # the selected columns.                    self.query.add_select_col(src)                    resolved.set_source_expressions([RawSQL('%d' % len(self.query.select), ())])             sql, params = self.compile(resolved)             # Don't add the same column twice, but the order direction is             # not taken into account so we strip it. When this entire methoddiff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py-- a/django/db/models/sql/query.py++ b/django/db/models/sql/query.py

context) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 85, in execute return (sql, params) File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 89, in exit raise djexcvalue.withtraceback(traceback) from excvalue File "/home/bbt/.virtualenvs/ispnext/lib/python3.6/site-", line 85, in execute return (sql, params) ORDER BY position 4 is not in select list LINE 1: .dimensionsdimension"."id" IN (16, 17)) ORDER BY (4) ASC LIM... ^ Evaluating the qs instead of creating a new qs makes the code proceed as expected. [ for dim in qs]


Question: self.select = ()         self.values_select = () <ins>    def add_select_col(self, col):        self.select += col,        self.values_select += col.output_field.name,</ins>     def set_select(self, cols):         self.default_cols = False         self.select = tuple(cols)


Question: self.select = ()         self.values_select = () <ins>    def add_select_col(self, col):        self.select += col,        self.values_select += col.output_field.name,</ins>     def set_select(self, cols):         self.default_cols = False         self.select = tuple(cols)


Question: self.related_model._meta.model_name,         )     def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH, ordering=()):    def get_choices(        self, include_blank=True, blank_choice=BLANK_CHOICE_DASH,        limit_choices_to=None, ordering=(),    ):         """         Return choices with a default blank choices included, for use         as <select> choices for this field.

Using RelatedOnlyFieldListFilter with reverse ManyToMany crashes Description (last modified by Tim Graham) Using RelatedOnlyFieldListFilter with a reverse ManyToMany relation causes this exception: getchoices() got an unexpected keyword argument 'limitchoicesto' This method in ForeignObjectRel.getchoices is missing the parameter that Field.get_choices has. Pull Request:  Demo of how to trigger bug:


Question: Analog of django.db.models.fields.Field.get_choices(), provided         initially for utilization by RelatedFieldListFilter.         """        qs = self.related_model._default_manager.all()        limit_choices_to = limit_choices_to or self.limit_choices_to        qs = self.related_model._default_manager.complex_filter(limit_choices_to)         if ordering:             qs = qs.order_by(*ordering)         return (blank_choice if include_blank else []) + [


Question: from django.core.exceptions import EmptyResultSet from django.db.models.expressions import Case, Exists, Func, Value, When from django.db.models.fields import (    BooleanField, DateTimeField, Field, IntegerField,    BooleanField, CharField, DateTimeField, Field, IntegerField, UUIDField, ) from django.db.models.query_utils import RegisterLookupMixin from django.utils.datastructures import OrderedSet

Allow icontains lookup to accept uuids with or without dashes Description We have Django 2.1 project with model admin which includes an UUIDField in listdisplay and searchfields. The UUID is displayed with dashes on changelist (e.g. "-6852-47be-82be-") and if the user cut'n'paste it to the search field, I would expect admin to find it. This works however only on Postgres but fails on Oracle. I can understand why this happens (Oracle backend stores uuid as string) and I believe I can workaround it by customizing getsearchresults but I think should be internal thing that Django handles gracefully - search should be possible by the value as displayed in admin.