Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic support for try except #4902

Merged
merged 51 commits into from Dec 12, 2019
Merged

basic support for try except #4902

merged 51 commits into from Dec 12, 2019

Conversation

sklam
Copy link
Member

@sklam sklam commented Nov 27, 2019

Implements #4898 (comment)

@sklam sklam changed the title [WIP] basic support for try except basic support for try except Dec 6, 2019
numba/byteflow.py Outdated Show resolved Hide resolved
@sklam
Copy link
Member Author

sklam commented Dec 11, 2019

@seibert
Copy link
Contributor

seibert commented Dec 11, 2019

now has conflict with master

# Conflicts:
#	numba/rewrites/static_raise.py
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix-ups, couple of typo's else good to go.

numba/lowering.py Outdated Show resolved Hide resolved
numba/lowering.py Outdated Show resolved Hide resolved
@stuartarchibald stuartarchibald added 4 - Waiting on author Waiting for author to respond to review and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Dec 12, 2019
Co-Authored-By: stuartarchibald <stuartarchibald@users.noreply.github.com>
@stuartarchibald stuartarchibald added 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on author Waiting for author to respond to review labels Dec 12, 2019
Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this, great to see this feature added!

@seibert seibert merged commit adfdcdd into numba:master Dec 12, 2019
@esc
Copy link
Member

esc commented Dec 12, 2019

🎉

@mobassir94
Copy link

mobassir94 commented Apr 4, 2020

i tried the code above :

@njit
def udt():
    x = 1
    y = 0
    try:
        x / y
    except Exception:
        pass

udt()

in numba version 0.47 and 0.48 and it still throws me error : "UnsupportedError: Failed in nopython mode pipeline (step: analyzing bytecode)
'try' block not supported until python3.7 or later"

how to solve this issue?

@esc
Copy link
Member

esc commented Apr 6, 2020

@mobassir94 I just tried the snippet you suggested on the current Numba master 0.50.0dev0-7-g917f582433-dirty and it seems to be fine. Could you give it a try?

@mobassir94
Copy link

mobassir94 commented Apr 6, 2020

@esc which one?
i tried this :

@njit
def udt():
    x = 1
    y = 0
    try:
        x / y
    except Exception:
        pass

udt()

and it didn't work at all in kaggle kernel

another code that i was trying is this one :

%%time
from langdetect import detect
count = 0
noise = []
non_eng = []
for i in range(len(df_train_full)):
    try:
        lang = detect(df_train_full.comment_text[i])
        if(lang != 'en'):
            count +=1
            non_eng.append(i)
    except:
        noise.append(i)

and the error comes for this line of code : lang = detect(df_train_full.comment_text[i])
i can't use this library : https://pypi.org/project/langdetect/ in try block,will you please give it a try and see if you can make it work?
the dataset i was using is this one : https://www.kaggle.com/c/jigsaw-multilingual-toxic-comment-classification/data

@esc
Copy link
Member

esc commented Apr 7, 2020

@mobassir94 thanks for following up. We appreciate your input in this matter. I am not sure what you mean "it didn't work at all in kaggle kernel"?! I just tried it again locally:

$ cat foo033.py
from numba import njit


@njit
def udt():
    x = 1
    y = 0
    try:
        x / y
    except Exception:
        pass


udt()
$ python foo033.py
$ echo $?
0
$ git desc
0.50.0dev0-7-g917f582433

As you can see I am not receiving any error message. Perhaps you could submit the full backtrace of the exception? Also, what Python version are you using? As can be seen on https://pypi.org/project/numba/ Numba only supports Pythonn 3.6 and later.

As for the issues with langdetect, only a subset of NumPy and Python functions/features are supported by Numba, documentation on those supported can be found here.

Effectively this means you can not use langdetect in functions that you would like to compile with Numba.

@gmarkall
Copy link
Member

gmarkall commented Apr 8, 2020

@mobassir94 Could you please open an issue for further discussion please? It will also be helpful for you to report the numba version used in the Kaggle kernel, i.e. numba.__version__ - many thanks!

@mobassir94
Copy link

dear @gmarkall as from last comment of @esc it is clear to me that numba doesn't support outside package like langdetect,i was using langdetect in try block so it was not working,i guess the program i tried to execute on gpu can't be done using numba,thanks for your comment

@segatrade
Copy link

segatrade commented Sep 2, 2020

Hello!

I run:

try:
    xx_inv = np.linalg.inv(xx)
except np.linalg.LinAlgError:
    return [np.nan], [[np.nan, np.nan]]

It gives:

numba.core.errors.UnsupportedError: Failed in nopython mode pipeline (step: analyzing bytecode)
'try' block not supported until python3.7 or later

I have python3.6, but in my case this is requirement. Is any way to use try on py3.6 with numba or replacement for try?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants