@@ -69,9 +69,12 @@ def np_dtype_to_arrays(any_real_dtype):
69
69
np_dtype = np .dtype (any_real_dtype )
70
70
pa_type = pa .from_numpy_dtype (np_dtype )
71
71
72
- pa_array = pa .array ([0 , 1 , 2 ], type = pa_type )
72
+ # None ensures the creation of a bitmask buffer.
73
+ pa_array = pa .array ([0 , 1 , 2 , None ], type = pa_type )
74
+ # Since masked Arrow buffer slots are not required to contain a specific
75
+ # value, assert only the first three values of the created np.array
73
76
np_expected = np .array ([0 , 1 , 2 ], dtype = np_dtype )
74
- mask_expected = np .array ([True , True , True ])
77
+ mask_expected = np .array ([True , True , True , False ])
75
78
return np_dtype , pa_array , np_expected , mask_expected
76
79
77
80
@@ -89,7 +92,7 @@ def test_pyarrow_array_to_numpy_and_mask(np_dtype_to_arrays):
89
92
90
93
np_dtype , pa_array , np_expected , mask_expected = np_dtype_to_arrays
91
94
data , mask = pyarrow_array_to_numpy_and_mask (pa_array , np_dtype )
92
- tm .assert_numpy_array_equal (data , np_expected )
95
+ tm .assert_numpy_array_equal (data [: 3 ] , np_expected )
93
96
tm .assert_numpy_array_equal (mask , mask_expected )
94
97
95
98
mask_buffer = pa_array .buffers ()[0 ]
@@ -106,13 +109,13 @@ def test_pyarrow_array_to_numpy_and_mask(np_dtype_to_arrays):
106
109
)
107
110
pa_array_trail .validate ()
108
111
data , mask = pyarrow_array_to_numpy_and_mask (pa_array_trail , np_dtype )
109
- tm .assert_numpy_array_equal (data , np_expected )
112
+ tm .assert_numpy_array_equal (data [: 3 ] , np_expected )
110
113
tm .assert_numpy_array_equal (mask , mask_expected )
111
114
112
115
# Add offset to the buffer.
113
116
offset = b"\x00 " * (pa_array .type .bit_width // 8 )
114
117
data_buffer_offset = pa .py_buffer (offset + data_buffer_bytes )
115
- mask_buffer_offset = pa .py_buffer (b"\x0F " )
118
+ mask_buffer_offset = pa .py_buffer (b"\x0E " )
116
119
pa_array_offset = pa .Array .from_buffers (
117
120
type = pa_array .type ,
118
121
length = len (pa_array ),
@@ -121,7 +124,7 @@ def test_pyarrow_array_to_numpy_and_mask(np_dtype_to_arrays):
121
124
)
122
125
pa_array_offset .validate ()
123
126
data , mask = pyarrow_array_to_numpy_and_mask (pa_array_offset , np_dtype )
124
- tm .assert_numpy_array_equal (data , np_expected )
127
+ tm .assert_numpy_array_equal (data [: 3 ] , np_expected )
125
128
tm .assert_numpy_array_equal (mask , mask_expected )
126
129
127
130
# Empty array
@@ -136,5 +139,5 @@ def test_pyarrow_array_to_numpy_and_mask(np_dtype_to_arrays):
136
139
)
137
140
pa_array_offset .validate ()
138
141
data , mask = pyarrow_array_to_numpy_and_mask (pa_array_offset , np_dtype )
139
- tm .assert_numpy_array_equal (data , np_expected_empty )
142
+ tm .assert_numpy_array_equal (data [: 3 ] , np_expected_empty )
140
143
tm .assert_numpy_array_equal (mask , mask_expected_empty )
0 commit comments