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

GH-21761: [Python] accept pyarrow scalars in array constructor #36162

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions python/pyarrow/tests/test_convert_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2457,14 +2457,29 @@ def test_array_from_pylist_offset_overflow():
)
])
def test_array_accepts_pyarrow_scalar(seq, data, scalar_data, value_type):
if type(seq(scalar_data)) == set:
pytest.skip("TODO: The elements in the set get reordered.")
expect = pa.array(data, type=value_type)
result = pa.array(seq(scalar_data))
assert expect.equals(result)

if type(seq(scalar_data)) == set:
try:
import pyarrow.compute as pc
expect = [expect[a] for a in pc.array_sort_indices(expect).to_pylist()]
result = [result[a] for a in pc.array_sort_indices(result).to_pylist()]
expect == result
except pa.lib.ArrowNotImplementedError:
set(expect) == set(result)
AlenkaF marked this conversation as resolved.
Show resolved Hide resolved
else:
assert expect.equals(result)

result = pa.array(seq(scalar_data), type=value_type)
assert expect.equals(result)
if type(seq(scalar_data)) == set:
try:
result = [result[a] for a in pc.array_sort_indices(result).to_pylist()]
expect == result
except pa.lib.ArrowNotImplementedError:
set(expect) == set(result)
else:
assert expect.equals(result)


@parametrize_with_collections_types
Expand Down