|
9 | 9 | from pandas import DataFrame, MultiIndex, Series, date_range
|
10 | 10 | import pandas.util.testing as tm
|
11 | 11 |
|
| 12 | + |
12 | 13 | # ----------------------------------------------------------------------
|
13 | 14 | # Generic types test cases
|
14 | 15 |
|
@@ -265,7 +266,6 @@ def test_metadata_propagation(self):
|
265 | 266 |
|
266 | 267 | # simple boolean
|
267 | 268 | for op in ["__eq__", "__le__", "__ge__"]:
|
268 |
| - |
269 | 269 | # this is a name matching op
|
270 | 270 | v1 = getattr(o, op)(o)
|
271 | 271 | v2 = getattr(o, op)(o2)
|
@@ -948,3 +948,20 @@ def test_axis_classmethods(self, box):
|
948 | 948 | assert obj._get_axis_number(v) == box._get_axis_number(v)
|
949 | 949 | assert obj._get_axis_name(v) == box._get_axis_name(v)
|
950 | 950 | assert obj._get_block_manager_axis(v) == box._get_block_manager_axis(v)
|
| 951 | + |
| 952 | + # Tests that the ignore keyword causes the intended functionality |
| 953 | + def test_astype_ignores(self): |
| 954 | + df = pd.DataFrame({"a": [1, 2, 3]}) |
| 955 | + df_validation = pd.DataFrame({"a": [1, 2, 3]}) |
| 956 | + |
| 957 | + # Tests that a KeyError is raised when raise is explicitly declared |
| 958 | + with pytest.raises(KeyError): |
| 959 | + df.astype({"b": str}, errors="raise") |
| 960 | + |
| 961 | + # Tests that a KeyError is raised when no argument is declared |
| 962 | + with pytest.raises(KeyError): |
| 963 | + df.astype({"b": str}) |
| 964 | + |
| 965 | + # Tests that no KeyError is thrown if ignore is true. Ensures there is no change to the initial DataFrame |
| 966 | + df.astype({"b": str}, errors="ignore") |
| 967 | + assert df.equals(df_validation) |
0 commit comments