From 1937c71f5c23b431bec69ff596b893988bb1adc2 Mon Sep 17 00:00:00 2001 From: prakhar pandey Date: Fri, 31 Jan 2020 14:18:19 +0530 Subject: [PATCH] TST: added test to validate (#31340) --- pandas/tests/indexing/test_loc.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index b9dc96adfa738..0cb4bdcc334d8 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -92,6 +92,18 @@ def test_loc_setitem_slice(self): expected = DataFrame({"a": [0, 1, 1], "b": [100, 200, 300]}, dtype="uint64") tm.assert_frame_equal(df2, expected) + def test_loc_setitem_dtype(self): + # GH31340 + df = DataFrame({"id": ["A"], "a": [1.2], "b": [0.0], "c": [-2.5]}) + cols = ["a", "b", "c"] + df.loc[:, cols] = df.loc[:, cols].astype("float32") + + expected = DataFrame( + {"id": ["A"], "a": [1.2], "b": [0.0], "c": [-2.5]}, dtype="float32" + ) # id is inferred as object + + tm.assert_frame_equal(df, expected) + def test_loc_getitem_int(self): # int label