(self, idx)
Pandas Series operator :attr:`pandas.Series.__getitem__` implementation
    for methods `pandas.Series.iloc`, `pandas.Series.loc`, `pandas.Series.iat`, `pandas.Series.at`

    Parameters
    ----------
    self: :class:`pandas.Series`
        input Series
    other: :obj:`pandas.Series`, :obj:`int` or :obj:`float`, :obj:`slice`, :obj:`list`
        input arg

    Returns
    -------
    :class:`pandas.Series` or a value of :obj:`pandas.Series.dtype`
        returns object
Pandas Series operator :attr:`pandas.Series.__getitem__` implementation
    for methods `pandas.Series.iloc`, `pandas.Series.loc`, `pandas.Series.iat`, `pandas.Series.at`
Pandas Series operator : attr : pandas . Series . __getitem__ implementation for methods pandas . Series . iloc pandas . Series . loc pandas . Series . iat pandas . Series . at
def hpat_pandas_series_accessor_getitem(self, idx):
    """
    Pandas Series operator :attr:`pandas.Series.__getitem__` implementation
    for methods `pandas.Series.iloc`, `pandas.Series.loc`, `pandas.Series.iat`, `pandas.Series.at`

    Parameters
    ----------
    self: :class:`pandas.Series`
        input Series
    other: :obj:`pandas.Series`, :obj:`int` or :obj:`float`, :obj:`slice`, :obj:`list`
        input arg

    Returns
    -------
    :class:`pandas.Series` or a value of :obj:`pandas.Series.dtype`
        returns object
    """

    _func_name = 'Operator getitem().'

    if not isinstance(self, SeriesGetitemAccessorType):
        return None

    accessor = self.accessor.literal_value

    if accessor == 'iloc':
        if isinstance(idx, (types.List, types.Array, types.SliceType)):
            def hpat_pandas_series_iloc_list_slice_impl(self, idx):
                result_data = self._series._data[idx]
                result_index = self._series.index[idx]
                return pandas.Series(data=result_data, index=result_index, name=self._series._name)

            return hpat_pandas_series_iloc_list_slice_impl

        if isinstance(idx, (int, types.Integer)):
            def hpat_pandas_series_iloc_impl(self, idx):
                return self._series._data[idx]

            return hpat_pandas_series_iloc_impl

        def hpat_pandas_series_iloc_callable_impl(self, idx):
            index = numpy.asarray(list(map(idx, self._series._data)))
            return pandas.Series(
                data=self._series._data[index],
                index=self._series.index[index],
                name=self._series._name
            )

        return hpat_pandas_series_iloc_callable_impl

        raise TypingError('{} The index must be an Integer, Slice or List of Integer or a callable.\
                    Given: {}'.format(_func_name, idx))

    if accessor == 'iat':
        if isinstance(idx, (int, types.Integer)):
            def hpat_pandas_series_iat_impl(self, idx):
                return self._series._data[idx]

            return hpat_pandas_series_iat_impl

        raise TypingError('{} The index must be a Integer. Given: {}'.format(_func_name, idx))

    if accessor == 'loc':
        # Note: Loc return Series
        # Note: Loc slice and callable with String is not implemented
        # Note: Loc slice without start is not supported
        min_int64 = numpy.iinfo('int64').min
        max_int64 = numpy.iinfo('int64').max
        index_is_positional = isinstance(self.series.index, PositionalIndexType)
        if isinstance(idx, types.SliceType) and not index_is_positional:
            def hpat_pandas_series_loc_slice_impl(self, idx):
                series = self._series
                index = series.index
                start_position = len(index)
                stop_position = 0
                max_diff = 0
                min_diff = 0
                start_position_inc = len(index)
                start_position_dec = len(index)
                stop_position_inc = 0
                stop_position_dec = 0
                idx_start = idx.start
                idx_stop = idx.stop
                for i in numba.prange(len(index)):
                    if index[i] >= idx_start:
                        start_position_inc = min(start_position_inc, i)
                    if index[i] <= idx_start:
                        start_position_dec = min(start_position_dec, i)
                    if index[i] <= idx_stop:
                        stop_position_inc = max(stop_position_inc, i)
                    if index[i] >= idx_stop:
                        stop_position_dec = max(stop_position_dec, i)
                    if i > 0:
                        max_diff = max(max_diff, index[i] - index[i - 1])
                        min_diff = min(min_diff, index[i] - index[i - 1])

                if max_diff*min_diff < 0:
                    raise ValueError("Index must be monotonic increasing or decreasing")

                if max_diff > 0:
                    start_position = start_position_inc
                    stop_position = stop_position_inc
                    if idx_stop < index[0]:
                        return pandas.Series(data=series._data[:0], index=series._index[:0], name=series._name)
                else:
                    start_position = start_position_dec
                    stop_position = stop_position_dec if idx.stop != max_int64 else len(index)
                    if idx_stop > index[0] and idx_stop != max_int64:
                        return pandas.Series(data=series._data[:0], index=series._index[:0], name=series._name)

                stop_position = min(stop_position + 1, len(index))

                if (
                    start_position >= len(index) or stop_position <= 0 or stop_position <= start_position
                ):
                    return pandas.Series(data=series._data[:0], index=series._index[:0], name=series._name)

                return pandas.Series(data=series._data[start_position:stop_position],
                                     index=index[start_position:stop_position],
                                     name=series._name)

            return hpat_pandas_series_loc_slice_impl

        if isinstance(idx, types.SliceType) and index_is_positional:
            def hpat_pandas_series_loc_slice_noidx_impl(self, idx):
                max_slice = sys.maxsize
                start = idx.start
                stop = idx.stop
                if idx.stop == max_slice:
                    stop = max_slice - 1
                result_data = self._series._data[start:stop+1]
                result_index = numpy.arange(start, stop + 1)
                return pandas.Series(data=result_data, index=result_index, name=self._series._name)

            return hpat_pandas_series_loc_slice_noidx_impl

        if isinstance(idx, (types.Array, types.List)):
            def hpat_pandas_series_loc_array_impl(self, idx):
                index = self._series.index
                data = self._series._data
                size = len(index)
                data_res = []
                index_res = []
                for value in idx:
                    mask = numpy.zeros(shape=size, dtype=numpy.bool_)
                    for i in numba.prange(size):
                        mask[i] = index[i] == value
                    data_res.extend(data[mask])
                    index_res.extend(index[mask])

                return pandas.Series(data=data_res, index=index_res, name=self._series._name)

            return hpat_pandas_series_loc_array_impl

        if isinstance(idx, (int, types.Integer, types.UnicodeType, types.StringLiteral)):
            def hpat_pandas_series_loc_impl(self, idx):
                index = self._series.index
                mask = numpy.empty(len(self._series._data), numpy.bool_)
                for i in numba.prange(len(index)):
                    mask[i] = index[i] == idx
                return pandas.Series(data=self._series._data[mask], index=index[mask], name=self._series._name)

            return hpat_pandas_series_loc_impl

        raise TypingError('{} The index must be an Number, Slice, String, List, Array or a callable.\
                          Given: {}'.format(_func_name, idx))

    if accessor == 'at':
        if isinstance(idx, (int, types.Integer, types.UnicodeType, types.StringLiteral)):
            def hpat_pandas_series_at_impl(self, idx):
                index = self._series.index
                count = 0
                mask = numpy.empty(len(self._series._data), numpy.bool_)
                for i in numba.prange(len(index)):
                    mask[i] = index[i] == idx
                    if mask[i] == True:  # noqa
                        count += 1
                if count == 0:  # noqa
                    raise ValueError("Index is not in the Series")
                return self._series._data[mask]

            return hpat_pandas_series_at_impl

        raise TypingError('{} The index must be a Number or String. Given: {}'.format(_func_name, idx))

    raise TypingError('{} Unknown accessor. Only "loc", "iloc", "at", "iat" are supported.\
                      Given: {}'.format(_func_name, accessor))
