Python pandas.series() Examples

The following are 30 code examples of pandas.series(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas , or try the search function .
Example #1
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def hpat_pandas_series_len(self):
    """
    Pandas Series operator :func:`len` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_len
    """

    _func_name = 'Operator len().'

    if not isinstance(self, SeriesType):
        raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))

    def hpat_pandas_series_len_impl(self):
        return len(self._data)

    return hpat_pandas_series_len_impl 
Example #2
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def hpat_pandas_series_str(self):
    """
    Pandas Series attribute :attr:`pandas.Series.str` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_hiframes.TestHiFrames.test_str_get
    """

    _func_name = 'Attribute str.'

    if not isinstance(self, SeriesType):
        raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))

    if not isinstance(self.data.dtype, (types.List, types.UnicodeType)):
        msg = '{}  Can only use .str accessor with string values. Given: {}'
        raise TypingError(msg.format(_func_name, self.data.dtype))

    def hpat_pandas_series_str_impl(self):
        return pandas.core.strings.StringMethods(self)

    return hpat_pandas_series_str_impl 
Example #3
Source File: scale.py    From plotnine with GNU General Public License v2.0 6 votes vote down vote up
def train(self, x, drop=None):
        """
        Train scale

        Parameters
        ----------
        x: pd.series| np.array
            a column of data to train over

        A discrete range is stored in a list
        """
        if not len(x):
            return

        na_rm = (not self.na_translate)
        self.range.train(x, drop, na_rm=na_rm) 
Example #4
Source File: QADataStruct.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def order(self):
        """return the order num of transaction/ for everyday change

        Decorators:
            lru_cache

        Returns:
            pd.series -- [description]
        """

        return self.data.order 
Example #5
Source File: first.py    From aca with MIT License 5 votes vote down vote up
def generate_one_row(row, flag=True):
    """
    Input: one row data of pandas.series
    Output: the answer string 
    """
    if flag:
        ans = '\t'.join([row.id, row.homepage, row.gender, row.position, row.pic, row.email, row.location])
    else:
        ans = '\t'.join([row.expert_id, row.homepage_url, row.gender, row.position, row.person_photo, row.email, row.location])
    return ans + '\n' 
Example #6
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def hpat_pandas_series_T(self):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.T

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_T.py
       :language: python
       :lines: 27-
       :caption: Return the transpose, which is by definition self.
       :name: ex_series_T

    .. command-output:: python ./series/series_T.py
       :cwd: ../../../examples

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series attribute :attr:`pandas.Series.T` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_getattr_T
    """

    _func_name = 'Attribute T.'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    def hpat_pandas_series_T_impl(self):
        return self._data

    return hpat_pandas_series_T_impl 
Example #7
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def hpat_pandas_series_ndim(self):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.ndim

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_ndim.py
       :language: python
       :lines: 27-
       :caption: Number of dimensions of the underlying data, by definition 1.
       :name: ex_series_ndim

    .. command-output:: python ./series/series_ndim.py
       :cwd: ../../../examples

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series attribute :attr:`pandas.Series.ndim` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_getattr_ndim
    """

    _func_name = 'Attribute ndim.'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    def hpat_pandas_series_ndim_impl(self):
        return 1

    return hpat_pandas_series_ndim_impl 
Example #8
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def hpat_pandas_series_size(self):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.size

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_size.py
       :language: python
       :lines: 27-
       :caption: Return the number of elements in the underlying data.
       :name: ex_series_size

    .. command-output:: python ./series/series_size.py
       :cwd: ../../../examples

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series attribute :attr:`pandas.Series.size` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_size
    """

    _func_name = 'Attribute size.'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    def hpat_pandas_series_size_impl(self):
        return len(self._data)

    return hpat_pandas_series_size_impl 
Example #9
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def hpat_pandas_series_shape(self):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.shape

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_shape.py
       :language: python
       :lines: 27-
       :caption: Return a tuple of the shape of the underlying data.
       :name: ex_series_shape

    .. command-output:: python ./series/series_shape.py
       :cwd: ../../../examples

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series attribute :attr:`pandas.Series.shape` implementation

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_shape1
    """

    _func_name = 'Attribute shape.'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    def hpat_pandas_series_shape_impl(self):
        return self._data.shape

    return hpat_pandas_series_shape_impl 
