From 99fb660d79e72d769cb4de2f7cd3753e502a03da Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Tue, 18 Apr 2017 17:18:27 +0530 Subject: [PATCH 01/14] TST: wrote test representing bug fix result for #15520 --- pandas/tests/dtypes/test_common.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 1017f93b8241c..1e7751c53aacd 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -2,6 +2,7 @@ import pytest import numpy as np +import pandas as pd from pandas.core.dtypes.dtypes import ( DatetimeTZDtype, PeriodDtype, CategoricalDtype) @@ -13,6 +14,15 @@ class TestPandasDtype(tm.TestCase): + # Passing invalid dtype, both as a string or object, must raise TypeError + def test_invalid_dtype_error(self): + msg = 'not understood' + with tm.assertRaisesRegexp(TypeError, msg): + pandas_dtype(pd.Timestamp) + + with tm.assertRaisesRegexp(TypeError, msg): + pandas_dtype('time') + def test_numpy_dtype(self): for dtype in ['M8[ns]', 'm8[ns]', 'object', 'float64', 'int64']: self.assertEqual(pandas_dtype(dtype), np.dtype(dtype)) From fecba127033ebbe2810e2d37a59d4a459a9f3b2d Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Tue, 18 Apr 2017 17:37:18 +0530 Subject: [PATCH 02/14] BUG: Raise when invalid dtype passed to pandas_dtype Changes made to pandas_dtype() in pandas/core/dtypes/common.py --- pandas/core/dtypes/common.py | 2 ++ pandas/core/generic.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 0b14e484d40a7..63e5d0b39adc1 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -737,5 +737,7 @@ def pandas_dtype(dtype): pass elif isinstance(dtype, ExtensionDtype): return dtype + elif np.dtype(dtype).kind == 'O': + raise TypeError("data type {0} not understood".format(dtype)) return np.dtype(dtype) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 841df3727e5a6..c42d509a15c7a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -23,7 +23,8 @@ is_datetime64tz_dtype, is_list_like, is_dict_like, - is_re_compilable) + is_re_compilable, + pandas_dtype) from pandas.core.dtypes.cast import maybe_promote, maybe_upcast_putmask from pandas.core.dtypes.missing import isnull, notnull from pandas.core.dtypes.generic import ABCSeries, ABCPanel @@ -165,12 +166,15 @@ def _validate_dtype(self, dtype): if dtype is not None: dtype = _coerce_to_dtype(dtype) + # This would raise an error if an invalid dtype was passed + dtype = pandas_dtype(dtype) # a compound dtype if dtype.kind == 'V': raise NotImplementedError("compound dtypes are not implemented" "in the {0} constructor" .format(self.__class__.__name__)) + return dtype def _init_mgr(self, mgr, axes=None, dtype=None, copy=False): From c10e1d466f311ab0e2357fcfb24de329ec2ccb1b Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Tue, 18 Apr 2017 18:54:23 +0530 Subject: [PATCH 03/14] TST: maintain list containing dtypes in TestPandasDtype --- pandas/tests/dtypes/test_common.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 1e7751c53aacd..9a67dd0caa828 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -17,11 +17,9 @@ class TestPandasDtype(tm.TestCase): # Passing invalid dtype, both as a string or object, must raise TypeError def test_invalid_dtype_error(self): msg = 'not understood' - with tm.assertRaisesRegexp(TypeError, msg): - pandas_dtype(pd.Timestamp) - - with tm.assertRaisesRegexp(TypeError, msg): - pandas_dtype('time') + for dtype in [pd.Timestamp, 'time']: + with tm.assertRaisesRegexp(TypeError, msg): + pandas_dtype(dtype) def test_numpy_dtype(self): for dtype in ['M8[ns]', 'm8[ns]', 'object', 'float64', 'int64']: From 3700259dcb6ab3193b5c517466f8e9fded8ed2c7 Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Tue, 18 Apr 2017 18:58:38 +0530 Subject: [PATCH 04/14] CLN: Replace _coerce_to_dtype() with pandas_dtype() Changes made to series.py, generic.py in pandas/core and cast.py in pandas/core/dtypes --- pandas/core/dtypes/cast.py | 4 ++-- pandas/core/generic.py | 2 -- pandas/core/series.py | 7 ++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 3c1f480787d3a..8270e0c08a3b4 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -22,7 +22,7 @@ is_numeric_dtype, is_decimal, is_number, _string_dtypes, - _coerce_to_dtype, + pandas_dtype, _ensure_int8, _ensure_int16, _ensure_int32, _ensure_int64, _NS_DTYPE, _TD_DTYPE, _INT64_DTYPE, @@ -579,7 +579,7 @@ def astype_nansafe(arr, dtype, copy=True): """ return a view if copy is False, but need to be very careful as the result shape could change! """ if not isinstance(dtype, np.dtype): - dtype = _coerce_to_dtype(dtype) + dtype = pandas_dtype(dtype) if issubclass(dtype.type, text_type): # in Py3 that's str, in Py2 that's unicode diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c42d509a15c7a..0f67a79050107 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11,7 +11,6 @@ from pandas._libs import tslib, lib from pandas.core.dtypes.common import ( - _coerce_to_dtype, _ensure_int64, needs_i8_conversion, is_scalar, @@ -165,7 +164,6 @@ def _validate_dtype(self, dtype): """ validate the passed dtype """ if dtype is not None: - dtype = _coerce_to_dtype(dtype) # This would raise an error if an invalid dtype was passed dtype = pandas_dtype(dtype) diff --git a/pandas/core/series.py b/pandas/core/series.py index 69a2b35d88460..43273af720cc6 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -14,7 +14,7 @@ import numpy.ma as ma from pandas.core.dtypes.common import ( - _coerce_to_dtype, is_categorical_dtype, + is_categorical_dtype, is_bool, is_integer, is_integer_dtype, is_float_dtype, @@ -28,7 +28,8 @@ is_dict_like, is_scalar, _is_unorderable_exception, - _ensure_platform_int) + _ensure_platform_int, + pandas_dtype) from pandas.core.dtypes.generic import ABCSparseArray, ABCDataFrame from pandas.core.dtypes.cast import ( maybe_upcast, infer_dtype_from_scalar, @@ -2869,7 +2870,7 @@ def _sanitize_array(data, index, dtype=None, copy=False, """ if dtype is not None: - dtype = _coerce_to_dtype(dtype) + dtype = pandas_dtype(dtype) if isinstance(data, ma.MaskedArray): mask = ma.getmaskarray(data) From ee0030f1cf64a180d08246315243ebc07dd9c2dc Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Thu, 20 Apr 2017 18:26:09 +0530 Subject: [PATCH 05/14] TST: added more test-cases for pandas_dtype() test --- pandas/tests/dtypes/test_common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 9a67dd0caa828..2d3aa290b987a 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -17,10 +17,15 @@ class TestPandasDtype(tm.TestCase): # Passing invalid dtype, both as a string or object, must raise TypeError def test_invalid_dtype_error(self): msg = 'not understood' - for dtype in [pd.Timestamp, 'time']: + invalid_list = [pd.Timestamp, 'pd.Timestamp'] + for dtype in invalid_list: with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) + valid_list = [object, 'float64', np.float64, float, np.dtype('float64')] + for dtype in valid_list: + pandas_dtype(dtype) + def test_numpy_dtype(self): for dtype in ['M8[ns]', 'm8[ns]', 'object', 'float64', 'int64']: self.assertEqual(pandas_dtype(dtype), np.dtype(dtype)) From d4971cdba58ba1ddb75d501518e3ac7e8cfa0f4b Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Thu, 20 Apr 2017 18:27:12 +0530 Subject: [PATCH 06/14] BUG: pandas_dtype() to raise error for invalid dtype per GH15520 This change ensures that no error is raised when type 'object' is passed. --- pandas/core/dtypes/common.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 63e5d0b39adc1..ec7d5c2e9208a 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -731,13 +731,23 @@ def pandas_dtype(dtype): except TypeError: pass + elif dtype == 'object': + return np.dtype(dtype) + try: return CategoricalDtype.construct_from_string(dtype) except TypeError: pass elif isinstance(dtype, ExtensionDtype): return dtype - elif np.dtype(dtype).kind == 'O': - raise TypeError("data type {0} not understood".format(dtype)) + else: + try: + np.dtype(dtype) + except (TypeError, ValueError): + raise + if dtype == object: + return np.dtype(dtype) + elif np.dtype(dtype).kind == 'O': + raise TypeError('dtype {0} not understood'.format(dtype)) return np.dtype(dtype) From f858726c62f86dd174c56d8b37680841f0bd28da Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Fri, 21 Apr 2017 13:27:04 +0530 Subject: [PATCH 07/14] style fix --- pandas/tests/dtypes/test_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 2d3aa290b987a..c1d98a406d961 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -22,7 +22,8 @@ def test_invalid_dtype_error(self): with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) - valid_list = [object, 'float64', np.float64, float, np.dtype('float64')] + valid_list = [object, 'float64', + np.float64, float, np.dtype('float64')] for dtype in valid_list: pandas_dtype(dtype) From 3eaa43293f5b8b7f0170dc81747fc4dd0196bd36 Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Fri, 21 Apr 2017 14:23:54 +0530 Subject: [PATCH 08/14] TST: Added numpy.object_ dtype to valid pandas_dtype list --- pandas/tests/dtypes/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index c1d98a406d961..11455cdea3ed0 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -22,7 +22,7 @@ def test_invalid_dtype_error(self): with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) - valid_list = [object, 'float64', + valid_list = [object, 'float64', np.object_, np.float64, float, np.dtype('float64')] for dtype in valid_list: pandas_dtype(dtype) From a358181298640b8c6748483422bd6191d3c572d9 Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Fri, 21 Apr 2017 14:24:35 +0530 Subject: [PATCH 09/14] BUG: Added numpy.dtype_ to valid pandas_dtype() type list --- pandas/core/dtypes/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index ec7d5c2e9208a..74d5ffee62713 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -745,7 +745,7 @@ def pandas_dtype(dtype): np.dtype(dtype) except (TypeError, ValueError): raise - if dtype == object: + if dtype in [object, np.object_]: return np.dtype(dtype) elif np.dtype(dtype).kind == 'O': raise TypeError('dtype {0} not understood'.format(dtype)) From ad9f345c4a59dc3eab4b50baf39b5f6b9078666c Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Mon, 24 Apr 2017 16:37:28 +0530 Subject: [PATCH 10/14] CLN: refactored code related to issue GH15520 --- pandas/core/dtypes/common.py | 31 ++++++++++++++++-------------- pandas/core/generic.py | 1 - pandas/tests/dtypes/test_common.py | 3 ++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 74d5ffee62713..55c7576713642 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -731,23 +731,26 @@ def pandas_dtype(dtype): except TypeError: pass - elif dtype == 'object': - return np.dtype(dtype) - try: return CategoricalDtype.construct_from_string(dtype) except TypeError: pass elif isinstance(dtype, ExtensionDtype): return dtype - else: - try: - np.dtype(dtype) - except (TypeError, ValueError): - raise - if dtype in [object, np.object_]: - return np.dtype(dtype) - elif np.dtype(dtype).kind == 'O': - raise TypeError('dtype {0} not understood'.format(dtype)) - - return np.dtype(dtype) + + try: + npdtype = np.dtype(dtype) + except (TypeError, ValueError): + raise + + # Any invalid dtype (such as pd.Timestamp) should raise an error. + # np.dtype(invalid_type).kind = 0 for such objects. However, this will + # also catch some valid dtypes such as object, np.object_ and 'object' + # which we safeguard against by catching them earlier and returning + # np.dtype(valid_dtype) before this condition is evaluated. + if dtype in [object, np.object_, 'object']: + return npdtype + elif npdtype.kind == 'O': + raise TypeError('dtype {0} not understood'.format(dtype)) + + return npdtype diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0f67a79050107..a14a6707a36e3 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -164,7 +164,6 @@ def _validate_dtype(self, dtype): """ validate the passed dtype """ if dtype is not None: - # This would raise an error if an invalid dtype was passed dtype = pandas_dtype(dtype) # a compound dtype diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 11455cdea3ed0..5c4bbe284a286 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -15,6 +15,7 @@ class TestPandasDtype(tm.TestCase): # Passing invalid dtype, both as a string or object, must raise TypeError + # Per issue GH15520 def test_invalid_dtype_error(self): msg = 'not understood' invalid_list = [pd.Timestamp, 'pd.Timestamp'] @@ -22,7 +23,7 @@ def test_invalid_dtype_error(self): with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) - valid_list = [object, 'float64', np.object_, + valid_list = [object, 'float64', np.object_, np.dtype('object'), np.float64, float, np.dtype('float64')] for dtype in valid_list: pandas_dtype(dtype) From fbed5a62edff9e67800be5bbaf196e8626ffeb22 Mon Sep 17 00:00:00 2001 From: Akash Tandon Date: Mon, 24 Apr 2017 16:47:58 +0530 Subject: [PATCH 11/14] TST: Added list to invalid dtype Changes made to: - test_empty_str_methods in test_strings.py - test_invalid_dtype_error in dtypes/test_common.py --- pandas/tests/dtypes/test_common.py | 2 +- pandas/tests/test_strings.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 5c4bbe284a286..676037de93b0f 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -18,7 +18,7 @@ class TestPandasDtype(tm.TestCase): # Per issue GH15520 def test_invalid_dtype_error(self): msg = 'not understood' - invalid_list = [pd.Timestamp, 'pd.Timestamp'] + invalid_list = [pd.Timestamp, 'pd.Timestamp', list] for dtype in invalid_list: with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 7a68ec8f368ae..3272397ea0ab5 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -1207,10 +1207,9 @@ def test_extractall_same_as_extract_subject_index(self): tm.assert_frame_equal(extract_one_noname, no_match_index) def test_empty_str_methods(self): - empty_str = empty = Series(dtype=str) + empty_str = empty = Series(dtype=object) empty_int = Series(dtype=int) empty_bool = Series(dtype=bool) - empty_list = Series(dtype=list) empty_bytes = Series(dtype=object) # GH7241 @@ -1241,25 +1240,24 @@ def test_empty_str_methods(self): DataFrame(columns=[0, 1], dtype=str), empty.str.extract('()()', expand=False)) tm.assert_frame_equal(DataFrame(dtype=str), empty.str.get_dummies()) - tm.assert_series_equal(empty_str, empty_list.str.join('')) + tm.assert_series_equal(empty_str, empty_str.str.join('')) tm.assert_series_equal(empty_int, empty.str.len()) - tm.assert_series_equal(empty_list, empty_list.str.findall('a')) + tm.assert_series_equal(empty_str, empty_str.str.findall('a')) tm.assert_series_equal(empty_int, empty.str.find('a')) tm.assert_series_equal(empty_int, empty.str.rfind('a')) tm.assert_series_equal(empty_str, empty.str.pad(42)) tm.assert_series_equal(empty_str, empty.str.center(42)) - tm.assert_series_equal(empty_list, empty.str.split('a')) - tm.assert_series_equal(empty_list, empty.str.rsplit('a')) - tm.assert_series_equal(empty_list, + tm.assert_series_equal(empty_str, empty.str.split('a')) + tm.assert_series_equal(empty_str, empty.str.rsplit('a')) + tm.assert_series_equal(empty_str, empty.str.partition('a', expand=False)) - tm.assert_series_equal(empty_list, + tm.assert_series_equal(empty_str, empty.str.rpartition('a', expand=False)) tm.assert_series_equal(empty_str, empty.str.slice(stop=1)) tm.assert_series_equal(empty_str, empty.str.slice(step=1)) tm.assert_series_equal(empty_str, empty.str.strip()) tm.assert_series_equal(empty_str, empty.str.lstrip()) tm.assert_series_equal(empty_str, empty.str.rstrip()) - tm.assert_series_equal(empty_str, empty.str.rstrip()) tm.assert_series_equal(empty_str, empty.str.wrap(42)) tm.assert_series_equal(empty_str, empty.str.get(0)) tm.assert_series_equal(empty_str, empty_bytes.str.decode('ascii')) From c3699fb5a5b360d50eedf990392cf713de3909eb Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 Apr 2017 09:21:46 +0530 Subject: [PATCH 12/14] DOC: added whatsnew entry for PR#16047 addressing GH15520 --- doc/source/whatsnew/v0.20.0.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 9fe0b66028ac5..0d66f402b4060 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -1509,6 +1509,8 @@ Conversion - Bug in ``is_string_dtype``, ``is_timedelta64_ns_dtype``, and ``is_string_like_dtype`` in which an error was raised when ``None`` was passed in (:issue:`15941`) - Bug in the return type of ``pd.unique`` on a ``Categorical``, which was returning an ndarray and not a ``Categorical`` (:issue:`15903`) - Bug in ``Index.to_series()`` where the index was not copied (and so mutating later would change the original), (:issue:`15949`) +- Bug in indexing with partial string indexing with a len-1 DataFrame (:issue:`16071`) +- Bug in ``pandas_dtype`` where passing invalid dtype didn't raise an error. (:issue:`15520`) Indexing ^^^^^^^^ From b3c2fbbdddb6a0f2d6cda9662fcb1552922506b6 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 25 Apr 2017 09:24:12 +0530 Subject: [PATCH 13/14] BUG: Added 'O' to pandas_dtype's valid list --- pandas/core/dtypes/common.py | 2 +- pandas/tests/dtypes/test_common.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 55c7576713642..c9afe525d57a5 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -748,7 +748,7 @@ def pandas_dtype(dtype): # also catch some valid dtypes such as object, np.object_ and 'object' # which we safeguard against by catching them earlier and returning # np.dtype(valid_dtype) before this condition is evaluated. - if dtype in [object, np.object_, 'object']: + if dtype in [object, np.object_, 'object', 'O']: return npdtype elif npdtype.kind == 'O': raise TypeError('dtype {0} not understood'.format(dtype)) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 676037de93b0f..2df0455619dd1 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -23,7 +23,7 @@ def test_invalid_dtype_error(self): with tm.assertRaisesRegexp(TypeError, msg): pandas_dtype(dtype) - valid_list = [object, 'float64', np.object_, np.dtype('object'), + valid_list = [object, 'float64', np.object_, np.dtype('object'), 'O', np.float64, float, np.dtype('float64')] for dtype in valid_list: pandas_dtype(dtype) From 3646eb6a3e95d419d54a7cc83ca0bede35352387 Mon Sep 17 00:00:00 2001 From: analyticalmonk Date: Tue, 25 Apr 2017 19:41:02 +0530 Subject: [PATCH 14/14] TST: check for invalid dtype for Series constructor per GH15520 --- pandas/tests/series/test_constructors.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 57cce1d1cf199..74c2544d900ea 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -30,6 +30,14 @@ class TestSeriesConstructors(TestData, tm.TestCase): + def test_invalid_dtype(self): + # GH15520 + msg = 'not understood' + invalid_list = [pd.Timestamp, 'pd.Timestamp', list] + for dtype in invalid_list: + with tm.assertRaisesRegexp(TypeError, msg): + Series([], name='time', dtype=dtype) + def test_scalar_conversion(self): # Pass in scalar is disabled