(self, idx)
Intel Scalable Dataframe Compiler User Guide
    ********************************************
    Pandas API: pandas.Series.getitem

    Get value(s) of Series by key.

    Limitations
    -----------
    Supported ``key`` can be one of the following:
        - Integer scalar, e.g. :obj:`series[0]`
        - An array or a list, e.g. :obj:`series[0,2,5]`
        - A list of booleans, e.g. :obj:`series[True,False]`
        - A slice, e.g. :obj:`series[2:5]`
        - Another series

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_scalar_single_result.py
       :language: python
       :lines: 32-
       :caption: Getting Pandas Series elements. Returns single value.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_scalar_single_result.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_scalar_multiple_result.py
       :language: python
       :lines: 34-
       :caption: Getting Pandas Series elements. Returns multiple value.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_scalar_multiple_result.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_slice.py
       :language: python
       :lines: 35-
       :caption: Getting Pandas Series elements by slice.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_slice.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_bool_array.py
       :language: python
       :lines: 37-
       :caption: Getting Pandas Series elements by array of booleans.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_bool_array.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_series.py
       :language: python
       :lines: 36-
       :caption: Getting Pandas Series elements by another Series.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_series.py
       :cwd: ../../../examples

    .. seealso::
        :ref:`Series.setitem <pandas.Series.setitem>`
            Set value to Series by index
        :ref:`Series.loc <pandas.Series.loc>`
            Access a group of rows and columns by label(s) or a boolean array.
        :ref:`Series.iloc <pandas.Series.iloc>`
            Purely integer-location based indexing for selection by position.
        :ref:`Series.at <pandas.Series.at>`
            Access a single value for a row/column label pair.
        :ref:`Series.iat <pandas.Series.iat>`
            Access a single value for a row/column pair by integer position.
        :ref:`DataFrame.getitem <pandas.DataFrame.getitem>`
            Get data from a DataFrame by indexer.
        :ref:`DataFrame.setitem <pandas.DataFrame.setitem>`
            Set value to DataFrame by index
        :ref:`DataFrame.loc <pandas.DataFrame.loc>`
            Access a group of rows and columns by label(s) or a boolean array.
        :ref:`DataFrame.iloc <pandas.DataFrame.iloc>`
            Purely integer-location based indexing for selection by position.
        :ref:`DataFrame.at <pandas.DataFrame.at>`
            Access a single value for a row/column label pair.
        :ref:`DataFrame.iat <pandas.DataFrame.iat>`
            Access a single value for a row/column pair by integer position.

    .. todo:: Fix SDC behavior and add the expected output of the > python ./series_getitem.py to the docstring

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series operator :attr:`pandas.Series.__getitem__` implementation

    .. only:: developer
        Test: python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_getitem*
Intel Scalable Dataframe Compiler User Guide
    ********************************************
    Pandas API: pandas.Series.getitem
