From ed8baec6cbcdb489f7fc0af906ebcf1357417478 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Thu, 30 May 2019 20:18:05 -0500 Subject: [PATCH 01/12] Include more specific error messaging for non coo matrix and introduce non regression tests --- pandas/core/arrays/sparse.py | 12 ++++++++---- pandas/tests/arrays/sparse/test_accessor.py | 7 +++++++ pandas/tests/arrays/sparse/test_array.py | 7 +++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index ecc06db2bd07b..c5f18f8a22a6a 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -2014,11 +2014,15 @@ def from_coo(cls, A, dense_index=False): from pandas.core.sparse.scipy_sparse import _coo_to_sparse_series from pandas import Series - result = _coo_to_sparse_series(A, dense_index=dense_index, - sparse_series=False) - result = Series(result.array, index=result.index, copy=False) + try: + result = _coo_to_sparse_series(A, dense_index=dense_index, + sparse_series=False) + result = Series(result.array, index=result.index, copy=False) - return result + return result + + except AttributeError: + raise AttributeError('Expected coo matrix format.') def to_coo(self, row_levels=(0, ), column_levels=(1, ), sort_labels=False): """ diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index 370d222c1ab4e..d2cc605f05019 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -119,3 +119,10 @@ def test_series_from_coo(self, dtype, dense_index): ) tm.assert_series_equal(result, expected) + + @td.skip_if_no_scipy + def test_series_from_coo_incorrect_format(self): + import scipy.sparse + m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) + with pytest.raises(AttributeError): + pd.Series.sparse.from_coo(m) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 659f2b97485a9..f8a09ae8eb56a 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -1128,6 +1128,13 @@ def test_from_coo(self): expected = pd.Series([4, 9, 7, 5], index=index, dtype='Sparse[int]') tm.assert_series_equal(result, expected) + @td.skip_if_no_scipy + def test_from_coo_invalid_input(self): + import scipy.sparse + m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) + with pytest.raises(AttributeError): + pd.Series.sparse.from_coo(m) + @td.skip_if_no_scipy def test_to_coo(self): import scipy.sparse From 811647dc72e39953689c37fd0f85b2cc600f8adf Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Thu, 30 May 2019 20:29:01 -0500 Subject: [PATCH 02/12] Log changes to what's new --- 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 89a9da4a73b35..329bf8d28aebb 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) - +- Introduce a more specific error message in :class:`SparseAccessor` so user knows when they provide the incorrect matrix format to `from_coo` (:issue:`26554`) Other ^^^^^ From 282bc9fcfcd10b269bd7718b98b1a9197ddd6257 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Fri, 31 May 2019 17:25:23 -0500 Subject: [PATCH 03/12] Remove redundant test Move try-catch block to _coo_to_sparse_series Update entry log --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/arrays/sparse.py | 10 ++---- pandas/core/sparse/scipy_sparse.py | 39 +++++++++++++----------- pandas/tests/arrays/sparse/test_array.py | 7 ----- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 329bf8d28aebb..6bcf061356680 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) -- Introduce a more specific error message in :class:`SparseAccessor` so user knows when they provide the incorrect matrix format to `from_coo` (:issue:`26554`) +- Introduce a more specific error message in :meth:`_coo_to_sparse_series` so user knows when they provide the incorrect matrix format to `from_coo` (:issue:`26554`) Other ^^^^^ diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index c5f18f8a22a6a..4950acfa9f0cc 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -2014,15 +2014,11 @@ def from_coo(cls, A, dense_index=False): from pandas.core.sparse.scipy_sparse import _coo_to_sparse_series from pandas import Series - try: - result = _coo_to_sparse_series(A, dense_index=dense_index, + result = _coo_to_sparse_series(A, dense_index=dense_index, sparse_series=False) - result = Series(result.array, index=result.index, copy=False) - - return result + result = Series(result.array, index=result.index, copy=False) - except AttributeError: - raise AttributeError('Expected coo matrix format.') + return result def to_coo(self, row_levels=(0, ), column_levels=(1, ), sort_labels=False): """ diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index 7630983421ff9..d2ea1deb657c4 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -129,23 +129,28 @@ def _coo_to_sparse_series(A, dense_index: bool = False, Returns ------- - Series or SparseSeries + Series or SparseSeries on success + """ from pandas import SparseDtype - s = Series(A.data, MultiIndex.from_arrays((A.row, A.col))) - s = s.sort_index() - if sparse_series: - # TODO(SparseSeries): remove this and the sparse_series keyword. - # This is just here to avoid a DeprecationWarning when - # _coo_to_sparse_series is called via Series.sparse.from_coo - s = s.to_sparse() # TODO: specify kind? - else: - s = s.astype(SparseDtype(s.dtype)) - if dense_index: - # is there a better constructor method to use here? - i = range(A.shape[0]) - j = range(A.shape[1]) - ind = MultiIndex.from_product([i, j]) - s = s.reindex(ind) - return s + try: + s = Series(A.data, MultiIndex.from_arrays((A.row, A.col))) + s = s.sort_index() + if sparse_series: + # TODO(SparseSeries): remove this and the sparse_series keyword. + # This is just here to avoid a DeprecationWarning when + # _coo_to_sparse_series is called via Series.sparse.from_coo + s = s.to_sparse() # TODO: specify kind? + else: + s = s.astype(SparseDtype(s.dtype)) + if dense_index: + # is there a better constructor method to use here? + i = range(A.shape[0]) + j = range(A.shape[1]) + ind = MultiIndex.from_product([i, j]) + s = s.reindex(ind) + return s + except AttributeError: + raise TypeError('Expected coo_matrix. Got {} instead.'.format(type(A).__name__)) + diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index f8a09ae8eb56a..659f2b97485a9 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -1128,13 +1128,6 @@ def test_from_coo(self): expected = pd.Series([4, 9, 7, 5], index=index, dtype='Sparse[int]') tm.assert_series_equal(result, expected) - @td.skip_if_no_scipy - def test_from_coo_invalid_input(self): - import scipy.sparse - m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) - with pytest.raises(AttributeError): - pd.Series.sparse.from_coo(m) - @td.skip_if_no_scipy def test_to_coo(self): import scipy.sparse From ceab97dbb3c15bd3e517484446ca517631c63dd1 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Fri, 31 May 2019 17:27:18 -0500 Subject: [PATCH 04/12] Fix pep8 --- pandas/core/arrays/sparse.py | 2 +- pandas/core/sparse/scipy_sparse.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index 4950acfa9f0cc..ecc06db2bd07b 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -2015,7 +2015,7 @@ def from_coo(cls, A, dense_index=False): from pandas import Series result = _coo_to_sparse_series(A, dense_index=dense_index, - sparse_series=False) + sparse_series=False) result = Series(result.array, index=result.index, copy=False) return result diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index d2ea1deb657c4..e2c4152557635 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -152,5 +152,5 @@ def _coo_to_sparse_series(A, dense_index: bool = False, s = s.reindex(ind) return s except AttributeError: - raise TypeError('Expected coo_matrix. Got {} instead.'.format(type(A).__name__)) - + raise TypeError('Expected coo_matrix. Got {} instead.' + .format(type(A).__name__)) From 69ea6f2ffe3f2f406b67e92272ed1632d19fce6b Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Fri, 31 May 2019 18:02:59 -0500 Subject: [PATCH 05/12] Change test to expect TypeError --- pandas/tests/arrays/sparse/test_accessor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index d2cc605f05019..e1caced8eca7e 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -124,5 +124,5 @@ def test_series_from_coo(self, dtype, dense_index): def test_series_from_coo_incorrect_format(self): import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) - with pytest.raises(AttributeError): + with pytest.raises(TypeError): pd.Series.sparse.from_coo(m) From 21ecdab0e307c0609c84e339598bc8d70e55eb14 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Fri, 31 May 2019 22:05:18 -0500 Subject: [PATCH 06/12] Update what's new --- 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 6bcf061356680..e3cb08c2557ca 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) -- Introduce a more specific error message in :meth:`_coo_to_sparse_series` so user knows when they provide the incorrect matrix format to `from_coo` (:issue:`26554`) +- Introduce a more specific error message in :meth:`_coo_to_sparse_series` so it returns a TypeError for inputs that are not coo matrices (:issue:`26554`) Other ^^^^^ From d8405fc3d9d0165bf7dff49f9d555c4ad6b1dbba Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Fri, 31 May 2019 22:20:24 -0500 Subject: [PATCH 07/12] Update docstring to reflect what will be returned in an error state --- pandas/core/sparse/scipy_sparse.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index e2c4152557635..578d9ee4960be 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -130,6 +130,7 @@ def _coo_to_sparse_series(A, dense_index: bool = False, Returns ------- Series or SparseSeries on success + TypeError if A is not a coo_matrix """ from pandas import SparseDtype From b2b923977c39ac7252edcc4a5b574e594efee594 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Sat, 1 Jun 2019 09:33:14 -0500 Subject: [PATCH 08/12] - Update what's new - Simplify scope of except Block - comment on non-regression test --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/sparse/scipy_sparse.py | 36 ++++++++++++--------- pandas/tests/arrays/sparse/test_accessor.py | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index e3cb08c2557ca..739f9d36243d7 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) -- Introduce a more specific error message in :meth:`_coo_to_sparse_series` so it returns a TypeError for inputs that are not coo matrices (:issue:`26554`) +- Introduce a better error message in :meth:`Series.sparse.from_coo` so it returns a TypeError for inputs that are not coo matrices (:issue:`26554`) Other ^^^^^ diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index 578d9ee4960be..2e40e8e728370 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -129,7 +129,10 @@ def _coo_to_sparse_series(A, dense_index: bool = False, Returns ------- - Series or SparseSeries on success + Series or SparseSeries + + Raises + ------- TypeError if A is not a coo_matrix """ @@ -137,21 +140,22 @@ def _coo_to_sparse_series(A, dense_index: bool = False, try: s = Series(A.data, MultiIndex.from_arrays((A.row, A.col))) - s = s.sort_index() - if sparse_series: - # TODO(SparseSeries): remove this and the sparse_series keyword. - # This is just here to avoid a DeprecationWarning when - # _coo_to_sparse_series is called via Series.sparse.from_coo - s = s.to_sparse() # TODO: specify kind? - else: - s = s.astype(SparseDtype(s.dtype)) - if dense_index: - # is there a better constructor method to use here? - i = range(A.shape[0]) - j = range(A.shape[1]) - ind = MultiIndex.from_product([i, j]) - s = s.reindex(ind) - return s except AttributeError: raise TypeError('Expected coo_matrix. Got {} instead.' .format(type(A).__name__)) + s = s.sort_index() + if sparse_series: + # TODO(SparseSeries): remove this and the sparse_series keyword. + # This is just here to avoid a DeprecationWarning when + # _coo_to_sparse_series is called via Series.sparse.from_coo + s = s.to_sparse() # TODO: specify kind? + else: + s = s.astype(SparseDtype(s.dtype)) + if dense_index: + # is there a better constructor method to use here? + i = range(A.shape[0]) + j = range(A.shape[1]) + ind = MultiIndex.from_product([i, j]) + s = s.reindex(ind) + return s + diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index e1caced8eca7e..ac38b8694003f 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -121,6 +121,7 @@ def test_series_from_coo(self, dtype, dense_index): tm.assert_series_equal(result, expected) @td.skip_if_no_scipy + # non-regression test for fix to issue #26554 def test_series_from_coo_incorrect_format(self): import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) From fb6e0d9641a61979ce226adbdbca90384bf5998f Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Sat, 1 Jun 2019 12:37:58 -0500 Subject: [PATCH 09/12] - Clean up what's new formatting - Move comment inside test - Update docstring delineator bar --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/core/sparse/scipy_sparse.py | 3 +-- pandas/tests/arrays/sparse/test_accessor.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 739f9d36243d7..ee77326cad00b 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) -- Introduce a better error message in :meth:`Series.sparse.from_coo` so it returns a TypeError for inputs that are not coo matrices (:issue:`26554`) +- Introduce a better error message in :meth:`Series.sparse.from_coo` so it returns a `TypeError` for inputs that are not coo matrices (:issue:`26554`) Other ^^^^^ diff --git a/pandas/core/sparse/scipy_sparse.py b/pandas/core/sparse/scipy_sparse.py index 2e40e8e728370..0dd8958e93c13 100644 --- a/pandas/core/sparse/scipy_sparse.py +++ b/pandas/core/sparse/scipy_sparse.py @@ -132,7 +132,7 @@ def _coo_to_sparse_series(A, dense_index: bool = False, Series or SparseSeries Raises - ------- + ------ TypeError if A is not a coo_matrix """ @@ -158,4 +158,3 @@ def _coo_to_sparse_series(A, dense_index: bool = False, ind = MultiIndex.from_product([i, j]) s = s.reindex(ind) return s - diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index ac38b8694003f..c94252e2febd6 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -121,8 +121,8 @@ def test_series_from_coo(self, dtype, dense_index): tm.assert_series_equal(result, expected) @td.skip_if_no_scipy - # non-regression test for fix to issue #26554 def test_series_from_coo_incorrect_format(self): + # non-regression test for fix to issue #26554 import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) with pytest.raises(TypeError): From 8739f291e3041c2acb76456db21238f297cef610 Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Sat, 1 Jun 2019 17:45:12 -0500 Subject: [PATCH 10/12] Add message assertion to test and change test name to be more verbose in functionality --- pandas/tests/arrays/sparse/test_accessor.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index c94252e2febd6..bed7ef003d843 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -121,9 +121,11 @@ def test_series_from_coo(self, dtype, dense_index): tm.assert_series_equal(result, expected) @td.skip_if_no_scipy - def test_series_from_coo_incorrect_format(self): + def test_series_from_coo_incorrect_format_raises_type_error(self): # non-regression test for fix to issue #26554 import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) - with pytest.raises(TypeError): + with pytest.raises(TypeError, + match='Expected coo_matrix. Got {} instead.'.format( + type(m).__name__)): pd.Series.sparse.from_coo(m) From 633b1ff00a33c6ca3238a0412266c7e9cbd358db Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Sat, 1 Jun 2019 18:55:34 -0500 Subject: [PATCH 11/12] Proper formatting in what's new + proper commenting for test --- doc/source/whatsnew/v0.25.0.rst | 2 +- pandas/tests/arrays/sparse/test_accessor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index ee77326cad00b..95c0095ebe9db 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -590,7 +590,7 @@ Sparse - Significant speedup in :class:`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 :class:`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`) -- Introduce a better error message in :meth:`Series.sparse.from_coo` so it returns a `TypeError` for inputs that are not coo matrices (:issue:`26554`) +- Introduce a better error message in :meth:`Series.sparse.from_coo` so it returns a ``TypeError`` for inputs that are not coo matrices (:issue:`26554`) Other ^^^^^ diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index bed7ef003d843..7f7ac8c6239c0 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -122,7 +122,7 @@ def test_series_from_coo(self, dtype, dense_index): @td.skip_if_no_scipy def test_series_from_coo_incorrect_format_raises_type_error(self): - # non-regression test for fix to issue #26554 + # gh-26554 import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) with pytest.raises(TypeError, From 206faffe47355df1d96263393af06ad67e5b1dbb Mon Sep 17 00:00:00 2001 From: Frank Hoang Date: Sat, 1 Jun 2019 19:49:38 -0500 Subject: [PATCH 12/12] Fix test name for consistency and assert on literal message --- pandas/tests/arrays/sparse/test_accessor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_accessor.py b/pandas/tests/arrays/sparse/test_accessor.py index 7f7ac8c6239c0..d0a188a8aff3c 100644 --- a/pandas/tests/arrays/sparse/test_accessor.py +++ b/pandas/tests/arrays/sparse/test_accessor.py @@ -121,11 +121,11 @@ def test_series_from_coo(self, dtype, dense_index): tm.assert_series_equal(result, expected) @td.skip_if_no_scipy - def test_series_from_coo_incorrect_format_raises_type_error(self): + def test_series_from_coo_incorrect_format_raises(self): # gh-26554 import scipy.sparse m = scipy.sparse.csr_matrix(np.array([[0, 1], [0, 0]])) with pytest.raises(TypeError, - match='Expected coo_matrix. Got {} instead.'.format( - type(m).__name__)): + match='Expected coo_matrix. Got csr_matrix instead.' + ): pd.Series.sparse.from_coo(m)