From 5ab27e5a9b31ff62046603f32a85a0bf41f5001f Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Sat, 2 Feb 2019 15:30:02 +0530 Subject: [PATCH 1/5] Fixed tuple to List Conversion in Dataframe class --- pandas/_libs/lib.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index f8875d60049b1..1f0f0a408aee8 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -2277,7 +2277,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] From 60cc4a648c93ae9e648b5453afd4b2c07e7719c2 Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Mon, 4 Feb 2019 20:33:26 +0530 Subject: [PATCH 2/5] Added tests and Modified whatsnew --- doc/source/whatsnew/v0.24.2.rst | 11 +++++------ pandas/tests/frame/test_constructors.py | 7 +++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index a047ad46e4887..7eebce3a80bfd 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -22,13 +22,14 @@ Fixed Regressions - Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only=True`` was ignored (:issue:`25101`) +- Fixed regression in :meth:`DataFrame.__init__` where mixed type of rows generated `Segmentation fault` (:issue:`25075`) + .. _whatsnew_0242.enhancements: Enhancements ^^^^^^^^^^^^ -- -- +- The DataFrame class supports list as well as tuples in the ndarray, which previously raised `TypeError` .. _whatsnew_0242.bug_fixes: @@ -37,9 +38,7 @@ Bug Fixes **Conversion** -- -- -- +- Fixed bug in :meth:`lib.pyx` where `tuple` to `list` conversion failed ([:issue:25075](https://github.com/pandas-dev/pandas/pull/25089#issue-249804406)) **Indexing** @@ -94,4 +93,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/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 90ad48cac3a5f..8b663227b41ef 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): + data = [[1, 2], (3, 4)] + result = DataFrame(data) + data2 = [[1, 2], [3, 4]] + expected = DataFrame(data2) + 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)])}) From 37936a38f318c959708f535a519daaa64eaf32e2 Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Mon, 4 Feb 2019 22:32:23 +0530 Subject: [PATCH 3/5] Modified whatsnew and Done asv check --- doc/source/whatsnew/v0.24.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index 7eebce3a80bfd..2524cc8701dfe 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -38,7 +38,7 @@ Bug Fixes **Conversion** -- Fixed bug in :meth:`lib.pyx` where `tuple` to `list` conversion failed ([:issue:25075](https://github.com/pandas-dev/pandas/pull/25089#issue-249804406)) +- Fixed bug in :meth:`lib.pyx` where `tuple` to `list` conversion failed (:issue:`25089`) **Indexing** From 26cb100a38d8a8332f593aae007a3e1544ae92de Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Tue, 5 Feb 2019 10:28:06 +0530 Subject: [PATCH 4/5] Made requested changes --- doc/source/whatsnew/v0.24.2.rst | 9 ++++++--- pandas/tests/frame/test_constructors.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.24.2.rst b/doc/source/whatsnew/v0.24.2.rst index 2524cc8701dfe..6a9a316da1ec6 100644 --- a/doc/source/whatsnew/v0.24.2.rst +++ b/doc/source/whatsnew/v0.24.2.rst @@ -22,14 +22,15 @@ Fixed Regressions - Fixed regression in :meth:`DataFrame.all` and :meth:`DataFrame.any` where ``bool_only=True`` was ignored (:issue:`25101`) -- Fixed regression in :meth:`DataFrame.__init__` where mixed type of rows generated `Segmentation fault` (:issue:`25075`) +- Fixed issue in ``DataFrame`` construction with passing a mixed list of mixed types could segfault. (:issue:`25075`) .. _whatsnew_0242.enhancements: Enhancements ^^^^^^^^^^^^ -- The DataFrame class supports list as well as tuples in the ndarray, which previously raised `TypeError` +- +- .. _whatsnew_0242.bug_fixes: @@ -38,7 +39,9 @@ Bug Fixes **Conversion** -- Fixed bug in :meth:`lib.pyx` where `tuple` to `list` conversion failed (:issue:`25089`) +- +- +- **Indexing** diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 8b663227b41ef..3a44b048ca36f 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1184,10 +1184,10 @@ def test_constructor_mixed_dict_and_Series(self): tm.assert_frame_equal(result, expected) def test_constructor_mixed_type_rows(self): + # Issue #25075 data = [[1, 2], (3, 4)] result = DataFrame(data) - data2 = [[1, 2], [3, 4]] - expected = DataFrame(data2) + expected = DataFrame([[1, 2], [3, 4]]) tm.assert_frame_equal(result, expected) def test_constructor_tuples(self): From 3e424effd3976eb1734a74a40bbae126daffbf62 Mon Sep 17 00:00:00 2001 From: Vibhu Agarwal Date: Tue, 5 Feb 2019 10:34:08 +0530 Subject: [PATCH 5/5] Updated according to PEP8 --- pandas/tests/frame/test_constructors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_constructors.py b/pandas/tests/frame/test_constructors.py index 3a44b048ca36f..b97f5e0b6edf9 100644 --- a/pandas/tests/frame/test_constructors.py +++ b/pandas/tests/frame/test_constructors.py @@ -1184,7 +1184,7 @@ def test_constructor_mixed_dict_and_Series(self): tm.assert_frame_equal(result, expected) def test_constructor_mixed_type_rows(self): - # Issue #25075 + # Issue 25075 data = [[1, 2], (3, 4)] result = DataFrame(data) expected = DataFrame([[1, 2], [3, 4]])