Example #10
Source File: randomdata.py    From pysystemtrade with GNU General Public License v3.0 5 votes vote down vote up
def generate_noise(Nlength, stdev):
    """
    Generates a series of gaussian noise as a list Nlength

    :param Nlength: total number of returns to generate
    :type Nlength: int

    :param stdev: Standard deviation of noise
    :type stdev: float

    :returns: returns a vector of numbers as a list, length Nlength

    """

    return [gauss(0.0, stdev) for Unused in range(Nlength)] 
Example #11
Source File: randomdata.py    From pysystemtrade with GNU General Public License v3.0 5 votes vote down vote up
def get_raw_price(self, instrument_code):
        """
        Returns a pd.series of prices

        :param instrument_code: instrument to get carry data for
        :type instrument_code: str

        :returns: pd.DataSeries

        >>> ans=RandomData()
        >>> ans.generate_random_data("wibble", 10, 5, 5, 0.0)

        >>> ans.get_raw_price("wibble")
        1980-01-01    0.0
        1980-01-02    1.0
        1980-01-03    2.0
        1980-01-04    3.0
        1980-01-07    4.0
        1980-01-08    5.0
        1980-01-09    4.0
        1980-01-10    3.0
        1980-01-11    2.0
        1980-01-14    1.0
        Freq: B, dtype: float64

        """

        if instrument_code in self.get_instrument_list():
            ## must have been cached
            return self._price_cache_random_data[instrument_code]

        error_msg = "No price found for %s you need to run .generate_random_data(instrument_code=%s....)" % (
            instrument_code, instrument_code)
        self.log.critical(error_msg) 
Example #12
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def inverse(self, x):
        """
        Inverse transform array|series x
        """
        try:
            return self.trans.inverse(x)
        except TypeError:
            return np.array([self.trans.inverse(val) for val in x]) 
Example #13
Source File: spot.py    From SPOT with GNU General Public License v3.0 5 votes vote down vote up
def fit(self,init_data,data):
        """
        Import data to biDSPOT object
        
        Parameters
	    ----------
	    init_data : list, numpy.array or pandas.Series
		    initial batch to calibrate the algorithm
            
        data : numpy.array
		    data for the run (list, np.array or pd.series)
	
        """
        if isinstance(data,list):
            self.data = np.array(data)
        elif isinstance(data,np.ndarray):
            self.data = data
        elif isinstance(data,pd.Series):
            self.data = data.values
        else:
            print('This data format (%s) is not supported' % type(data))
            return
            
        if isinstance(init_data,list):
            self.init_data = np.array(init_data)
        elif isinstance(init_data,np.ndarray):
            self.init_data = init_data
        elif isinstance(init_data,pd.Series):
            self.init_data = init_data.values
        elif isinstance(init_data,int):
            self.init_data = self.data[:init_data]
            self.data = self.data[init_data:]
        elif isinstance(init_data,float) & (init_data<1) & (init_data>0):
            r = int(init_data*data.size)
            self.init_data = self.data[:r]
            self.data = self.data[r:]
        else:
            print('The initial data cannot be set')
            return 
Example #14
Source File: QADataStruct.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def order(self):
        """return the order num of transaction/ for everyday change

        Decorators:
            lru_cache

        Returns:
            pd.series -- [description]
        """

        return self.data.order 
Example #15
Source File: comparison_plot_data_preparation.py    From estimagic with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _create_plot_info(x_min, x_max, rect_width, y_max, plot_height):
    """Return the information on the plot specs in one dictionary.

    Args:
        x_min (pd.Series): see _calculate_x_bounds
        x_max (pd.series): see _calculate_x_bounds
        rect_width (pd.Series): The index are the parameter groups. The values
            are the rectangle widths used in each group
        y_max (float): maximum number of parameters that fall into one bin
        plot_height (int): Plot height in pixels.

    Returns:
        plot_info (dict): of the form:
            plot_height: plot_height
            y_range: (0, y_max)
            group_info:
                group: {x_range: x_range, width: rect_width}
    """
    group_plot_info = pd.concat([x_min, x_max, rect_width], axis=1)
    group_plot_info["x_range"] = group_plot_info.apply(
        lambda x: (x["x_min"], x["x_max"]), axis=1
    )
    group_plot_info.drop(columns=["x_min", "x_max"], inplace=True)
    group_plot_info = group_plot_info.T.to_dict()
    plot_info = {
        "plot_height": plot_height,
        "y_range": (0, y_max),
        "group_info": group_plot_info,
    }
    return plot_info 
