Skip to content

Commit c88f05f

Browse files
committed
TST: test_cast_1d_array
1 parent 69e0061 commit c88f05f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/tests/dtypes/test_cast.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
infer_dtype_from_array,
2222
maybe_convert_string_to_object,
2323
maybe_convert_scalar,
24-
find_common_type)
24+
find_common_type,
25+
construct_1d_array_from_listlike)
2526
from pandas.core.dtypes.dtypes import (
2627
CategoricalDtype,
2728
DatetimeTZDtype,
@@ -407,3 +408,20 @@ def test_period_dtype(self):
407408
np.dtype('datetime64[ns]'), np.object, np.int64]:
408409
assert find_common_type([dtype, dtype2]) == np.object
409410
assert find_common_type([dtype2, dtype]) == np.object
411+
412+
@pytest.mark.parametrize('dtype', [int, float, str, object, None])
413+
@pytest.mark.parametrize('datum1', [1, 2., "3", (4, 5), [6, 7], None])
414+
@pytest.mark.parametrize('datum2', [8, 9., "10", (11, 12), [13, 14], None])
415+
def test_cast_1d_array(self, dtype, datum1, datum2):
416+
data = [datum1, datum2]
417+
try:
418+
problem = (dtype is not object
419+
and np.array(data, dtype=dtype).ndim != 1) or ValueError
420+
except (ValueError, TypeError) as exc:
421+
problem = type(exc)
422+
423+
if problem:
424+
assert list(construct_1d_array_from_listlike(data)) == data
425+
else:
426+
pytest.raises(problem, construct_1d_array_from_listlike,
427+
data, dtype=dtype)

0 commit comments

Comments
 (0)