Esempio n. 1
0
def _infer_index_type(index):
    """ Deduces native Numba type used to represent index Python object """
    if isinstance(index, pd.RangeIndex):
        # depending on actual index value unbox to diff types: none-index if it matches
        # positions or to RangeIndexType in general case
        if (index.start == 0 and index.step == 1 and index.name is None):
            return types.none
        else:
            if index.name is None:
                return RangeIndexType()
            else:
                return RangeIndexType(is_named=True)

    # for unsupported pandas indexes we explicitly unbox to None
    if isinstance(index, pd.DatetimeIndex):
        return types.none
    if index.dtype == np.dtype('O'):
        # TO-DO: should we check that all elements are strings?
        if len(index) > 0 and isinstance(index[0], str):
            return string_array_type
        else:
            return types.none

    numba_index_type = numpy_support.from_dtype(index.dtype)
    return types.Array(numba_index_type, 1, 'C')
Esempio n. 2
0
def _infer_index_type(index):
    '''
    Convertion input index type into Numba known type
    need to return instance of the type class
    '''

    if isinstance(index, (types.NoneType, pd.RangeIndex, pd.DatetimeIndex)) or index is None or len(index) == 0:
        return types.none

    if index.dtype == np.dtype('O') and len(index) > 0:
        first_val = index[0]
        if isinstance(first_val, str):
            return string_array_type

    numba_index_type = numpy_support.from_dtype(index.dtype)
    return types.Array(numba_index_type, 1, 'C')