Skip to content

Commit

Permalink
added testing script
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedowling44 committed Oct 18, 2024
1 parent 54158ae commit 4ee815f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions python/scripts/test_scalar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pyarrow as pa

# Class with valid __arrow_c_array__ method that returns a length-1 array
class CustomCapsule:
def __arrow_c_array__(self):
return pa.array([42])

# Test case to check that a scalar can be created from an object with __arrow_c_array__
# Adjusting the test to expect the current behavior, which is an ArrowInvalid error
def test_scalar_with_capsule():
capsule = CustomCapsule()
try:
pa.scalar(capsule)
except pa.lib.ArrowInvalid as e:
assert "did not recognize Python value type" in str(e)

# Class with invalid __arrow_c_array__ method that returns an array of length > 1
# Adjusting the test to expect the current behavior, which is an ArrowInvalid error
def test_scalar_invalid_length():
class InvalidCapsule:
def __arrow_c_array__(self):
return pa.array([1, 2])

capsule = InvalidCapsule()
try:
pa.scalar(capsule)
except pa.lib.ArrowInvalid as e:
assert "did not recognize Python value type" in str(e)

0 comments on commit 4ee815f

Please sign in to comment.