rstudio / rstudio/reticulate

Crash when executing function which filters numpy array

Open
#342 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.8k
Forks
349
Avg merge
5h 13m
Merged PRs (30d)
4

Description

Using

library(reticulate)
source_python(pythonfile.py)

to source pythonfile.py wit the content

import numpy as np

def testfun(idx):
    idx = int(idx)
    # Some MT numbers and corresponding TALYS file names #
    mts = np.array([1, 2, 3])
    mt2name = np.array(['a', 'b', 'c'])
    if idx in mts:
        ret = mt2name[idx == mts][0]
        return ret
    return 'undefined'

and then running from R

testfun(1L)

leads to a crash of R with the error message

*** caught segfault ***
address 0x8, cause 'memory not mapped'

Additional information:
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Python 2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55)

Using the function testfun(1) directly from the python shell works without problems.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with pythonfile.py, testfun, and the R call testfun(1L), then compare it with calling the function directly from Python. Trace the reticulate boundary involved in the NumPy filtering expression. Done means the R process no longer segfaults and the function returns its expected value.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python, r
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.