From 648e6bf5af1be5680d9e30e4a7fa3a8d55ac9176 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Tue, 17 Aug 2021 08:26:16 +0200 Subject: [PATCH 1/2] Fix len one list dataframe constructor bug for datetime (#43041) * Fix len one list dataframe constructor bug for datetime * Move whatsnew Co-authored-by: Jeff Reback (cherry picked from commit f5d1cacb384534b59461c36a55e39e2188e7ba53) --- doc/source/whatsnew/v1.3.3.rst | 2 ++ pandas/core/construction.py | 1 - pandas/tests/frame/test_constructors.py | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.3.rst b/doc/source/whatsnew/v1.3.3.rst index 78f1883695c47..549d0dcb593fd 100644 --- a/doc/source/whatsnew/v1.3.3.rst +++ b/doc/source/whatsnew/v1.3.3.rst @@ -14,6 +14,8 @@ 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 68d7f6c6f8a22..9d48bf612eb11 100644 --- a/pandas/core/construction.py +++ b/pandas/core/construction.py @@ -552,7 +552,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 1d286e379da86..94fba0cbb90d5 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1286,6 +1286,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 From 031b83c3a468aca6d9e379b83609d76bec64e54b Mon Sep 17 00:00:00 2001 From: phofl Date: Tue, 17 Aug 2021 09:40:14 +0200 Subject: [PATCH 2/2] Remove other whatsnew --- doc/source/whatsnew/v1.3.3.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.3.3.rst b/doc/source/whatsnew/v1.3.3.rst index 549d0dcb593fd..40adf1bd70389 100644 --- a/doc/source/whatsnew/v1.3.3.rst +++ b/doc/source/whatsnew/v1.3.3.rst @@ -15,7 +15,6 @@ 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`) - -