Example #16
Source File: spot.py    From SPOT with GNU General Public License v3.0 5 votes vote down vote up
def fit(self,init_data,data):
        """
        Import data to SPOT object
        
        Parameters
	    ----------
	    init_data : list, numpy.array or pandas.Series
		    initial batch to calibrate the algorithm
            
        data : numpy.array
		    data for the run (list, np.array or pd.series)
	
        """
        if isinstance(data,list):
            self.data = np.array(data)
        elif isinstance(data,np.ndarray):
            self.data = data
        elif isinstance(data,pd.Series):
            self.data = data.values
        else:
            print('This data format (%s) is not supported' % type(data))
            return
            
        if isinstance(init_data,list):
            self.init_data = np.array(init_data)
        elif isinstance(init_data,np.ndarray):
            self.init_data = init_data
        elif isinstance(init_data,pd.Series):
            self.init_data = init_data.values
        elif isinstance(init_data,int):
            self.init_data = self.data[:init_data]
            self.data = self.data[init_data:]
        elif isinstance(init_data,float) & (init_data<1) & (init_data>0):
            r = int(init_data*data.size)
            self.init_data = self.data[:r]
            self.data = self.data[r:]
        else:
            print('The initial data cannot be set')
            return 
Example #17
Source File: spot.py    From SPOT with GNU General Public License v3.0 5 votes vote down vote up
def fit(self,init_data,data):
        """
        Import data to biSPOT object
        
        Parameters
	    ----------
	    init_data : list, numpy.array or pandas.Series
		    initial batch to calibrate the algorithm ()
            
        data : numpy.array
		    data for the run (list, np.array or pd.series)
	
        """
        if isinstance(data,list):
            self.data = np.array(data)
        elif isinstance(data,np.ndarray):
            self.data = data
        elif isinstance(data,pd.Series):
            self.data = data.values
        else:
            print('This data format (%s) is not supported' % type(data))
            return
            
        if isinstance(init_data,list):
            self.init_data = np.array(init_data)
        elif isinstance(init_data,np.ndarray):
            self.init_data = init_data
        elif isinstance(init_data,pd.Series):
            self.init_data = init_data.values
        elif isinstance(init_data,int):
            self.init_data = self.data[:init_data]
            self.data = self.data[init_data:]
        elif isinstance(init_data,float) & (init_data<1) & (init_data>0):
            r = int(init_data*data.size)
            self.init_data = self.data[:r]
            self.data = self.data[r:]
        else:
            print('The initial data cannot be set')
            return 
Example #18
Source File: spot.py    From SPOT with GNU General Public License v3.0 5 votes vote down vote up
def fit(self,init_data,data):
        """
        Import data to DSPOT object
        
        Parameters
	    ----------
	    init_data : list, numpy.array or pandas.Series
		    initial batch to calibrate the algorithm
            
        data : numpy.array
		    data for the run (list, np.array or pd.series)
	
        """
        if isinstance(data,list):
            self.data = np.array(data)
        elif isinstance(data,np.ndarray):
            self.data = data
        elif isinstance(data,pd.Series):
            self.data = data.values
        else:
            print('This data format (%s) is not supported' % type(data))
            return
            
        if isinstance(init_data,list):
            self.init_data = np.array(init_data)
        elif isinstance(init_data,np.ndarray):
            self.init_data = init_data
        elif isinstance(init_data,pd.Series):
            self.init_data = init_data.values
        elif isinstance(init_data,int):
            self.init_data = self.data[:init_data]
            self.data = self.data[init_data:]
        elif isinstance(init_data,float) & (init_data<1) & (init_data>0):
            r = int(init_data*data.size)
            self.init_data = self.data[:r]
            self.data = self.data[r:]
        else:
            print('The initial data cannot be set')
            return 
Example #19
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def transform(self, x):
        """
        Transform array|series x
        """
        try:
            return self.trans.transform(x)
        except TypeError:
            return np.array([self.trans.transform(val) for val in x]) 
