diff --git a/doc/source/whatsnew/v1.3.3.rst b/doc/source/whatsnew/v1.3.3.rst index b3cd6d00d4322..549d0dcb593fd 100644 --- a/doc/source/whatsnew/v1.3.3.rst +++ b/doc/source/whatsnew/v1.3.3.rst @@ -14,6 +14,7 @@ including other versions of pandas. Fixed regressions ~~~~~~~~~~~~~~~~~ +- Fixed regression in :class:`DataFrame` constructor failing to broadcast for defined :class:`Index` and len one list of :class:`Timestamp` (:issue:`42810`) - Performance regression in :meth:`core.window.ewm.ExponentialMovingWindow.mean` (:issue:`42333`) - - diff --git a/pandas/core/construction.py b/pandas/core/construction.py index f84aaa907f3fc..7215cd17409cb 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -550,7 +550,6 @@ def sanitize_array( subarr = subarr.astype(dtype, copy=copy) elif copy: subarr = subarr.copy() - return subarr else: if isinstance(data, (set, frozenset)): diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 71f9544df42a3..6bf12a843eb9a 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1300,6 +1300,21 @@ def test_constructor_unequal_length_nested_list_column(self): with pytest.raises(ValueError, match=msg): DataFrame([[1, 2, 3, 4], [4, 5, 6, 7]], columns=arrays) + @pytest.mark.parametrize( + "data", + [ + [[Timestamp("2021-01-01")]], + [{"x": Timestamp("2021-01-01")}], + {"x": [Timestamp("2021-01-01")]}, + {"x": Timestamp("2021-01-01")}, + ], + ) + def test_constructor_one_element_data_list(self, data): + # GH#42810 + result = DataFrame(data, index=[0, 1, 2], columns=["x"]) + expected = DataFrame({"x": [Timestamp("2021-01-01")] * 3}) + tm.assert_frame_equal(result, expected) + def test_constructor_sequence_like(self): # GH 3783 # collections.Sequence like