Skip to content

Commit f5d1cac

Browse files
phofljreback
andauthored
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 <[email protected]>
1 parent bc16631 commit f5d1cac

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v1.3.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17+
- Fixed regression in :class:`DataFrame` constructor failing to broadcast for defined :class:`Index` and len one list of :class:`Timestamp` (:issue:`42810`)
1718
- Performance regression in :meth:`core.window.ewm.ExponentialMovingWindow.mean` (:issue:`42333`)
1819
-
1920
-

pandas/core/construction.py

-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ def sanitize_array(
550550
subarr = subarr.astype(dtype, copy=copy)
551551
elif copy:
552552
subarr = subarr.copy()
553-
return subarr
554553

555554
else:
556555
if isinstance(data, (set, frozenset)):

pandas/tests/frame/test_constructors.py

+15
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,21 @@ def test_constructor_unequal_length_nested_list_column(self):
13001300
with pytest.raises(ValueError, match=msg):
13011301
DataFrame([[1, 2, 3, 4], [4, 5, 6, 7]], columns=arrays)
13021302

1303+
@pytest.mark.parametrize(
1304+
"data",
1305+
[
1306+
[[Timestamp("2021-01-01")]],
1307+
[{"x": Timestamp("2021-01-01")}],
1308+
{"x": [Timestamp("2021-01-01")]},
1309+
{"x": Timestamp("2021-01-01")},
1310+
],
1311+
)
1312+
def test_constructor_one_element_data_list(self, data):
1313+
# GH#42810
1314+
result = DataFrame(data, index=[0, 1, 2], columns=["x"])
1315+
expected = DataFrame({"x": [Timestamp("2021-01-01")] * 3})
1316+
tm.assert_frame_equal(result, expected)
1317+
13031318
def test_constructor_sequence_like(self):
13041319
# GH 3783
13051320
# collections.Sequence like

0 commit comments

Comments
 (0)