Intel Scalable Dataframe Compiler User Guide ******************************************** Pandas API : pandas . Series . getitem
def hpat_pandas_series_getitem(self, idx):
    """
    Intel Scalable Dataframe Compiler User Guide
    ********************************************
    Pandas API: pandas.Series.getitem

    Get value(s) of Series by key.

    Limitations
    -----------
    Supported ``key`` can be one of the following:
        - Integer scalar, e.g. :obj:`series[0]`
        - An array or a list, e.g. :obj:`series[0,2,5]`
        - A list of booleans, e.g. :obj:`series[True,False]`
        - A slice, e.g. :obj:`series[2:5]`
        - Another series

    Examples
    --------
    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_scalar_single_result.py
       :language: python
       :lines: 32-
       :caption: Getting Pandas Series elements. Returns single value.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_scalar_single_result.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_scalar_multiple_result.py
       :language: python
       :lines: 34-
       :caption: Getting Pandas Series elements. Returns multiple value.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_scalar_multiple_result.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_slice.py
       :language: python
       :lines: 35-
       :caption: Getting Pandas Series elements by slice.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_slice.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_bool_array.py
       :language: python
       :lines: 37-
       :caption: Getting Pandas Series elements by array of booleans.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_bool_array.py
       :cwd: ../../../examples

    .. literalinclude:: ../../../examples/series/series_getitem/series_getitem_series.py
       :language: python
       :lines: 36-
       :caption: Getting Pandas Series elements by another Series.
       :name: ex_series_getitem

    .. command-output:: python ./series/series_getitem/series_getitem_series.py
       :cwd: ../../../examples

    .. seealso::
        :ref:`Series.setitem <pandas.Series.setitem>`
            Set value to Series by index
        :ref:`Series.loc <pandas.Series.loc>`
            Access a group of rows and columns by label(s) or a boolean array.
        :ref:`Series.iloc <pandas.Series.iloc>`
            Purely integer-location based indexing for selection by position.
        :ref:`Series.at <pandas.Series.at>`
            Access a single value for a row/column label pair.
        :ref:`Series.iat <pandas.Series.iat>`
            Access a single value for a row/column pair by integer position.
        :ref:`DataFrame.getitem <pandas.DataFrame.getitem>`
            Get data from a DataFrame by indexer.
        :ref:`DataFrame.setitem <pandas.DataFrame.setitem>`
            Set value to DataFrame by index
        :ref:`DataFrame.loc <pandas.DataFrame.loc>`
            Access a group of rows and columns by label(s) or a boolean array.
        :ref:`DataFrame.iloc <pandas.DataFrame.iloc>`
            Purely integer-location based indexing for selection by position.
        :ref:`DataFrame.at <pandas.DataFrame.at>`
            Access a single value for a row/column label pair.
        :ref:`DataFrame.iat <pandas.DataFrame.iat>`
            Access a single value for a row/column pair by integer position.

    .. todo:: Fix SDC behavior and add the expected output of the > python ./series_getitem.py to the docstring

    Intel Scalable Dataframe Compiler Developer Guide
    *************************************************
    Pandas Series operator :attr:`pandas.Series.__getitem__` implementation

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

    _func_name = 'Operator getitem().'

    if not isinstance(self, SeriesType):
        return None

    # Note: Getitem return Series
    index_is_positional = isinstance(self.index, PositionalIndexType)
    index_is_numeric = isinstance(self.index.dtype, types.Number)
    index_is_string = isinstance(self.index.dtype, types.UnicodeType)

    if (
        isinstance(idx, types.Number) and index_is_numeric or
        (isinstance(idx, (types.UnicodeType, types.StringLiteral)) and index_is_string)
    ):
        def hpat_pandas_series_getitem_index_impl(self, idx):
            index = self._index
            mask = numpy.empty(len(self._data), numpy.bool_)
            for i in numba.prange(len(index)):
                mask[i] = index[i] == idx
            return pandas.Series(data=self._data[mask], index=index[mask], name=self._name)

        return hpat_pandas_series_getitem_index_impl

    if (isinstance(idx, types.Integer) and index_is_string):
        def hpat_pandas_series_idx_impl(self, idx):
            return self._data[idx]

        return hpat_pandas_series_idx_impl

    if isinstance(idx, types.SliceType):
        # Return slice for str values not implement
        def hpat_pandas_series_getitem_idx_slice_impl(self, idx):
            return pandas.Series(data=self._data[idx], index=self.index[idx], name=self._name)

        return hpat_pandas_series_getitem_idx_slice_impl

    if (isinstance(idx, (types.List, types.Array))
            and isinstance(idx.dtype, types.Boolean)):
        def hpat_pandas_series_getitem_idx_list_impl(self, idx):

            if len(self) != len(idx):
                raise IndexError('Boolean index has wrong length')

            return pandas.Series(
                data=numpy_like.getitem_by_mask(self._data, idx),
                index=numpy_like.getitem_by_mask(self.index, idx),
                name=self._name
            )

        return hpat_pandas_series_getitem_idx_list_impl

    # idx is Series and it's index is any, idx.dtype is Boolean
    if (isinstance(idx, SeriesType) and isinstance(idx.dtype, types.Boolean)):

        positional_indexes = (isinstance(self.index, PositionalIndexType)
                              and isinstance(idx.index, PositionalIndexType))
        if not check_types_comparable(self.index, idx.index):
            msg = '{} The index of boolean indexer is not comparable to Series index.' + \
                  ' Given: self.index={}, idx.index={}'
            raise TypingError(msg.format(_func_name, self.index, idx.index))

        def _series_getitem_idx_bool_indexer_impl(self, idx):

            # TO-DO: replace sdc_reindex_series with reindex methods and move this logic to impl
            # for specific index types (needs proper index type instead of types.none as index)
            if positional_indexes == True:  # noqa
                if len(self) > len(idx):
                    msg = "Unalignable boolean Series provided as indexer " + \
                          "(index of the boolean Series and of the indexed object do not match)."
                    raise IndexingError(msg)

                self_index = self.index
                reindexed_idx = idx
            else:
                self_index = self.index
                reindexed_idx = sdc_reindex_series(idx._data, idx.index, idx._name, self_index)

            return pandas.Series(
                data=numpy_like.getitem_by_mask(self._data, reindexed_idx._data),
                index=numpy_like.getitem_by_mask(self_index, reindexed_idx._data),
                name=self._name
            )

        return _series_getitem_idx_bool_indexer_impl

    # idx is Series and it's index is PositionalIndex, idx.dtype is not Boolean
    if (isinstance(idx, SeriesType) and index_is_positional
            and not isinstance(idx.data.dtype, (types.Boolean, bool))):
        def hpat_pandas_series_getitem_idx_list_impl(self, idx):
            idx_data = idx._data
            self_data = self._data
            res = numpy.copy(self._data[:len(idx_data)])
            index = numpy.arange(len(self_data))
            for i in numba.prange(len(res)):
                for j in numba.prange(len(index)):
                    if j == idx_data[i]:
                        res[i] = self_data[j]
            return pandas.Series(data=res, index=index[idx_data], name=self._name)
        return hpat_pandas_series_getitem_idx_list_impl

    # idx is Series and it's index is not PositionalIndex, idx.dtype is not Boolean
    if (isinstance(idx, SeriesType) and not isinstance(self.index, PositionalIndexType)
            and not isinstance(idx.data.dtype, (types.Boolean, bool))):
        def hpat_pandas_series_getitem_idx_series_impl(self, idx):
            index = self.index
            data = self._data
            size = len(index)
            data_res = []
            index_res = []
            for value in idx._data:
                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._name)

        return hpat_pandas_series_getitem_idx_series_impl


    raise TypingError('{} The index must be an Number, Slice, String, Boolean Array or a Series.\
                    Given: {}'.format(_func_name, idx))
def hpat_pandas_series_getitem ( self , idx ) : _func_name = 'Operator getitem().' if not isinstance ( self , SeriesType ) : return None # Note: Getitem return Series index_is_positional = isinstance ( self . index , PositionalIndexType ) index_is_numeric = isinstance ( self . index . dtype , types . Number ) index_is_string = isinstance ( self . index . dtype , types . UnicodeType ) if ( isinstance ( idx , types . Number ) and index_is_numeric or ( isinstance ( idx , ( types . UnicodeType , types . StringLiteral ) ) and index_is_string ) ) : def hpat_pandas_series_getitem_index_impl ( self , idx ) : index = self . _index mask = numpy . empty ( len ( self . _data ) , numpy . bool_ ) for i in numba . prange ( len ( index ) ) : mask [ i ] = index [ i ] == idx return pandas . Series ( data = self . _data [ mask ] , index = index [ mask ] , name = self . _name ) return hpat_pandas_series_getitem_index_impl if ( isinstance ( idx , types . Integer ) and index_is_string ) : def hpat_pandas_series_idx_impl ( self , idx ) : return self . _data [ idx ] return hpat_pandas_series_idx_impl if isinstance ( idx , types . SliceType ) : # Return slice for str values not implement def hpat_pandas_series_getitem_idx_slice_impl ( self , idx ) : return pandas . Series ( data = self . _data [ idx ] , index = self . index [ idx ] , name = self . _name ) return hpat_pandas_series_getitem_idx_slice_impl if ( isinstance ( idx , ( types . List , types . Array ) ) and isinstance ( idx . dtype , types . Boolean ) ) : def hpat_pandas_series_getitem_idx_list_impl ( self , idx ) : if len ( self ) != len ( idx ) : raise IndexError ( 'Boolean index has wrong length' ) return pandas . Series ( data = numpy_like . getitem_by_mask ( self . _data , idx ) , index = numpy_like . getitem_by_mask ( self . index , idx ) , name = self . _name ) return hpat_pandas_series_getitem_idx_list_impl # idx is Series and it's index is any, idx.dtype is Boolean if ( isinstance ( idx , SeriesType ) and isinstance ( idx . dtype , types . Boolean ) ) : positional_indexes = ( isinstance ( self . index , PositionalIndexType ) and isinstance ( idx . index , PositionalIndexType ) ) if not check_types_comparable ( self . index , idx . index ) : msg = '{} The index of boolean indexer is not comparable to Series index.' + ' Given: self.index={}, idx.index={}' raise TypingError ( msg . format ( _func_name , self . index , idx . index ) ) def _series_getitem_idx_bool_indexer_impl ( self , idx ) : # TO-DO: replace sdc_reindex_series with reindex methods and move this logic to impl # for specific index types (needs proper index type instead of types.none as index) if positional_indexes == True : # noqa if len ( self ) > len ( idx ) : msg = "Unalignable boolean Series provided as indexer " + "(index of the boolean Series and of the indexed object do not match)." raise IndexingError ( msg ) self_index = self . index reindexed_idx = idx else : self_index = self . index reindexed_idx = sdc_reindex_series ( idx . _data , idx . index , idx . _name , self_index ) return pandas . Series ( data = numpy_like . getitem_by_mask ( self . _data , reindexed_idx . _data ) , index = numpy_like . getitem_by_mask ( self_index , reindexed_idx . _data ) , name = self . _name ) return _series_getitem_idx_bool_indexer_impl # idx is Series and it's index is PositionalIndex, idx.dtype is not Boolean if ( isinstance ( idx , SeriesType ) and index_is_positional and not isinstance ( idx . data . dtype , ( types . Boolean , bool ) ) ) : def hpat_pandas_series_getitem_idx_list_impl ( self , idx ) : idx_data = idx . _data self_data = self . _data res = numpy . copy ( self . _data [ : len ( idx_data ) ] ) index = numpy . arange ( len ( self_data ) ) for i in numba . prange ( len ( res ) ) : for j in numba . prange ( len ( index ) ) : if j == idx_data [ i ] : res [ i ] = self_data [ j ] return pandas . Series ( data = res , index = index [ idx_data ] , name = self . _name ) return hpat_pandas_series_getitem_idx_list_impl # idx is Series and it's index is not PositionalIndex, idx.dtype is not Boolean if ( isinstance ( idx , SeriesType ) and not isinstance ( self . index , PositionalIndexType ) and not isinstance ( idx . data . dtype , ( types . Boolean , bool ) ) ) : def hpat_pandas_series_getitem_idx_series_impl ( self , idx ) : index = self . index data = self . _data size = len ( index ) data_res = [ ] index_res = [ ] for value in idx . _data : 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 . _name ) return hpat_pandas_series_getitem_idx_series_impl raise TypingError ( '{} The index must be an Number, Slice, String, Boolean Array or a Series.\
                    Given: {}' . format ( _func_name , idx ) )