Skip to content

Commit 5a993b8

Browse files
committed
TST: added working conditions for astype via loc (pandas-dev#31861)
1 parent 129b1b5 commit 5a993b8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/frame/methods/test_astype.py

+19
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ def test_astype_cast_via_loc_nan_int(self, val, dtype):
146146
df.loc[:, "b"] = df.loc[:, "b"].astype(dtype)
147147
tm.assert_frame_equal(df, expected)
148148

149+
expected2 = DataFrame(
150+
{"a": ["foo", "foo"], "b": integer_array([val, 1.0], dtype=dtype)}
151+
)
152+
df2 = DataFrame({"a": ["foo", "foo"], "b": [val, 1.0]})
153+
df2.loc[:, "b"] = df2.loc[:, "b"].astype(dtype)
154+
tm.assert_frame_equal(df2, expected2)
155+
156+
expected3 = DataFrame(
157+
{"a": ["foo", "foo"], "b": integer_array([val, val], dtype=dtype)}
158+
)
159+
df3 = DataFrame({"a": ["foo", "foo"], "b": [val, val]})
160+
df3.loc[:, "b"] = df3.loc[:, "b"].astype(dtype)
161+
tm.assert_frame_equal(df3, expected3)
162+
163+
expected4 = DataFrame({"b": integer_array([val], dtype=dtype)})
164+
df4 = DataFrame({"b": [val]})
165+
df4.loc[:, "b"] = df4.loc[:, "b"].astype(dtype)
166+
tm.assert_frame_equal(df4, expected4)
167+
149168
def test_astype_str(self):
150169
# see GH#9757
151170
a = Series(date_range("2010-01-04", periods=5))

0 commit comments

Comments
 (0)