def hpat_pandas_series_accessor_getitem ( self , idx ) : _func_name = 'Operator getitem().' if not isinstance ( self , SeriesGetitemAccessorType ) : return None accessor = self . accessor . literal_value if accessor == 'iloc' : if isinstance ( idx , ( types . List , types . Array , types . SliceType ) ) : def hpat_pandas_series_iloc_list_slice_impl ( self , idx ) : result_data = self . _series . _data [ idx ] result_index = self . _series . index [ idx ] return pandas . Series ( data = result_data , index = result_index , name = self . _series . _name ) return hpat_pandas_series_iloc_list_slice_impl if isinstance ( idx , ( int , types . Integer ) ) : def hpat_pandas_series_iloc_impl ( self , idx ) : return self . _series . _data [ idx ] return hpat_pandas_series_iloc_impl def hpat_pandas_series_iloc_callable_impl ( self , idx ) : index = numpy . asarray ( list ( map ( idx , self . _series . _data ) ) ) return pandas . Series ( data = self . _series . _data [ index ] , index = self . _series . index [ index ] , name = self . _series . _name ) return hpat_pandas_series_iloc_callable_impl raise TypingError ( '{} The index must be an Integer, Slice or List of Integer or a callable.\
                    Given: {}' . format ( _func_name , idx ) ) if accessor == 'iat' : if isinstance ( idx , ( int , types . Integer ) ) : def hpat_pandas_series_iat_impl ( self , idx ) : return self . _series . _data [ idx ] return hpat_pandas_series_iat_impl raise TypingError ( '{} The index must be a Integer. Given: {}' . format ( _func_name , idx ) ) if accessor == 'loc' : # Note: Loc return Series # Note: Loc slice and callable with String is not implemented # Note: Loc slice without start is not supported min_int64 = numpy . iinfo ( 'int64' ) . min max_int64 = numpy . iinfo ( 'int64' ) . max index_is_positional = isinstance ( self . series . index , PositionalIndexType ) if isinstance ( idx , types . SliceType ) and not index_is_positional : def hpat_pandas_series_loc_slice_impl ( self , idx ) : series = self . _series index = series . index start_position = len ( index ) stop_position = 0 max_diff = 0 min_diff = 0 start_position_inc = len ( index ) start_position_dec = len ( index ) stop_position_inc = 0 stop_position_dec = 0 idx_start = idx . start idx_stop = idx . stop for i in numba . prange ( len ( index ) ) : if index [ i ] >= idx_start : start_position_inc = min ( start_position_inc , i ) if index [ i ] <= idx_start : start_position_dec = min ( start_position_dec , i ) if index [ i ] <= idx_stop : stop_position_inc = max ( stop_position_inc , i ) if index [ i ] >= idx_stop : stop_position_dec = max ( stop_position_dec , i ) if i > 0 : max_diff = max ( max_diff , index [ i ] - index [ i - 1 ] ) min_diff = min ( min_diff , index [ i ] - index [ i - 1 ] ) if max_diff * min_diff < 0 : raise ValueError ( "Index must be monotonic increasing or decreasing" ) if max_diff > 0 : start_position = start_position_inc stop_position = stop_position_inc if idx_stop < index [ 0 ] : return pandas . Series ( data = series . _data [ : 0 ] , index = series . _index [ : 0 ] , name = series . _name ) else : start_position = start_position_dec stop_position = stop_position_dec if idx . stop != max_int64 else len ( index ) if idx_stop > index [ 0 ] and idx_stop != max_int64 : return pandas . Series ( data = series . _data [ : 0 ] , index = series . _index [ : 0 ] , name = series . _name ) stop_position = min ( stop_position + 1 , len ( index ) ) if ( start_position >= len ( index ) or stop_position <= 0 or stop_position <= start_position ) : return pandas . Series ( data = series . _data [ : 0 ] , index = series . _index [ : 0 ] , name = series . _name ) return pandas . Series ( data = series . _data [ start_position : stop_position ] , index = index [ start_position : stop_position ] , name = series . _name ) return hpat_pandas_series_loc_slice_impl if isinstance ( idx , types . SliceType ) and index_is_positional : def hpat_pandas_series_loc_slice_noidx_impl ( self , idx ) : max_slice = sys . maxsize start = idx . start stop = idx . stop if idx . stop == max_slice : stop = max_slice - 1 result_data = self . _series . _data [ start : stop + 1 ] result_index = numpy . arange ( start , stop + 1 ) return pandas . Series ( data = result_data , index = result_index , name = self . _series . _name ) return hpat_pandas_series_loc_slice_noidx_impl if isinstance ( idx , ( types . Array , types . List ) ) : def hpat_pandas_series_loc_array_impl ( self , idx ) : index = self . _series . index data = self . _series . _data size = len ( index ) data_res = [ ] index_res = [ ] for value in idx : mask = numpy . zeros ( shape = size , dtype = numpy . bool_ ) for i in numba . prange ( size ) : mask [ i ] = index [ i ] == value data_res . extend ( data [ mask ] ) index_res . extend ( index [ mask ] ) return pandas . Series ( data = data_res , index = index_res , name = self . _series . _name ) return hpat_pandas_series_loc_array_impl if isinstance ( idx , ( int , types . Integer , types . UnicodeType , types . StringLiteral ) ) : def hpat_pandas_series_loc_impl ( self , idx ) : index = self . _series . index mask = numpy . empty ( len ( self . _series . _data ) , numpy . bool_ ) for i in numba . prange ( len ( index ) ) : mask [ i ] = index [ i ] == idx return pandas . Series ( data = self . _series . _data [ mask ] , index = index [ mask ] , name = self . _series . _name ) return hpat_pandas_series_loc_impl raise TypingError ( '{} The index must be an Number, Slice, String, List, Array or a callable.\
                          Given: {}' . format ( _func_name , idx ) ) if accessor == 'at' : if isinstance ( idx , ( int , types . Integer , types . UnicodeType , types . StringLiteral ) ) : def hpat_pandas_series_at_impl ( self , idx ) : index = self . _series . index count = 0 mask = numpy . empty ( len ( self . _series . _data ) , numpy . bool_ ) for i in numba . prange ( len ( index ) ) : mask [ i ] = index [ i ] == idx if mask [ i ] == True : # noqa count += 1 if count == 0 : # noqa raise ValueError ( "Index is not in the Series" ) return self . _series . _data [ mask ] return hpat_pandas_series_at_impl raise TypingError ( '{} The index must be a Number or String. Given: {}' . format ( _func_name , idx ) ) raise TypingError ( '{} Unknown accessor. Only "loc", "iloc", "at", "iat" are supported.\
                      Given: {}' . format ( _func_name , accessor ) )