|
1 | 1 | import numpy as np |
2 | 2 | import pytest |
3 | 3 |
|
4 | | -from pandas._config import using_string_dtype |
5 | | - |
6 | 4 | import pandas.util._test_decorators as td |
7 | 5 |
|
8 | 6 | from pandas import ( |
9 | | - ArrowDtype, |
10 | 7 | DataFrame, |
11 | 8 | Index, |
12 | 9 | MultiIndex, |
13 | 10 | Series, |
14 | 11 | _testing as tm, |
15 | 12 | ) |
16 | 13 |
|
17 | | -try: |
18 | | - import pyarrow as pa |
19 | | -except ImportError: |
20 | | - pa = None |
21 | | - |
22 | 14 |
|
23 | 15 | def test_get_dummies(any_string_dtype): |
24 | 16 | s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype) |
@@ -99,32 +91,12 @@ def test_get_dummies_with_pyarrow_dtype(any_string_dtype, dtype): |
99 | 91 |
|
100 | 92 |
|
101 | 93 | # GH#47872 |
102 | | -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") |
103 | 94 | def test_get_dummies_with_str_dtype(any_string_dtype): |
104 | 95 | s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype) |
105 | | - result = s.str.get_dummies("|", dtype=str) |
106 | | - expected = DataFrame( |
107 | | - [["T", "T", "F"], ["T", "F", "T"], ["F", "F", "F"]], |
108 | | - columns=list("abc"), |
109 | | - dtype=str, |
110 | | - ) |
111 | | - tm.assert_frame_equal(result, expected) |
112 | | - |
113 | 96 |
|
114 | | -# GH#47872 |
115 | | -@td.skip_if_no("pyarrow") |
116 | | -def test_get_dummies_with_pa_str_dtype(any_string_dtype): |
117 | | - import pyarrow as pa |
| 97 | + msg = "Only numeric or boolean dtypes are supported for 'dtype'" |
| 98 | + with pytest.raises(ValueError, match=msg): |
| 99 | + s.str.get_dummies("|", dtype=str) |
118 | 100 |
|
119 | | - s = Series(["a|b", "a|c", np.nan], dtype=any_string_dtype) |
120 | | - result = s.str.get_dummies("|", dtype=ArrowDtype(pa.string())) |
121 | | - expected = DataFrame( |
122 | | - [ |
123 | | - ["true", "true", "false"], |
124 | | - ["true", "false", "true"], |
125 | | - ["false", "false", "false"], |
126 | | - ], |
127 | | - columns=list("abc"), |
128 | | - dtype=ArrowDtype(pa.string()), |
129 | | - ) |
130 | | - tm.assert_frame_equal(result, expected) |
| 101 | + with pytest.raises(ValueError, match=msg): |
| 102 | + s.str.get_dummies("|", dtype="datetime64[ns]") |
0 commit comments