Example #20
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def train(self, x):
        """
        Train scale

        Parameters
        ----------
        x: pd.series | np.array
            a column of data to train over
        """
        raise NotImplementedError('Not Implemented') 
Example #21
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def inverse(self, x):
        """
        Inverse transform array|series x
        """
        raise NotImplementedError('Not Implemented') 
Example #22
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def transform(self, x):
        """
        Transform array|series x
        """
        # Discrete scales do not do transformations
        return x 
Example #23
Source File: scale.py    From plotnine with GNU General Public License v2.0 5 votes vote down vote up
def transform(self, x):
        """
        Transform array|series x
        """
        raise NotImplementedError('Not Implemented') 
Example #24
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def hpat_pandas_series_head(self, n=5):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.head

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_head.py
       :language: python
       :lines: 34-
       :caption: Getting the first n rows.
       :name: ex_series_head

    .. command-output:: python ./series/series_head.py
       :cwd: ../../../examples

    .. seealso::

        :ref:`DataFrame.tail <pandas.DataFrame.tail>`

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series method :meth:`pandas.Series.head` implementation.

    .. only:: developer
        Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_head*
    """

    _func_name = 'Method head().'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    if not isinstance(n, (types.Integer, types.Omitted, types.NoneType)) and n != 5:
        ty_checker.raise_exc(n, 'int', 'n')

    if isinstance(self.index, types.NoneType):
        def hpat_pandas_series_head_impl(self, n=5):
            return pandas.Series(data=self._data[:n], name=self._name)

        return hpat_pandas_series_head_impl
    else:
        def hpat_pandas_series_head_index_impl(self, n=5):
            return pandas.Series(data=self._data[:n], index=self._index[:n], name=self._name)

        return hpat_pandas_series_head_index_impl 
Example #25
Source File: sdc_autogenerated.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def sdc_pandas_series_operator_ne(self, other):
    """
    Pandas Series operator :attr:`pandas.Series.ne` implementation

    .. only:: developer

    **Test**: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_op7*
              python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_operator_ne*

    Parameters
    ----------
    series: :obj:`pandas.Series`
        Input series
    other: :obj:`pandas.Series` or :obj:`scalar`
        Series or scalar value to be used as a second argument of binary operation

    Returns
    -------
    :obj:`pandas.Series`
        The result of the operation
    """

    _func_name = 'Operator ne().'
    ty_checker = TypeChecker(_func_name)
    self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType)
    if not (self_is_series or other_is_series):
        return None

    if not isinstance(self, (SeriesType, types.Number, types.UnicodeType)):
        ty_checker.raise_exc(self, 'pandas.series or scalar', 'self')

    if not isinstance(other, (SeriesType, types.Number, types.UnicodeType)):
        ty_checker.raise_exc(other, 'pandas.series or scalar', 'other')

    operands_are_series = self_is_series and other_is_series
    if operands_are_series:
        none_or_numeric_indexes = ((isinstance(self.index, types.NoneType) or check_index_is_numeric(self))
                                   and (isinstance(other.index, types.NoneType) or check_index_is_numeric(other)))
        series_indexes_comparable = check_types_comparable(self.index, other.index) or none_or_numeric_indexes
        if not series_indexes_comparable:
            raise TypingError('{} Not implemented for series with not-comparable indexes. \
            Given: self.index={}, other.index={}'.format(_func_name, self.index, other.index))

    series_data_comparable = check_types_comparable(self, other)
    if not series_data_comparable:
        raise TypingError('{} Not supported for not-comparable operands. \
        Given: self={}, other={}'.format(_func_name, self, other))

    def sdc_pandas_series_operator_ne_impl(self, other):
        return self.ne(other)

    return sdc_pandas_series_operator_ne_impl 
Example #26
Source File: _sax.py    From sktime with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def transform(self, X, y=None):
        """

        Parameters
        ----------
        X : nested pandas DataFrame of shape [n_instances, 1]
            Nested dataframe with univariate time-series in cells.

        Returns
        -------
        dims: Pandas data frame with first dimension in column zero
        """
        self.check_is_fitted()
        X = check_X(X, enforce_univariate=True)
        X = tabularize(X, return_array=True)

        if self.alphabet_size < 2 or self.alphabet_size > 4:
            raise RuntimeError(
                "Alphabet size must be an integer between 2 and 4")
        if self.word_length < 1 or self.word_length > 16:
            raise RuntimeError(
                "Word length must be an integer between 1 and 16")

        breakpoints = self._generate_breakpoints()
        n_instances, series_length = X.shape

        bags = pd.DataFrame()
        dim = []

        for i in range(n_instances):
            bag = {}
            lastWord = None

            words = []

            num_windows_per_inst = series_length - self.window_size + 1
            split = np.array(X[i, np.arange(self.window_size)[None, :]
                               + np.arange(num_windows_per_inst)[:, None]])

            split = scipy.stats.zscore(split, axis=1)

            paa = PAA(num_intervals=self.word_length)
            data = pd.DataFrame()
            data[0] = [pd.Series(x, dtype=np.float32) for x in split]
            patterns = paa.fit_transform(data)
            patterns = np.asarray([a.values for a in patterns.iloc[:, 0]])

            for n in range(patterns.shape[0]):
                pattern = patterns[n, :]
                word = self._create_word(pattern, breakpoints)
                words.append(word)
                lastWord = self._add_to_bag(bag, word, lastWord)

            if self.save_words:
                self.words.append(words)

            dim.append(pd.Series(bag))

        bags[0] = dim

        return bags 
Example #27
Source File: sdc_function_templates.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def sdc_pandas_series_operator_comp_binop(self, other):
    """
    Pandas Series operator :attr:`pandas.Series.comp_binop` implementation

    .. only:: developer

    **Test**: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_op7*
              python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_operator_comp_binop*

    Parameters
    ----------
    series: :obj:`pandas.Series`
        Input series
    other: :obj:`pandas.Series` or :obj:`scalar`
        Series or scalar value to be used as a second argument of binary operation

    Returns
    -------
    :obj:`pandas.Series`
        The result of the operation
    """

    _func_name = 'Operator comp_binop().'
    ty_checker = TypeChecker(_func_name)
    self_is_series, other_is_series = isinstance(self, SeriesType), isinstance(other, SeriesType)
    if not (self_is_series or other_is_series):
        return None

    if not isinstance(self, (SeriesType, types.Number, types.UnicodeType)):
        ty_checker.raise_exc(self, 'pandas.series or scalar', 'self')

    if not isinstance(other, (SeriesType, types.Number, types.UnicodeType)):
        ty_checker.raise_exc(other, 'pandas.series or scalar', 'other')

    operands_are_series = self_is_series and other_is_series
    if operands_are_series:
        none_or_numeric_indexes = ((isinstance(self.index, types.NoneType) or check_index_is_numeric(self))
                                   and (isinstance(other.index, types.NoneType) or check_index_is_numeric(other)))
        series_indexes_comparable = check_types_comparable(self.index, other.index) or none_or_numeric_indexes
        if not series_indexes_comparable:
            raise TypingError('{} Not implemented for series with not-comparable indexes. \
            Given: self.index={}, other.index={}'.format(_func_name, self.index, other.index))

    series_data_comparable = check_types_comparable(self, other)
    if not series_data_comparable:
        raise TypingError('{} Not supported for not-comparable operands. \
        Given: self={}, other={}'.format(_func_name, self, other))

    def sdc_pandas_series_operator_comp_binop_impl(self, other):
        return self.comp_binop(other)

    return sdc_pandas_series_operator_comp_binop_impl 
Example #28
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def sdc_pandas_series_skew(self, axis=None, skipna=None, level=None, numeric_only=None):
    """
        Intel Scalable Dataframe Compiler User Guide
        ********************************************

        Pandas API: pandas.Series.skew

        Limitations
        -----------
        - Parameters ``level`` and ``numeric_only`` are supported only with default value ``None``.

        Examples
        --------
        .. literalinclude:: ../../../examples/series/series_skew.py
           :language: python
           :lines: 27-
           :caption: Unbiased rolling skewness.
           :name: ex_series_skew

        .. command-output:: python ./series/series_skew.py
           :cwd: ../../../examples

        Intel Scalable Dataframe Compiler Developer Guide
        *************************************************
        Pandas Series method :meth:`pandas.Series.skew` implementation.

        .. only:: developer
            Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_skew*
        """
    _func_name = 'Method Series.skew().'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    if not isinstance(axis, (types.Integer, types.NoneType, types.Omitted)) and axis is not None:
        ty_checker.raise_exc(axis, 'int64', 'axis')

    if not isinstance(skipna, (types.Boolean, types.NoneType, types.Omitted)) and skipna is not None:
        ty_checker.raise_exc(skipna, 'bool', 'skipna')

    if not isinstance(level, (types.Omitted, types.NoneType)) and level is not None:
        ty_checker.raise_exc(level, 'None', 'level')

    if not isinstance(numeric_only, (types.Omitted, types.NoneType)) and numeric_only is not None:
        ty_checker.raise_exc(numeric_only, 'None', 'numeric_only')

    def sdc_pandas_series_skew_impl(self, axis=None, skipna=None, level=None, numeric_only=None):
        if axis != 0 and axis is not None:
            raise ValueError('Parameter axis must be only 0 or None.')

        if skipna is None:
            _skipna = True
        else:
            _skipna = skipna

        if _skipna:
            return numpy_like.nanskew(self._data)

        return numpy_like.skew(self._data)

    return sdc_pandas_series_skew_impl 
Example #29
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def hpat_pandas_series_cumsum(self, axis=None, skipna=True):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.cumsum

    Limitations
    -----------
    Parameter ``axis`` is supported only with default value ``None``.

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_cumsum.py
       :language: python
       :lines: 27-
       :caption: Returns cumulative sum over Series.
       :name: ex_series_cumsum

    .. command-output:: python ./series/series_cumsum.py
       :cwd: ../../../examples

    .. seealso::
        :ref:`Series.sum <pandas.Series.sum>`
            Return the sum over Series.
        :ref:`Series.cummax <pandas.Series.cummax>`
            Return cumulative maximum over Series.
        :ref:`Series.cummin <pandas.Series.cummin>`
            Return cumulative minimum over Series.
        :ref:`Series.cumprod <pandas.Series.cumprod>`
            Return cumulative product over Series.

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************

    Pandas Series method :meth:`pandas.Series.cumsum` implementation.

    .. only:: developer
        Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_cumsum*
    """

    _func_name = 'Method cumsum().'

    ty_checker = TypeChecker(_func_name)
    ty_checker.check(self, SeriesType)

    if not isinstance(self.data.dtype, types.Number):
        ty_checker.raise_exc(self.data.dtype, 'numeric', 'self.data.dtype')

    if not isinstance(axis, (types.Omitted, types.NoneType)) and axis is not None:
        ty_checker.raise_exc(axis, 'None', 'axis')

    def hpat_pandas_series_cumsum_impl(self, axis=None, skipna=True):
        if skipna:
            return pandas.Series(numpy_like.nancumsum(self._data, like_pandas=True))
        return pandas.Series(numpy_like.cumsum(self._data))

    return hpat_pandas_series_cumsum_impl 
