From 583754f6dccb340522d16d3587c8fad462c8ea75 Mon Sep 17 00:00:00 2001 From: Andy Hayden Date: Wed, 10 Jul 2013 14:05:39 +0100 Subject: [PATCH] FIX disallow MultiIndex in Series constructor GH4187 --- doc/source/release.rst | 1 + pandas/core/series.py | 3 +++ pandas/tests/test_series.py | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/doc/source/release.rst b/doc/source/release.rst index a965d92e5dbe3..d97a99426ff7d 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -199,6 +199,7 @@ pandas 0.12 - Fixed an esoteric excel reading bug, xlrd>= 0.9.0 now required for excel support. Should provide python3 support (for reading) which has been lacking. (:issue:`3164`) + - Disallow Series constructor called with MultiIndex which caused segfault (:issue:`4187`) - Allow unioning of date ranges sharing a timezone (:issue:`3491`) - Fix to_csv issue when having a large number of rows and ``NaT`` in some columns (:issue:`3437`) diff --git a/pandas/core/series.py b/pandas/core/series.py index 06abd1d5b4127..cb81c15a24122 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -432,6 +432,9 @@ def __new__(cls, data=None, index=None, dtype=None, name=None, if data is None: data = {} + if isinstance(data, MultiIndex): + raise NotImplementedError + if index is not None: index = _ensure_index(index) diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index b4ad172ddf340..e2afb2bf26a6c 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -311,6 +311,10 @@ def test_constructor(self): xp = 'Series' self.assertEqual(rs, xp) + # raise on MultiIndex GH4187 + m = MultiIndex.from_arrays([[1, 2], [3,4]]) + self.assertRaises(NotImplementedError, Series, m) + def test_constructor_empty(self): empty = Series() empty2 = Series([])