File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -947,3 +947,21 @@ def test_axis_classmethods(self, box):
947
947
assert obj ._get_axis_number (v ) == box ._get_axis_number (v )
948
948
assert obj ._get_axis_name (v ) == box ._get_axis_name (v )
949
949
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 )
You can’t perform that action at this time.
0 commit comments