Visitar URL original
Unexpected error when compilation fails for function loaded with execfile · Issue #2456 · numba/numba · GitHub
Skip to content

Unexpected error when compilation fails for function loaded with execfile #2456

Closed

Description

@seibert

(Python 2.7, Numba 0.33, OS X)

If I have a file called ex.py with some code that will fail to run in python mode:

import numpy as np
import numba

@numba.jit  # didn't set nopython mode, so can fall back to object mode!
def example(values, threshold):
    result = np.zeros_like(values)
    for i in range(values.shape):  # This should be values.shape[0]!
        if np.abs(values[i]) >= threshold:
            result[i] = values[i]
    return result

And then I run the Numba function using execfile from a file called load_ex.py:

import np

global_dict = {}
execfile('ex.py', global_dict)
in_array = np.array([0,1,2])

print global_dict['example'](in_array, 1)

I get the unexpected exception:

Traceback (most recent call last):
  File "load_ex.py", line 9, in <module>
    print global_dict['example'](in_array, 1)
NameError: global name 'np' is not defined

rather than the exception I would have expected:

Traceback (most recent call last):
  File "ex.py", line 15, in <module>
    print example(in_array, 1)
TypeError: range() integer end argument expected, got tuple.

If I force nopython mode, I get the compiler failure that I also would have expected, so this is a low priority issue. It just seems pretty weird...

Activity

  1. stuartarchibald commented on Jul 13, 2017

    @stuartarchibald
    Contributor

    I can replicate on Linux. This is indeed weird.

  2. stuartarchibald commented on Feb 6, 2020

    @stuartarchibald
    Contributor

    Python 2.7 reached EOL on January 1st, 2020 and Numba 0.47 was the last release to support Python 2.7. Closing this issue as it is Python 2.7 specific, if this problem is reproducible on Python 3 with Numba >= 0.48 then please reopen it. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions