From 3749db6478ee291ad612f235788191910824bbc5 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Fri, 12 Apr 2019 14:17:12 +0200 Subject: [PATCH 1/4] merge master --- doc/source/whatsnew/v0.25.0.rst | 4 +--- pandas/core/sparse/frame.py | 8 ++++---- pandas/tests/sparse/frame/test_frame.py | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index e2ae7cfc0cc34..884c096b3c871 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -254,8 +254,6 @@ Performance Improvements Bug Fixes ~~~~~~~~~ - - Categorical ^^^^^^^^^^^ @@ -402,7 +400,7 @@ Sparse - Significant speedup in `SparseArray` initialization that benefits most operations, fixing performance regression introduced in v0.20.0 (:issue:`24985`) - Bug in :class:`SparseFrame` constructor where passing ``None`` as the data would cause ``default_fill_value`` to be ignored (:issue:`16807`) -- +- Bug in `SparseDataFrame` when adding a column in which the length of values does not match length of index, ``AssertionError`` is raised instead of raising ``ValueError`` (:issue:`25484`) Other diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index d7fe6d837f04d..08729442e701f 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -430,8 +430,8 @@ def sp_maker(x, index=None): elif isinstance(value, SparseArray): if len(value) != len(self.index): - raise AssertionError('Length of values does not match ' - 'length of index') + raise ValueError('Length of values does not match ' + 'length of index') clean = value elif hasattr(value, '__iter__'): @@ -441,8 +441,8 @@ def sp_maker(x, index=None): clean = sp_maker(clean) else: if len(value) != len(self.index): - raise AssertionError('Length of values does not match ' - 'length of index') + raise ValueError('Length of values does not match ' + 'length of index') clean = sp_maker(value) # Scalar diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 954dd85f16c28..45df08ccfeb48 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -568,8 +568,9 @@ def _check_frame(frame, orig): assert len(frame['I'].sp_values) == N // 2 # insert ndarray wrong size - msg = "Length of values does not match length of index" - with pytest.raises(AssertionError, match=msg): + # GH 25484 + msg = 'Length of values does not match length of index' + with pytest.raises(ValueError, match=msg): frame['foo'] = np.random.randn(N - 1) # scalar value From 4f00463cd50e00e4dd5e752ae3c1817a227e4625 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Fri, 12 Apr 2019 14:19:39 +0200 Subject: [PATCH 2/4] put back bashes that removed by accident --- doc/source/whatsnew/v0.25.0.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 884c096b3c871..30dc0dfae6cc8 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -254,6 +254,9 @@ Performance Improvements Bug Fixes ~~~~~~~~~ +- +- + Categorical ^^^^^^^^^^^ From fbd23055ce096b13ef8f8be7c81160bb3f20e5f7 Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Fri, 12 Apr 2019 14:20:47 +0200 Subject: [PATCH 3/4] restore changes --- doc/source/whatsnew/v0.25.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 30dc0dfae6cc8..8e4d2ca3c2d45 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -254,7 +254,6 @@ Performance Improvements Bug Fixes ~~~~~~~~~ -- - Categorical From 7562481db9b26b6410e5999c0e2d8cc3d0830f4f Mon Sep 17 00:00:00 2001 From: Kaiqi Dong Date: Fri, 12 Apr 2019 14:21:56 +0200 Subject: [PATCH 4/4] restore changes --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 8e4d2ca3c2d45..7b87f6a7f8d3c 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -254,7 +254,7 @@ Performance Improvements Bug Fixes ~~~~~~~~~ -- + Categorical ^^^^^^^^^^^