Skip to content

Commit 3e38fb5

Browse files
committed
Add tests that catch bug
1 parent 0e0814b commit 3e38fb5

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

pandas/tests/arrays/numpy_/test_numpy.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
the interface tests.
44
"""
55

6+
from datetime import datetime
7+
68
import numpy as np
79
import pytest
810

@@ -195,6 +197,68 @@ def test_validate_reduction_keyword_args():
195197
arr.all(keepdims=True)
196198

197199

200+
@pytest.mark.parametrize(
201+
"value, expectedError",
202+
[
203+
(True, False),
204+
(9, False),
205+
(5.5, True),
206+
(1 + 2j, True),
207+
("t", True),
208+
(datetime.now(), True),
209+
],
210+
)
211+
def test_int_arr_validate_setitem_value(value, expectedError):
212+
arr = pd.Series(range(5), dtype="int").array
213+
if expectedError:
214+
with pytest.raises(TypeError):
215+
arr._validate_setitem_value(value)
216+
else:
217+
arr[0] = value
218+
assert arr[0] == value
219+
220+
221+
@pytest.mark.parametrize(
222+
"value, expectedError",
223+
[
224+
(True, False),
225+
(9, False),
226+
(5.5, False),
227+
(1 + 2j, True),
228+
("t", True),
229+
(datetime.now(), True),
230+
],
231+
)
232+
def test_float_arr_validate_setitem_value(value, expectedError):
233+
arr = pd.Series(range(5), dtype="float").array
234+
if expectedError:
235+
with pytest.raises(TypeError):
236+
arr._validate_setitem_value(value)
237+
else:
238+
arr[0] = value
239+
assert arr[0] == value
240+
241+
242+
@pytest.mark.parametrize(
243+
"value, expectedError",
244+
[
245+
(True, False),
246+
(9, False),
247+
(5.5, False),
248+
("t", False),
249+
(datetime.now(), True),
250+
],
251+
)
252+
def test_str_arr_validate_setitem_value(value, expectedError):
253+
arr = NumpyExtensionArray(np.array(["foo", "bar", "test"], dtype="str"))
254+
if expectedError:
255+
with pytest.raises(TypeError):
256+
arr._validate_setitem_value(value)
257+
else:
258+
arr[0] = value
259+
assert arr[0] == str(value)
260+
261+
198262
def test_np_max_nested_tuples():
199263
# case where checking in ufunc.nout works while checking for tuples
200264
# does not

0 commit comments

Comments
 (0)