# Buggy code
def unicode_split(a, sep=None, maxsplit=-1):
    if not (
        maxsplit == -1
        or isinstance(maxsplit, (types.Omitted, types.Integer, types.IntegerLiteral))
    ):
        return None  # fail typing if maxsplit is not an integer

    if isinstance(sep, types.UnicodeType):

        def split_impl(a, sep, maxsplit=-1):
            a_len = len(a)
            sep_len = len(sep)

            if sep_len == 0:
                raise ValueError("empty separator")

            parts = []
            last = 0
            idx = 0

            if sep_len == 1 and maxsplit == -1:
                sep_code_point = _get_code_point(sep, 0)
                for idx in range(a_len):
                    if _get_code_point(a, idx) == sep_code_point:
                        parts.append(a[last:idx])
                        last = idx + 1
            else:
                split_count = 0

                while idx < a_len and (maxsplit == -1 or split_count < maxsplit):
                    if _cmp_region(a, idx, sep, 0, sep_len) == 0:
                        parts.append(a[last:idx])
                        idx += sep_len
                        last = idx
                        split_count += 1
                    else:
                        idx += 1

            if last <= a_len:
                parts.append(a[last:])

            return parts

        return split_impl
    elif (
        sep is None
        or isinstance(sep, types.NoneType)
        or getattr(sep, "value", False) is None
    ):

        def split_whitespace_impl(a, sep=None, maxsplit=-1):
            a_len = len(a)

            parts = []
            last = 0
            idx = 0
            split_count = 0
            in_whitespace_block = True

            for idx in range(a_len):
                code_point = _get_code_point(a, idx)
                is_whitespace = _is_whitespace(code_point)
                if in_whitespace_block:
                    if is_whitespace:
                        pass  # keep consuming space
                    else:
                        last = idx  # this is the start of the next string
                        in_whitespace_block = False
                else:
                    if not is_whitespace:
                        pass  # keep searching for whitespace transition
                    else:
                        parts.append(a[last:idx])
                        in_whitespace_block = True
                        split_count += 1
                        if maxsplit != -1 and split_count == maxsplit:
                            break

            if last <= a_len and not in_whitespace_block:
                parts.append(a[last:])

            return parts

        return split_whitespace_impl


# Traceback (NotImplementedError)
Traceback (most recent call last):
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 1032, in lower_expr
impl = self.context.get_function("static_getitem", signature)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 551, in get_function
return self.get_function(fn, sig, _firstcall=False)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 553, in get_function
raise NotImplementedError("No definition for lowering %s%s" % (key, sig))
NotImplementedError: No definition for lowering static_getitem(array([unichr x 1], 1d, C), Literal[int](0)) -> [unichr x 1]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/pearu/git/Quansight/numba/numba/errors.py", line 662, in new_error_context
yield
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 258, in lower_block
self.lower_inst(inst)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 301, in lower_inst
val = self.lower_assign(ty, inst)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 459, in lower_assign
return self.lower_expr(ty, value)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 1041, in lower_expr
expr.index_var, signature)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 600, in lower_getitem
res = impl(self.builder, castvals)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 1132, in __call__
res = self._imp(self._context, builder, self._sig, args, loc=loc)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 1157, in wrapper
return fn(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 422, in getitem_arraynd_intp
aryty, ary, (idxty,), (idx,))
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 406, in _getitem_array_generic
return load_item(context, builder, aryty, dataptr)
File "/home/pearu/git/Quansight/numba/numba/targets/arrayobj.py", line 127, in load_item
align=align)
File "/home/pearu/git/Quansight/numba/numba/targets/base.py", line 492, in unpack_value
return dm.load_from_data_pointer(builder, ptr, align)
File "/home/pearu/git/Quansight/numba/numba/datamodel/models.py", line 87, in load_from_data_pointer
return self.from_data(builder, builder.load(ptr, align=align))
File "/home/pearu/git/Quansight/numba/numba/datamodel/models.py", line 70, in from_data
raise NotImplementedError(self)
NotImplementedError: <numba.datamodel.models.UnicodeCharSeq object at 0x7f8674a8c400>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "bug_lowering_unicodecharseq.py", line 8, in <module>
foo(np.array(['a']))
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 395, in _compile_for_args
raise e
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 352, in _compile_for_args
return self.compile(tuple(argtypes))
File "/home/pearu/git/Quansight/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 693, in compile
cres = self._compiler.compile(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 76, in compile
status, retval = self._compile_cached(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 90, in _compile_cached
retval = self._compile_core(args, return_type)
File "/home/pearu/git/Quansight/numba/numba/dispatcher.py", line 108, in _compile_core
pipeline_class=self.pipeline_class)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 972, in compile_extra
return pipeline.compile_extra(func)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 390, in compile_extra
return self._compile_bytecode()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 903, in _compile_bytecode
return self._compile_core()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 890, in _compile_core
res = pm.run(self.status)
File "/home/pearu/git/Quansight/numba/numba/compiler_lock.py", line 32, in _acquire_compile_lock
return func(*args, **kwargs)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 266, in run
raise patched_exception
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 257, in run
stage()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 764, in stage_nopython_backend
self._backend(lowerfn, objectmode=False)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 703, in _backend
lowered = lowerfn()
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 690, in backend_nopython_mode
self.metadata)
File "/home/pearu/git/Quansight/numba/numba/compiler.py", line 1143, in native_lowering_stage
lower.lower()
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 177, in lower
self.lower_normal_function(self.fndesc)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 218, in lower_normal_function
entry_block_tail = self.lower_function_body()
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 243, in lower_function_body
self.lower_block(block)
File "/home/pearu/git/Quansight/numba/numba/lowering.py", line 258, in lower_block
self.lower_inst(inst)
File "/home/pearu/mconda3/envs/numba-dev/lib/python3.7/contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "/home/pearu/git/Quansight/numba/numba/errors.py", line 670, in new_error_context
six.reraise(type(newerr), newerr, tb)
File "/home/pearu/git/Quansight/numba/numba/six.py", line 659, in reraise
raise value
numba.errors.LoweringError: Failed in nopython mode pipeline (step: nopython mode backend)
<numba.datamodel.models.UnicodeCharSeq object at 0x7f8674a8c400>

