|
5 | 5 |
|
6 | 6 | from pandas import (
|
7 | 7 | DataFrame,
|
8 |
| - MultiIndex, |
9 | 8 | get_option,
|
10 | 9 | read_clipboard,
|
11 | 10 | )
|
@@ -257,16 +256,34 @@ def test_infer_excel_with_nulls(self, request, mock_clipboard):
|
257 | 256 | # excel data is parsed correctly
|
258 | 257 | tm.assert_frame_equal(df, df_expected)
|
259 | 258 |
|
260 |
| - def test_infer_excel_with_multiindex(self, request, mock_clipboard): |
| 259 | + @pytest.mark.parametrize( |
| 260 | + "multiindex", |
| 261 | + [ |
| 262 | + ( |
| 263 | + """\t\t\tcol1\tcol2 |
| 264 | + A\t0\tTrue\t1\tred |
| 265 | + A\t1\tTrue\t\tblue |
| 266 | + B\t0\tFalse\t2\tgreen""", |
| 267 | + [["A", "A", "B"], [0, 1, 0], [True, True, False]], |
| 268 | + ), |
| 269 | + ( |
| 270 | + """\t\tcol1\tcol2 |
| 271 | + A\t0\t1\tred |
| 272 | + A\t1\t\tblue |
| 273 | + B\t0\t2\tgreen""", |
| 274 | + [["A", "A", "B"], [0, 1, 0]], |
| 275 | + ), |
| 276 | + ], |
| 277 | + ) |
| 278 | + def test_infer_excel_with_multiindex(self, request, mock_clipboard, multiindex): |
261 | 279 | # GH41108
|
262 |
| - text = "\t\tcol1\tcol2\nA\t0\t1\tred\nA\t1\t\tblue\nB\t0\t2\tgreen" |
263 | 280 |
|
264 |
| - mock_clipboard[request.node.name] = text |
| 281 | + # the `.replace()` is because `.dedent()` does not like the leading `\t` |
| 282 | + mock_clipboard[request.node.name] = multiindex[0].replace(" ", "") |
265 | 283 | df = read_clipboard()
|
266 |
| - multiindex = MultiIndex.from_tuples([("A", 0), ("A", 1), ("B", 0)]) |
267 | 284 | df_expected = DataFrame(
|
268 | 285 | data={"col1": [1, None, 2], "col2": ["red", "blue", "green"]},
|
269 |
| - index=multiindex, |
| 286 | + index=multiindex[1], |
270 | 287 | )
|
271 | 288 |
|
272 | 289 | # excel data is parsed correctly
|
|
0 commit comments