Skip to content

Commit a4992fe

Browse files
committed
Placed the tests in the right location.
Signed-off-by: nbonnin <[email protected]>
1 parent 011dac3 commit a4992fe

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5614,7 +5614,7 @@ def astype(
56145614
"""
56155615
if is_dict_like(dtype):
56165616
if self.ndim == 1: # i.e. Series
5617-
if len(dtype) > 1 or self.name not in dtype and errors == "raise":
5617+
if len(dtype) > 1 or self.name not in dtype and errors == 'raise':
56185618
raise KeyError(
56195619
"Only the Series name can be used for "
56205620
"the key in Series dtype mappings."
@@ -5623,7 +5623,7 @@ def astype(
56235623
return self.astype(new_type, copy, errors)
56245624

56255625
for col_name in dtype.keys():
5626-
if col_name not in self and errors == "raise":
5626+
if col_name not in self and errors == 'raise':
56275627
raise KeyError(
56285628
"Only a column name can be used for the "
56295629
"key in a dtype mappings argument."

pandas/tests/frame/test_dtypes.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -980,23 +980,23 @@ def test_arg_for_errors_in_astype_dictlist(self):
980980

981981
tm.assert_frame_equal(result, expected)
982982

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)
983+
def test_astype_ignores(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+
assert df.equals(df_validation)
10001000

10011001
@pytest.mark.parametrize(
10021002
"input_vals",

0 commit comments

Comments
 (0)