File tree 2 files changed +18
-18
lines changed
2 files changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -980,6 +980,24 @@ def test_arg_for_errors_in_astype_dictlist(self):
980
980
981
981
tm .assert_frame_equal (result , expected )
982
982
983
+ def test_astype_ignores_arg (self ):
984
+ # 30324
985
+ df = pd .DataFrame ({"a" : [1 , 2 , 3 ]})
986
+ df_validation = pd .DataFrame ({"a" : [1 , 2 , 3 ]})
987
+
988
+ # Tests that a KeyError is raised when raise is explicitly declared
989
+ with pytest .raises (KeyError ):
990
+ df .astype ({"b" : str }, errors = "raise" )
991
+
992
+ # Tests that a KeyError is raised when no argument is declared
993
+ with pytest .raises (KeyError ):
994
+ df .astype ({"b" : str })
995
+
996
+ # Tests that no KeyError is thrown if ignore is true.
997
+ # Ensures there is no change to the initial DataFrame.
998
+ df .astype ({"b" : str }, errors = "ignore" )
999
+ tm .assert_frame_equal (df , df_validation )
1000
+
983
1001
@pytest .mark .parametrize (
984
1002
"input_vals" ,
985
1003
[
Original file line number Diff line number Diff line change @@ -947,21 +947,3 @@ 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