Example #30
Source File: hpat_pandas_series_functions.py    From sdc with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def hpat_pandas_series_unique(self):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************

    Pandas API: pandas.Series.unique

    Limitations
    -----------
    - Return values order is unspecified
    - This function may reveal slower performance than Pandas* on user system. Users should exercise a tradeoff
    between staying in JIT-region with that function or going back to interpreter mode.

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_unique.py
       :language: python
       :lines: 27-
       :caption: Getting unique values in Series
       :name: ex_series_unique

    .. command-output:: python ./series/series_unique.py
       :cwd: ../../../examples

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series method :meth:`pandas.Series.unique` implementation.

    .. only:: developer
        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_unique_sorted
    """

    ty_checker = TypeChecker('Method unique().')
    ty_checker.check(self, SeriesType)

    if isinstance(self.data, StringArrayType):
        def hpat_pandas_series_unique_str_impl(self):
            '''
            Returns sorted unique elements of an array
            Note: Can't use Numpy due to StringArrayType has no ravel() for noPython mode.
            Also, NotImplementedError: unicode_type cannot be represented as a Numpy dtype

            Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_unique_str
            '''

            str_set = set(self._data)
            return to_array(str_set)

        return hpat_pandas_series_unique_str_impl

    def hpat_pandas_series_unique_impl(self):
        '''
        Returns sorted unique elements of an array

        Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_unique
        '''

        return numpy.unique(self._data)

    return hpat_pandas_series_unique_impl