|
21 | 21 | infer_dtype_from_array,
|
22 | 22 | maybe_convert_string_to_object,
|
23 | 23 | maybe_convert_scalar,
|
24 |
| - find_common_type) |
| 24 | + find_common_type, |
| 25 | + construct_1d_array_from_listlike) |
25 | 26 | from pandas.core.dtypes.dtypes import (
|
26 | 27 | CategoricalDtype,
|
27 | 28 | DatetimeTZDtype,
|
@@ -407,3 +408,20 @@ def test_period_dtype(self):
|
407 | 408 | np.dtype('datetime64[ns]'), np.object, np.int64]:
|
408 | 409 | assert find_common_type([dtype, dtype2]) == np.object
|
409 | 410 | 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