File "bug_lowering_unicodecharseq.py", line 6:
def foo(x):
return x[0]
^

[1] During: lowering "$0.3 = static_getitem(value=x, index=0, index_var=$const0.2)" at bug_lowering_unicodecharseq.py (6)
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
You are currently using Numba version 0.46.0dev0+43.g8b5726899.dirty.

# Fixed code
def unicode_split(a, sep=None, maxsplit=-1):
    if not (
        maxsplit == -1
        or isinstance(maxsplit, (types.Omitted, types.Integer, types.IntegerLiteral))
    ):
        return None  # fail typing if maxsplit is not an integer

    if isinstance(sep, types.UnicodeCharSeq):

        def split_impl(a, sep, maxsplit=1):
            return a.split(str(sep), maxsplit=maxsplit)

        return split_impl

    if isinstance(sep, types.UnicodeType):

        def split_impl(a, sep, maxsplit=-1):
            a_len = len(a)
            sep_len = len(sep)

            if sep_len == 0:
                raise ValueError("empty separator")

            parts = []
            last = 0
            idx = 0

            if sep_len == 1 and maxsplit == -1:
                sep_code_point = _get_code_point(sep, 0)
                for idx in range(a_len):
                    if _get_code_point(a, idx) == sep_code_point:
                        parts.append(a[last:idx])
                        last = idx + 1
            else:
                split_count = 0

                while idx < a_len and (maxsplit == -1 or split_count < maxsplit):
                    if _cmp_region(a, idx, sep, 0, sep_len) == 0:
                        parts.append(a[last:idx])
                        idx += sep_len
                        last = idx
                        split_count += 1
                    else:
                        idx += 1

            if last <= a_len:
                parts.append(a[last:])

            return parts

        return split_impl
    elif (
        sep is None
        or isinstance(sep, types.NoneType)
        or getattr(sep, "value", False) is None
    ):

        def split_whitespace_impl(a, sep=None, maxsplit=-1):
            a_len = len(a)

            parts = []
            last = 0
            idx = 0
            split_count = 0
            in_whitespace_block = True

            for idx in range(a_len):
                code_point = _get_code_point(a, idx)
                is_whitespace = _is_whitespace(code_point)
                if in_whitespace_block:
                    if is_whitespace:
                        pass  # keep consuming space
                    else:
                        last = idx  # this is the start of the next string
                        in_whitespace_block = False
                else:
                    if not is_whitespace:
                        pass  # keep searching for whitespace transition
                    else:
                        parts.append(a[last:idx])
                        in_whitespace_block = True
                        split_count += 1
                        if maxsplit != -1 and split_count == maxsplit:
                            break

            if last <= a_len and not in_whitespace_block:
                parts.append(a[last:])

            return parts

        return split_whitespace_impl