Skip to content

Commit a63365b

Browse files
committed
TST: astype cast via loc with nan values (pandas-dev#31861)
1 parent 8c76a64 commit a63365b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

pandas/tests/frame/methods/test_astype.py

+9
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ def test_astype_cast_nan_inf_int(self, val, dtype):
136136
with pytest.raises(ValueError, match=msg):
137137
df.astype(dtype)
138138

139+
@pytest.mark.parametrize("dtype", ["Int64", "Int32", "Int16"])
140+
@pytest.mark.parametrize("val", [np.nan])
141+
def test_astype_cast_via_loc_nan_int(self, val, dtype):
142+
# see GH#31861
143+
expected = DataFrame({"a": ["foo"], "b": integer_array([val], dtype=dtype)})
144+
result = DataFrame({"a": ["foo"], "b": [val]})
145+
result.loc[:, "b"] = result.loc[:, "b"].astype(dtype)
146+
tm.assert_frame_equal(result, expected)
147+
139148
def test_astype_str(self):
140149
# see GH#9757
141150
a = Series(date_range("2010-01-04", periods=5))

0 commit comments

Comments
 (0)