Skip to content

Commit 011dac3

Browse files
committed
Merge remote-tracking branch 'origin/pandas-dev#30324' into pandas-dev#30324
2 parents 3d0603f + 5d4a890 commit 011dac3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/generic/test_generic.py

+18
Original file line numberDiff line numberDiff line change
@@ -947,3 +947,21 @@ def test_axis_classmethods(self, box):
947947
assert obj._get_axis_number(v) == box._get_axis_number(v)
948948
assert obj._get_axis_name(v) == box._get_axis_name(v)
949949
assert obj._get_block_manager_axis(v) == box._get_block_manager_axis(v)
950+
951+
# Tests that the ignore keyword causes the intended functionality
952+
def test_astype_ignores(self):
953+
df = pd.DataFrame({"a": [1, 2, 3]})
954+
df_validation = pd.DataFrame({"a": [1, 2, 3]})
955+
956+
# Tests that a KeyError is raised when raise is explicitly declared
957+
with pytest.raises(KeyError):
958+
df.astype({"b": str}, errors="raise")
959+
960+
# Tests that a KeyError is raised when no argument is declared
961+
with pytest.raises(KeyError):
962+
df.astype({"b": str})
963+
964+
# Tests that no KeyError is thrown if ignore is true.
965+
# 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

Comments
 (0)