Skip to content

Commit

Permalink
ARROW-8105: [Python] Fix segfault when shrunken masked array is passe…
Browse files Browse the repository at this point in the history
…d to pyarrow.array

Needed to validate that the mask of the masked array wasn't equal to the nomask
constant which indicates that the masked array was shrunk

Closes #6612 from nugend/master

Lead-authored-by: Dan Nugent <nugend@gmail.com>
Co-authored-by: Daniel Nugent <nugend@gmail.com>
Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
  • Loading branch information
nugend authored and jorisvandenbossche committed Mar 17, 2020
1 parent 892921a commit ac197f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def array(object obj, type=None, mask=None, size=None, from_pandas=None,
raise ValueError("Cannot pass a numpy masked array and "
"specify a mask at the same time")
else:
mask = values.mask
# don't use shrunken masks
mask = None if values.mask is np.ma.nomask else values.mask
values = values.data

if hasattr(values, '__arrow_array__'):
Expand Down
7 changes: 7 additions & 0 deletions python/pyarrow/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,13 @@ def test_array_from_masked():
pa.array(ma, mask=np.array([True, False, False, False]))


def test_array_from_shrunken_masked():
ma = np.ma.array([0], dtype='int64')
result = pa.array(ma)
expected = pa.array([0], type='int64')
assert expected.equals(result)


def test_array_from_invalid_dim_raises():
msg = "only handle 1-dimensional arrays"
arr2d = np.array([[1, 2, 3], [4, 5, 6]])
Expand Down

0 comments on commit ac197f4

Please sign in to comment.