|
| 1 | +import numpy as np |
1 | 2 | import pytest
|
2 | 3 |
|
3 | 4 | import pandas as pd
|
|
15 | 16 | (["Int32", "UInt32"], "Int64"),
|
16 | 17 | # this still gives object (awaiting float extension dtype)
|
17 | 18 | (["Int64", "UInt64"], "object"),
|
| 19 | + (["Int64", "boolean"], "Int64"), |
| 20 | + (["UInt8", "boolean"], "UInt8"), |
18 | 21 | ],
|
19 | 22 | )
|
20 | 23 | def test_concat_series(to_concat_dtypes, result_dtype):
|
21 | 24 |
|
22 |
| - result = pd.concat([pd.Series([1, 2, pd.NA], dtype=t) for t in to_concat_dtypes]) |
23 |
| - expected = pd.concat([pd.Series([1, 2, pd.NA], dtype=object)] * 2).astype( |
| 25 | + result = pd.concat([pd.Series([0, 1, pd.NA], dtype=t) for t in to_concat_dtypes]) |
| 26 | + expected = pd.concat([pd.Series([0, 1, pd.NA], dtype=object)] * 2).astype( |
24 | 27 | result_dtype
|
25 | 28 | )
|
26 | 29 | tm.assert_series_equal(result, expected)
|
| 30 | + |
| 31 | + # order doesn't matter for result |
| 32 | + result = pd.concat( |
| 33 | + [pd.Series([0, 1, pd.NA], dtype=t) for t in to_concat_dtypes[::-1]] |
| 34 | + ) |
| 35 | + expected = pd.concat([pd.Series([0, 1, pd.NA], dtype=object)] * 2).astype( |
| 36 | + result_dtype |
| 37 | + ) |
| 38 | + tm.assert_series_equal(result, expected) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.parametrize( |
| 42 | + "to_concat_dtypes, result_dtype", |
| 43 | + [ |
| 44 | + (["Int64", "int64"], "Int64"), |
| 45 | + (["UInt64", "uint64"], "UInt64"), |
| 46 | + (["Int8", "int8"], "Int8"), |
| 47 | + (["Int8", "int16"], "Int16"), |
| 48 | + (["UInt8", "int8"], "Int16"), |
| 49 | + (["Int32", "uint32"], "Int64"), |
| 50 | + # this still gives object (awaiting float extension dtype) |
| 51 | + (["Int64", "uint64"], "object"), |
| 52 | + (["Int64", "bool"], "Int64"), |
| 53 | + (["UInt8", "bool"], "UInt8"), |
| 54 | + ], |
| 55 | +) |
| 56 | +def test_concat_series_with_numpy(to_concat_dtypes, result_dtype): |
| 57 | + |
| 58 | + s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0]) |
| 59 | + s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1])) |
| 60 | + result = pd.concat([s1, s2], ignore_index=True) |
| 61 | + expected = pd.Series([0, 1, pd.NA, 0, 1], dtype=object).astype(result_dtype) |
| 62 | + tm.assert_series_equal(result, expected) |
| 63 | + |
| 64 | + # order doesn't matter for result |
| 65 | + result = pd.concat([s2, s1], ignore_index=True) |
| 66 | + expected = pd.Series([0, 1, 0, 1, pd.NA], dtype=object).astype(result_dtype) |
| 67 | + tm.assert_series_equal(result, expected) |
0 commit comments