From 266702af63d681c743176784a8513038e6f6e5fe Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Wed, 6 Feb 2019 07:47:00 +0530 Subject: [PATCH] Backport PR #25089: Fixed tuple to List Conversion in Dataframe class --- doc/source/whatsnew/v0.24.2.rst | 4 +++- pandas/_libs/lib.pyx | 2 +- pandas/tests/frame/test_constructors.py | 7 +++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index a047ad46e4887..6a9a316da1ec6 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -22,6 +22,8 @@ Fixed Regressions - Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only=True`` was ignored (:issue:`25101`) +- Fixed issue in ``DataFrame`` construction with passing a mixed list of mixed types could segfault. (:issue:`25075`) + .. _whatsnew_0242.enhancements: Enhancements @@ -94,4 +96,4 @@ Bug Fixes Contributors ~~~~~~~~~~~~ -.. contributors:: v0.24.1..v0.24.2 \ No newline at end of file +.. contributors:: v0.24.1..v0.24.2 diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 333626b309e3a..9f1f4d3f1dfa3 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2269,7 +2269,7 @@ def to_object_array(rows: object, int min_width=0): result = np.empty((n, k), dtype=object) for i in range(n): - row = input_rows[i] + row = list(input_rows[i]) for j in range(len(row)): result[i, j] = row[j] diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 90ad48cac3a5f..b97f5e0b6edf9 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1183,6 +1183,13 @@ def test_constructor_mixed_dict_and_Series(self): index=['a', 'b']) tm.assert_frame_equal(result, expected) + def test_constructor_mixed_type_rows(self): + # Issue 25075 + data = [[1, 2], (3, 4)] + result = DataFrame(data) + expected = DataFrame([[1, 2], [3, 4]]) + tm.assert_frame_equal(result, expected) + def test_constructor_tuples(self): result = DataFrame({'A': [(1, 2), (3, 4)]}) expected = DataFrame({'A': Series([(1, 2), (3, 4)])})