Skip to content

Commit cf4aa91

Browse files
apacheGH-49644: [Python] Trim test comments per review
1 parent 7c1bbce commit cf4aa91

2 files changed

Lines changed: 3 additions & 19 deletions

File tree

‎python/pyarrow/tests/test_array.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,30 +2926,24 @@ def test_array_from_invalid_dim_raises():
29262926

29272927
@pytest.mark.numpy
29282928
def test_fixed_size_list_from_multidim_ndarray():
2929-
# GH-49644: a fixed-size list can be built from multi-dimensional ndarray
2930-
# elements by flattening them in C order.
29312929
arr = pa.array([np.array([[1, 2, 3]], dtype=np.int64),
29322930
np.array([[4, 5, 6]], dtype=np.int64)],
29332931
type=pa.list_(pa.int64(), 3))
29342932
assert arr.type == pa.list_(pa.int64(), 3)
29352933
assert arr.to_pylist() == [[1, 2, 3], [4, 5, 6]]
29362934

2937-
# A non-trivial 2D shape confirms values are flattened in C (row-major) order
29382935
arr = pa.array([np.array([[1, 2], [3, 4]], dtype=np.int64)],
29392936
type=pa.list_(pa.int64(), 4))
29402937
assert arr.to_pylist() == [[1, 2, 3, 4]]
29412938

2942-
# The flattened length must still match the fixed size
29432939
with pytest.raises(pa.lib.ArrowInvalid):
29442940
pa.array([np.array([[1, 2], [3, 4]], dtype=np.int64)],
29452941
type=pa.list_(pa.int64(), 3))
29462942

2947-
# Variable-sized lists still require 1-dimensional values
2948-
with pytest.raises(pa.lib.ArrowInvalid, match="1-dimensional"):
2943+
with pytest.raises(pa.lib.ArrowInvalid, match=r"array values of .*int64"):
29492944
pa.array([np.array([[1, 2, 3]], dtype=np.int64)],
29502945
type=pa.list_(pa.int64()))
29512946

2952-
# 0-dimensional arrays are flattened into a length-1 fixed-size list (GH-49644)
29532947
arr = pa.array([np.array(1, dtype=np.int64)], type=pa.list_(pa.int64(), 1))
29542948
assert arr.to_pylist() == [[1]]
29552949

‎python/pyarrow/tests/test_extension_type.py‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,6 @@ def test_tensor_array_from_numpy(np_type_str):
17331733
@pytest.mark.numpy
17341734
@pytest.mark.parametrize("np_type_str", ("int8", "int64", "float32"))
17351735
def test_tensor_array_from_list_of_ndarrays(np_type_str):
1736-
# GH-49644
17371736
np_dtype = np.dtype(np_type_str)
17381737
tensor_type = pa.fixed_shape_tensor(pa.from_numpy_dtype(np_dtype), (2, 3))
17391738

@@ -1746,33 +1745,25 @@ def test_tensor_array_from_list_of_ndarrays(np_type_str):
17461745
assert result.type == tensor_type
17471746
assert len(result) == 2
17481747

1749-
# Must match the existing from_numpy_ndarray path on the same data
17501748
expected = pa.FixedShapeTensorArray.from_numpy_ndarray(np.stack(elements))
17511749
assert result.storage.equals(expected.storage)
17521750

1753-
# Each element round-trips back to the original ndarray (with its shape)
17541751
for scalar, original in zip(result, elements):
17551752
np.testing.assert_array_equal(scalar.to_numpy(), original)
17561753

1757-
# Higher-dimensional tensors work too
17581754
tensor_3d = pa.fixed_shape_tensor(pa.from_numpy_dtype(np_dtype), (2, 2, 3))
17591755
elements_3d = [np.arange(12, dtype=np_dtype).reshape(2, 2, 3)]
17601756
result_3d = pa.array(elements_3d, type=tensor_3d)
17611757
assert result_3d.type == tensor_3d
17621758
np.testing.assert_array_equal(result_3d[0].to_numpy(), elements_3d[0])
17631759

1764-
# None elements are allowed
17651760
result_with_null = pa.array([elements[0], None], type=tensor_type)
17661761
assert result_with_null.null_count == 1
17671762
assert result_with_null[1].as_py() is None
17681763

1769-
# A multi-dimensional element whose shape doesn't match the tensor shape is
1770-
# rejected, even when the total number of elements is the same (GH-49644).
17711764
with pytest.raises(ValueError, match="shape"):
17721765
pa.array([np.arange(6, dtype=np_dtype).reshape(3, 2)], type=tensor_type)
17731766

1774-
# Permuted tensor types can't be built from a sequence (the flatten would
1775-
# store the wrong layout), so they're rejected for now.
17761767
permuted_type = pa.fixed_shape_tensor(
17771768
pa.from_numpy_dtype(np_dtype), (2, 3), permutation=[1, 0])
17781769
with pytest.raises(NotImplementedError, match="permutation"):
@@ -1781,8 +1772,8 @@ def test_tensor_array_from_list_of_ndarrays(np_type_str):
17811772

17821773
@pytest.mark.numpy
17831774
def test_tensor_array_from_list_mixed_layout():
1784-
# GH-49644: C- and F-ordered arrays with the same values must produce the
1785-
# same result, since the values are always flattened in C order.
1775+
# C- and F-ordered arrays with the same values must produce the same
1776+
# result, since the values are always flattened in C order.
17861777
tensor_type = pa.fixed_shape_tensor(pa.int64(), (2, 3))
17871778
raw = [[1, 2, 3], [4, 5, 6]]
17881779
c_arr = np.array(raw, order="C")
@@ -1798,7 +1789,6 @@ def test_tensor_array_from_list_mixed_layout():
17981789

17991790
@pytest.mark.numpy
18001791
def test_tensor_array_from_list_of_0d_arrays():
1801-
# GH-49644: a scalar (0-dimensional) tensor can be built from 0-D arrays.
18021792
tensor_type = pa.fixed_shape_tensor(pa.int64(), ())
18031793
result = pa.array([np.array(1, dtype=np.int64), np.array(2, dtype=np.int64)],
18041794
type=tensor_type)

0 commit comments

Comments
 (0)