<commit_before>import abc

import numpy as np

__all__ = ['MissingDataAssociationException', 'IncompatibleErrorsException', 'NDError', 'StandardDeviationError']


class IncompatibleErrorsException(Exception):
   """
   This exception should be used to indicate cases in which errors with two different classes can not be propagated.
   """
   pass


class MissingDataAssociationException(Exception):
   """
   This exception should be used to indicate that an error instance has not been associated with a parent `~astropy.nddata.nddata.NDData` object.
   """
   pass


class NDError(object):
    '''
    This is the base class for error classes used with NDData. It is
    implemented as an abstract class and should never be directly
    instantiated.

    Classes inheriting from NDData should overload the ``propagate_*``
    methods, keeping the call signature the same. The propagate methods can
    assume that a `parent_nddata` attribute is present which links to the parent_nddata
    dataset, and take an `~astropy.nddata.NDData` instance as the positional
    argument, *not* an `~astropy.nddata.NDError` instance, because the
    `~astropy.nddata.NDData` instance can be used to access both the data and
    the errors (some propagations require the data values).
    '''

    __metaclass__ = abc.ABCMeta

    @property
    def parent_nddata(self):
        if self._parent_nddata is None:
            raise MissingDataAssociationException("Error is not associated with an NDData object")
        else:
            return self._parent_nddata

    @parent_nddata.setter
    def parent_nddata(self, value):
        self._parent_nddata = value

    @abc.abstractmethod
    def propagate_add(self, other_nddata, result_data):
        '''
        Propagate errors for addition.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error

        Raises
        ------
        IncompatibleErrorsException
            Raised if the method does not know how to add the errors
        '''
        pass

    @abc.abstractmethod
    def propagate_subtract(self, other_nddata, result_data):
        '''
        Propagate errors for subtraction.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error

        Raises
        ------
        IncompatibleErrorsException
            Raised if the method does not know how to add the errors
        '''
        pass

    @abc.abstractmethod
    def propagate_multiply(self, other_nddata, result_data):
        '''
        Propagate errors for mutliplication.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error
        '''
        pass

    @abc.abstractmethod
    def propagate_divide(self, other_nddata, result_data):
        '''
        Propagate errors for division.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error
        '''
        pass


class StandardDeviationError(NDError):
    '''
    A class for standard deviation errors
    '''

    def __init__(self, array=None, parent_nddata=None):

        # First initialize internal values to None
        self._parent_nddata = None
        self._array = None

        self.array = array
        self.parent_nddata = parent_nddata

    @property
    def parent_nddata(self):
        if self._parent_nddata is None:
            raise MissingDataAssociationException("Error is not associated with an NDData object")
        else:
            return self._parent_nddata

    @parent_nddata.setter
    def parent_nddata(self, value):
        if self.array is None or value is None:
            self._parent_nddata = value
        else:
            if value.shape != self.array.shape:
                raise ValueError("parent shape does not match array data shape")<commit_msg>Don't set parent_nddata via __init__ in NDError<commit_after>import abc

import numpy as np

__all__ = ['MissingDataAssociationException', 'IncompatibleErrorsException', 'NDError', 'StandardDeviationError']


class IncompatibleErrorsException(Exception):
    """
    This exception should be used to indicate cases in which errors with two different classes can not be propagated.
    """
    pass


class MissingDataAssociationException(Exception):
    """
    This exception should be used to indicate that an error instance has not been associated with a parent `~astropy.nddata.nddata.NDData` object.
    """
    pass


class NDError(object):
    '''
    This is the base class for error classes used with NDData. It is
    implemented as an abstract class and should never be directly
    instantiated.

    Classes inheriting from NDData should overload the ``propagate_*``
    methods, keeping the call signature the same. The propagate methods can
    assume that a `parent_nddata` attribute is present which links to the parent_nddata
    dataset, and take an `~astropy.nddata.NDData` instance as the positional
    argument, *not* an `~astropy.nddata.NDError` instance, because the
    `~astropy.nddata.NDData` instance can be used to access both the data and
    the errors (some propagations require the data values).
    '''

    __metaclass__ = abc.ABCMeta

    @property
    def parent_nddata(self):
        if self._parent_nddata is None:
            raise MissingDataAssociationException("Error is not associated with an NDData object")
        else:
            return self._parent_nddata

    @parent_nddata.setter
    def parent_nddata(self, value):
        self._parent_nddata = value

    @abc.abstractmethod
    def propagate_add(self, other_nddata, result_data):
        '''
        Propagate errors for addition.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error

        Raises
        ------
        IncompatibleErrorsException
            Raised if the method does not know how to add the errors
        '''
        pass

    @abc.abstractmethod
    def propagate_subtract(self, other_nddata, result_data):
        '''
        Propagate errors for subtraction.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error

        Raises
        ------
        IncompatibleErrorsException
            Raised if the method does not know how to add the errors
        '''
        pass

    @abc.abstractmethod
    def propagate_multiply(self, other_nddata, result_data):
        '''
        Propagate errors for mutliplication.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error
        '''
        pass

    @abc.abstractmethod
    def propagate_divide(self, other_nddata, result_data):
        '''
        Propagate errors for division.

        Parameters
        ----------
        other_nddata : NDData instance
            The data for the second other_nddata in a + b
        result_data : `~numpy.ndarray` instance
            The data array that is the result of the addition

        Returns
        -------
        result_error : NDError instance
            The resulting error
        '''
        pass


class StandardDeviationError(NDError):
    '''
    A class for standard deviation errors
    '''

    def __init__(self, array=None):
        self.array = array

    @property
    def parent_nddata(self):
        try:
            if self._parent_nddata is None:
                raise MissingDataAssociationException("Error is not associated with an NDData object")
            else:
                return self._parent_nddata
        except AttributeError:
            raise MissingDataAssociationException("Error is not associated with an NDData object")


    @parent_nddata.setter
    def parent_nddata(self, value):
        if self.array is None or value is None:
            self._parent_nddata = value
        else:
            if value.shape != self.array.shape:
                raise ValueError("parent shape does not match array data shape")
{'fraction_non_alphanumeric': 0.06834975369458128, 'fraction_numerical': 0.0, 'mean_word_length': 2.0995547073791347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5969822', 'n_tokens_mistral': 2537, 'n_tokens_neox': 2473, 'n_words': 898}