From a71737cef8d68339e08d6aa1b1909b17e79f3e23 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Wed, 5 Jun 2019 19:36:59 +0530 Subject: [PATCH 01/33] Deprecate Series/Dataframe.to_dense/to_sparse() --- pandas/core/frame.py | 5 +++++ pandas/core/series.py | 3 +++ pandas/core/sparse/frame.py | 15 +++++++++++++++ pandas/core/sparse/series.py | 5 ++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5957b23535350..bc632cc05370b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1887,6 +1887,8 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True, def to_sparse(self, fill_value=None, kind='block'): """ + ..deprecated:: 0.25.0 + Convert to SparseDataFrame. Implement the sparse version of the DataFrame meaning that any data @@ -1939,6 +1941,9 @@ def to_sparse(self, fill_value=None, kind='block'): >>> type(sdf) # doctest: +SKIP """ + warning_message ="""to_sparse is deprecated and will be removed in a future version""" + warnings.warn(warning_message, FutureWarning, stacklevel=2) + from pandas.core.sparse.api import SparseDataFrame return SparseDataFrame(self._series, index=self.index, columns=self.columns, default_kind=kind, diff --git a/pandas/core/series.py b/pandas/core/series.py index 8fb6ad3e3ccc5..6f5bd2565f7c8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1573,6 +1573,7 @@ def to_frame(self, name=None): def to_sparse(self, kind='block', fill_value=None): """ + ..deprecated:: 0.25.0 Convert Series to SparseSeries. Parameters @@ -1586,6 +1587,8 @@ def to_sparse(self, kind='block', fill_value=None): SparseSeries Sparse representation of the Series. """ + warning_message ="""to_sparse is deprecated and will be removed in a future version""" + warnings.warn(warning_message, FutureWarning, stacklevel=2) from pandas.core.sparse.series import SparseSeries values = SparseArray(self, kind=kind, fill_value=fill_value) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 0320da6d9a48d..ed48066dc63ce 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -277,6 +277,21 @@ def _unpickle_sparse_frame_compat(self, state): @Appender(SparseFrameAccessor.to_dense.__doc__) def to_dense(self): + """ + ..deprecated:: 0.25.0 + Use Dataframe.sparse.to_dense() instead + """ + + + warning_message ="""to_dense is deprecated and will be removed in a future version + + Use Dataframe.sparse.to_dense() instead + + >>> df = pd.DataFrame({"A": pd.SparseArray([0, 1, 0])}) + >>> df.sparse.to_dense() + """ + warnings.warn(warning_message, FutureWarning, stacklevel=2) + return SparseFrameAccessor(self).to_dense() def _apply_columns(self, func): diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 3814d8bb66635..c8b1fb322814b 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -428,12 +428,15 @@ def _set_values(self, key, value): def to_dense(self): """ + ..deprecated:: 0.25.0 Convert SparseSeries to a Series. - Returns ------- s : Series """ + warning_message ="""to_dense is deprecated and will be removed in a future version""" + warnings.warn(warning_message, FutureWarning, stacklevel=2) + return Series(self.values.to_dense(), index=self.index, name=self.name) From fc08e93f0bcbbdaa052d8ec5417e3eb92626f5f0 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Wed, 5 Jun 2019 19:47:13 +0530 Subject: [PATCH 02/33] Update series.py --- pandas/core/sparse/series.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index c8b1fb322814b..c830a4d60bb91 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -428,6 +428,7 @@ def _set_values(self, key, value): def to_dense(self): """ + ..deprecated:: 0.25.0 Convert SparseSeries to a Series. Returns From 82c713d290d6f07900aa81249a663c9ae00ef326 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Wed, 5 Jun 2019 21:06:48 +0530 Subject: [PATCH 03/33] Beautify --- pandas/core/frame.py | 7 ++++--- pandas/core/series.py | 3 ++- pandas/core/sparse/frame.py | 11 +++++------ pandas/core/sparse/series.py | 7 ++++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bc632cc05370b..5936082e88497 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1888,7 +1888,7 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True, def to_sparse(self, fill_value=None, kind='block'): """ ..deprecated:: 0.25.0 - + Convert to SparseDataFrame. Implement the sparse version of the DataFrame meaning that any data @@ -1941,9 +1941,10 @@ def to_sparse(self, fill_value=None, kind='block'): >>> type(sdf) # doctest: +SKIP """ - warning_message ="""to_sparse is deprecated and will be removed in a future version""" + warning_message = """to_sparse is deprecated and will be + removed in a future version""" warnings.warn(warning_message, FutureWarning, stacklevel=2) - + from pandas.core.sparse.api import SparseDataFrame return SparseDataFrame(self._series, index=self.index, columns=self.columns, default_kind=kind, diff --git a/pandas/core/series.py b/pandas/core/series.py index 6f5bd2565f7c8..f339dd901fa64 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1587,7 +1587,8 @@ def to_sparse(self, kind='block', fill_value=None): SparseSeries Sparse representation of the Series. """ - warning_message ="""to_sparse is deprecated and will be removed in a future version""" + warning_message = """to_sparse is deprecated and + will be removed in a future version""" warnings.warn(warning_message, FutureWarning, stacklevel=2) from pandas.core.sparse.series import SparseSeries diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index ed48066dc63ce..b238187841f74 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -281,17 +281,16 @@ def to_dense(self): ..deprecated:: 0.25.0 Use Dataframe.sparse.to_dense() instead """ - - - warning_message ="""to_dense is deprecated and will be removed in a future version - + + warning_message = """to_dense is deprecated and will be removed in a future version + Use Dataframe.sparse.to_dense() instead - + >>> df = pd.DataFrame({"A": pd.SparseArray([0, 1, 0])}) >>> df.sparse.to_dense() """ warnings.warn(warning_message, FutureWarning, stacklevel=2) - + return SparseFrameAccessor(self).to_dense() def _apply_columns(self, func): diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index c830a4d60bb91..19819dd1ec362 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -428,16 +428,17 @@ def _set_values(self, key, value): def to_dense(self): """ - + ..deprecated:: 0.25.0 Convert SparseSeries to a Series. Returns ------- s : Series """ - warning_message ="""to_dense is deprecated and will be removed in a future version""" + warning_message = """to_dense is deprecated and will be + removed in a future version""" warnings.warn(warning_message, FutureWarning, stacklevel=2) - + return Series(self.values.to_dense(), index=self.index, name=self.name) From 39230d43f8439c63c180b9ce8bd7fe9e9eb151f3 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Wed, 5 Jun 2019 21:41:38 +0530 Subject: [PATCH 04/33] Beautify --- pandas/core/frame.py | 5 +++-- pandas/core/series.py | 6 +++--- pandas/core/sparse/frame.py | 3 ++- pandas/core/sparse/series.py | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5936082e88497..1b3b0df1f2c29 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1941,8 +1941,9 @@ def to_sparse(self, fill_value=None, kind='block'): >>> type(sdf) # doctest: +SKIP """ - warning_message = """to_sparse is deprecated and will be - removed in a future version""" + warning_message = """\ + to_sparse is deprecated and will be removed in a future version + """ warnings.warn(warning_message, FutureWarning, stacklevel=2) from pandas.core.sparse.api import SparseDataFrame diff --git a/pandas/core/series.py b/pandas/core/series.py index f339dd901fa64..6b46f1cf8c55b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1587,9 +1587,9 @@ def to_sparse(self, kind='block', fill_value=None): SparseSeries Sparse representation of the Series. """ - warning_message = """to_sparse is deprecated and - will be removed in a future version""" - warnings.warn(warning_message, FutureWarning, stacklevel=2) + + warnings.warn("to_sparse is deprecated and will be removed" + "in a future version", FutureWarning, stacklevel=2) from pandas.core.sparse.series import SparseSeries values = SparseArray(self, kind=kind, fill_value=fill_value) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index b238187841f74..9ee208197e79b 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -282,7 +282,8 @@ def to_dense(self): Use Dataframe.sparse.to_dense() instead """ - warning_message = """to_dense is deprecated and will be removed in a future version + warning_message = """\ + to_dense is deprecated and will be removed in a future version Use Dataframe.sparse.to_dense() instead diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 19819dd1ec362..3e0150ea62292 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -435,9 +435,8 @@ def to_dense(self): ------- s : Series """ - warning_message = """to_dense is deprecated and will be - removed in a future version""" - warnings.warn(warning_message, FutureWarning, stacklevel=2) + warnings.warn("to_dense is deprecated and will be removed" + "in a future version", FutureWarning, stacklevel=2) return Series(self.values.to_dense(), index=self.index, name=self.name) From 1e7c0e8b936def829e266e640c8684b592a6660b Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Fri, 7 Jun 2019 14:32:55 +0530 Subject: [PATCH 05/33] Beautify --- pandas/core/frame.py | 19 ++++++++----------- pandas/core/series.py | 10 +++++----- pandas/core/sparse/frame.py | 11 ++++++++--- pandas/core/sparse/series.py | 18 ++++++++++-------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1b3b0df1f2c29..f98dc1cc2cf24 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1887,9 +1887,8 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True, def to_sparse(self, fill_value=None, kind='block'): """ - ..deprecated:: 0.25.0 - Convert to SparseDataFrame. + .. deprecated:: 0.25.0 Implement the sparse version of the DataFrame meaning that any data matching a specific value it's omitted in the representation. @@ -1941,10 +1940,8 @@ def to_sparse(self, fill_value=None, kind='block'): >>> type(sdf) # doctest: +SKIP """ - warning_message = """\ - to_sparse is deprecated and will be removed in a future version - """ - warnings.warn(warning_message, FutureWarning, stacklevel=2) + warnings.warn("DataFrame.to_sparse is deprecated and will be removed " + "in a future version", FutureWarning, stacklevel=2) from pandas.core.sparse.api import SparseDataFrame return SparseDataFrame(self._series, index=self.index, @@ -2289,7 +2286,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, text_col 5 non-null object float_col 5 non-null float64 dtypes: float64(1), int64(1), object(1) - memory usage: 200.0+ bytes + memory usage: 248.0+ bytes Prints a summary of columns count and its dtypes but not per column information: @@ -2299,7 +2296,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, RangeIndex: 5 entries, 0 to 4 Columns: 3 entries, int_col to float_col dtypes: float64(1), int64(1), object(1) - memory usage: 200.0+ bytes + memory usage: 248.0+ bytes Pipe output of DataFrame.info to buffer instead of sys.stdout, get buffer content and writes to a text file: @@ -2501,7 +2498,7 @@ def memory_usage(self, index=True, deep=False): 4 1 1.0 1.0+0.0j 1 True >>> df.memory_usage() - Index 80 + Index 128 int64 40000 float64 40000 complex128 80000 @@ -2520,7 +2517,7 @@ def memory_usage(self, index=True, deep=False): The memory footprint of `object` dtype columns is ignored by default: >>> df.memory_usage(deep=True) - Index 80 + Index 128 int64 40000 float64 40000 complex128 80000 @@ -2532,7 +2529,7 @@ def memory_usage(self, index=True, deep=False): many repeated values. >>> df['object'].astype('category').memory_usage(deep=True) - 5168 + 5216 """ result = Series([c.memory_usage(index=False, deep=deep) for col, c in self.iteritems()], index=self.columns) diff --git a/pandas/core/series.py b/pandas/core/series.py index 6b46f1cf8c55b..1976b7f26d46c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1573,8 +1573,8 @@ def to_frame(self, name=None): def to_sparse(self, kind='block', fill_value=None): """ - ..deprecated:: 0.25.0 Convert Series to SparseSeries. + .. deprecated:: 0.25.0 Parameters ---------- @@ -1588,7 +1588,7 @@ def to_sparse(self, kind='block', fill_value=None): Sparse representation of the Series. """ - warnings.warn("to_sparse is deprecated and will be removed" + warnings.warn("Series.to_sparse is deprecated and will be removed " "in a future version", FutureWarning, stacklevel=2) from pandas.core.sparse.series import SparseSeries @@ -4014,7 +4014,7 @@ def memory_usage(self, index=True, deep=False): -------- >>> s = pd.Series(range(3)) >>> s.memory_usage() - 104 + 152 Not including the index gives the size of the rest of the data, which is necessarily smaller: @@ -4028,9 +4028,9 @@ def memory_usage(self, index=True, deep=False): >>> s.values array(['a', 'b'], dtype=object) >>> s.memory_usage() - 96 + 144 >>> s.memory_usage(deep=True) - 212 + 260 """ v = super().memory_usage(deep=deep) if index: diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 9ee208197e79b..71d58082d008b 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -242,6 +242,11 @@ def _init_spmatrix(self, data, index, columns, dtype=None, def to_coo(self): return SparseFrameAccessor(self).to_coo() + def __repr__(self): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Sparse") + return super().__repr__() + def __getstate__(self): # pickling return dict(_typ=self._typ, _subtyp=self._subtyp, _data=self._data, @@ -278,12 +283,12 @@ def _unpickle_sparse_frame_compat(self, state): @Appender(SparseFrameAccessor.to_dense.__doc__) def to_dense(self): """ - ..deprecated:: 0.25.0 - Use Dataframe.sparse.to_dense() instead + .. deprecated:: 0.25.0 + Use Dataframe.sparse.to_dense() instead """ warning_message = """\ - to_dense is deprecated and will be removed in a future version +SparseDataFrame.to_dense is deprecated and will be removed in a future version Use Dataframe.sparse.to_dense() instead diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 3e0150ea62292..c3b78f381facc 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -214,10 +214,12 @@ def as_sparse_array(self, kind=None, fill_value=None, copy=False): fill_value=fill_value, kind=kind, copy=copy) def __repr__(self): - series_rep = Series.__repr__(self) - rep = '{series}\n{index!r}'.format(series=series_rep, - index=self.sp_index) - return rep + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Sparse") + series_rep = Series.__repr__(self) + rep = '{series}\n{index!r}'.format(series=series_rep, + index=self.sp_index) + return rep def _reduce(self, op, name, axis=0, skipna=True, numeric_only=None, filter_type=None, **kwds): @@ -428,15 +430,15 @@ def _set_values(self, key, value): def to_dense(self): """ - - ..deprecated:: 0.25.0 Convert SparseSeries to a Series. + .. deprecated:: 0.25.0 Returns ------- s : Series """ - warnings.warn("to_dense is deprecated and will be removed" - "in a future version", FutureWarning, stacklevel=2) + warnings.warn("SparseSeries.to_dense is deprecated " + "and will be removed in a future version", + FutureWarning, stacklevel=2) return Series(self.values.to_dense(), index=self.index, name=self.name) From e68826c34a5d6c42bde828d8bc10b1ddeebc697f Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Fri, 7 Jun 2019 23:26:20 +0530 Subject: [PATCH 06/33] Update Deprecated SparseDF/Series tests --- pandas/tests/sparse/frame/test_frame.py | 9 +++++++++ pandas/tests/sparse/series/test_series.py | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 050526aecd2bb..0069190e45a38 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -1292,6 +1292,15 @@ def test_default_fill_value_with_no_data(self): default_fill_value=1.0) tm.assert_frame_equal(expected, result) + def test_deprecated_to_dense(self): + df = pd.DataFrame({"A": [1, np.nan, 3]}) + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = sparse_df.to_dense() + tm.assert_frame_equal(result, df) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") class TestSparseDataFrameArithmetic: diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index b8d0fab1debbd..1aef396557fcc 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1040,6 +1040,15 @@ def test_memory_usage_deep(self, deep, fill_value): assert sparse_usage < dense_usage + def test_deprecate_to_dense(self): + ser = pd.Series([1,2,3]) + sparse_ser = pd.SparseSeries([1,2,3]) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning): + result = sparse_ser.to_dense() + tm.assert_series_equal(result, ser) + @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") class TestSparseHandlingMultiIndexes: From 20b8962fc764cc8827d6fd37405fb90dd9f1306c Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 11:54:03 +0530 Subject: [PATCH 07/33] Beautify --- pandas/tests/sparse/frame/test_frame.py | 3 ++- pandas/tests/sparse/series/test_series.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 0069190e45a38..931d59c8fad8d 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -1295,13 +1295,14 @@ def test_default_fill_value_with_no_data(self): def test_deprecated_to_dense(self): df = pd.DataFrame({"A": [1, np.nan, 3]}) sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - + # Deprecated 0.25.0 with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): result = sparse_df.to_dense() tm.assert_frame_equal(result, df) + @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") class TestSparseDataFrameArithmetic: diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 1aef396557fcc..5dc28b1445922 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1041,8 +1041,8 @@ def test_memory_usage_deep(self, deep, fill_value): assert sparse_usage < dense_usage def test_deprecate_to_dense(self): - ser = pd.Series([1,2,3]) - sparse_ser = pd.SparseSeries([1,2,3]) + ser = pd.Series([1, 2, 3]) + sparse_ser = pd.SparseSeries([1, 2, 3]) # Deprecated 0.25.0 with tm.assert_produces_warning(FutureWarning): From 50d0534f8c024686e2f939718c7e7e1cb19ab441 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 11:55:33 +0530 Subject: [PATCH 08/33] Deprecate NDFrame.to_dense --- pandas/core/generic.py | 4 ++++ pandas/tests/generic/test_generic.py | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 19d093dd29457..4054adf531f33 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1963,12 +1963,16 @@ def __array_wrap__(self, result, context=None): def to_dense(self): """ Return dense representation of NDFrame (as opposed to sparse). + .. deprecated:: 0.25.0 Returns ------- %(klass)s Dense %(klass)s. """ + warnings.warn("NDFrame.to_dense is deprecated " + "and will be removed in a future version", + FutureWarning, stacklevel=2) # compat return self diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index e6d9851b1bb99..bcf6d6ba2cd86 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -918,3 +918,16 @@ def test_axis_classmethods(self, box): assert obj._get_axis_name(v) == box._get_axis_name(v) assert obj._get_block_manager_axis(v) == \ box._get_block_manager_axis(v) + + def test_deprecated_to_dense(self): + # Deprecated 0.25.0 + + df = pd.DataFrame({"A": [1, 2, 3]}) + with tm.assert_produces_warning(FutureWarning): + result = df.to_dense() + tm.assert_frame_equal(result, df) + + ser = pd.Series([1, 2, 3]) + with tm.assert_produces_warning(FutureWarning): + result = ser.to_dense() + tm.assert_series_equal(result, ser) From 933162d708432f7ae0e01af21adcecb84bc2bebe Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 15:48:52 +0530 Subject: [PATCH 09/33] Beautify --- pandas/core/frame.py | 1 + pandas/core/generic.py | 1 + pandas/core/series.py | 1 + 3 files changed, 3 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f98dc1cc2cf24..a64898655e024 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1888,6 +1888,7 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True, def to_sparse(self, fill_value=None, kind='block'): """ Convert to SparseDataFrame. + .. deprecated:: 0.25.0 Implement the sparse version of the DataFrame meaning that any data diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 4054adf531f33..1201c1dcbf46c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1963,6 +1963,7 @@ def __array_wrap__(self, result, context=None): def to_dense(self): """ Return dense representation of NDFrame (as opposed to sparse). + .. deprecated:: 0.25.0 Returns diff --git a/pandas/core/series.py b/pandas/core/series.py index 1976b7f26d46c..39de91b378bb3 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1574,6 +1574,7 @@ def to_frame(self, name=None): def to_sparse(self, kind='block', fill_value=None): """ Convert Series to SparseSeries. + .. deprecated:: 0.25.0 Parameters From dd1e6c2c230f7330a9e38961c1cb477bd570872b Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 21:27:11 +0530 Subject: [PATCH 10/33] Silence test time deprecation warnings --- .../tests/arrays/sparse/test_arithmetics.py | 1 + pandas/tests/arrays/test_integer.py | 2 ++ pandas/tests/extension/test_datetime.py | 1 + pandas/tests/extension/test_integer.py | 1 + pandas/tests/extension/test_interval.py | 1 + pandas/tests/extension/test_numpy.py | 1 + pandas/tests/extension/test_period.py | 1 + pandas/tests/frame/test_analytics.py | 1 + .../tests/groupby/aggregate/test_aggregate.py | 9 ++++++++ pandas/tests/groupby/aggregate/test_cython.py | 2 ++ pandas/tests/groupby/aggregate/test_other.py | 13 +++++++++++ pandas/tests/groupby/test_apply.py | 4 ++++ pandas/tests/groupby/test_categorical.py | 5 +++++ pandas/tests/groupby/test_filters.py | 13 +++++++++++ pandas/tests/groupby/test_function.py | 22 +++++++++++++++++++ pandas/tests/groupby/test_groupby.py | 19 ++++++++++++++++ pandas/tests/groupby/test_grouping.py | 3 +++ pandas/tests/groupby/test_nth.py | 2 ++ pandas/tests/groupby/test_timegrouper.py | 1 + pandas/tests/groupby/test_transform.py | 17 ++++++++++++++ pandas/tests/groupby/test_value_counts.py | 1 + pandas/tests/groupby/test_whitelist.py | 1 + pandas/tests/io/json/test_pandas.py | 2 ++ pandas/tests/io/test_packers.py | 2 ++ pandas/tests/io/test_pytables.py | 2 ++ .../tests/reductions/test_stat_reductions.py | 1 + pandas/tests/resample/test_datetime_index.py | 2 ++ pandas/tests/resample/test_resample_api.py | 2 ++ .../tests/resample/test_resampler_grouper.py | 6 +++++ pandas/tests/resample/test_time_grouper.py | 1 + pandas/tests/reshape/test_pivot.py | 2 ++ pandas/tests/series/test_api.py | 1 + pandas/tests/series/test_combine_concat.py | 1 + pandas/tests/series/test_missing.py | 1 + pandas/tests/sparse/frame/test_apply.py | 3 +++ pandas/tests/sparse/frame/test_frame.py | 4 ++++ pandas/tests/sparse/frame/test_to_csv.py | 2 ++ .../tests/sparse/frame/test_to_from_scipy.py | 5 +++++ pandas/tests/sparse/series/test_series.py | 6 +++++ pandas/tests/sparse/test_combine_concat.py | 1 + pandas/tests/sparse/test_format.py | 15 +++++++++++++ pandas/tests/sparse/test_groupby.py | 2 ++ pandas/tests/sparse/test_indexing.py | 4 ++++ pandas/tests/sparse/test_pivot.py | 1 + pandas/tests/test_multilevel.py | 2 ++ pandas/tests/test_window.py | 4 ++++ 46 files changed, 193 insertions(+) diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index eb3af4e6dea73..b5541352be07e 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -9,6 +9,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseArrayArithmetics: _base = np.array diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 066eadc9b68bc..b218bebaf97b6 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -659,6 +659,7 @@ def test_cross_type_arithmetic(): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op', ['sum', 'min', 'max', 'prod']) def test_preserve_dtypes(op): # TODO(#22346): preserve Int64 dtype @@ -684,6 +685,7 @@ def test_preserve_dtypes(op): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op', ['mean']) def test_reduce_to_float(op): # some reduce ops always return float, even if the result diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index baee04c3b79eb..6ca86ab44b9f9 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -232,6 +232,7 @@ class TestSetitem(BaseDatetimeTests, base.BaseSetitemTests): pass +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BaseDatetimeTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 22bb086a919ca..090f38daeba6e 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -204,6 +204,7 @@ class TestCasting(base.BaseCastingTests): pass +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index f1f90b298ffe2..f60301b3ccb0e 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -90,6 +90,7 @@ class TestGetitem(BaseInterval, base.BaseGetitemTests): pass +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGrouping(BaseInterval, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index f31fa5b87cfe5..2f9f6ec15b2be 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -181,6 +181,7 @@ def test_take_series(self, data): super().test_take_series(data) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BaseNumPyTests, base.BaseGroupbyTests): @skip_nested def test_groupby_extension_apply( diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index b988dcb211dd0..501ec15301ead 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -151,6 +151,7 @@ class TestSetitem(BasePeriodTests, base.BaseSetitemTests): pass +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BasePeriodTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 487ff7932ec5f..0197c718d99c4 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -948,6 +948,7 @@ def test_sem(self, datetime_frame): result = nanops.nansem(arr, axis=0) assert not (result < 0).any() + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @td.skip_if_no_scipy def test_kurt(self): index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]], diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 9e714a1086037..18469b9b619f6 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -21,6 +21,7 @@ def test_agg_regression1(tsframe): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_must_agg(df): grouped = df.groupby('A')['C'] @@ -31,6 +32,7 @@ def test_agg_must_agg(df): grouped.agg(lambda x: x.index[:2]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_ser_multi_key(df): # TODO(wesm): unused ser = df.C # noqa @@ -145,6 +147,7 @@ def test_aggregate_str_func(tsframe, groupbyfunc): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_aggregate_item_by_item(df): grouped = df.groupby('A') @@ -172,6 +175,7 @@ def aggfun(ser): assert len(result) == 0 +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_wrap_agg_out(three_group): grouped = three_group.groupby(['A', 'B']) @@ -210,6 +214,7 @@ def test_multiple_functions_tuples_and_non_tuples(df): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_multiple_functions_too_many_lambdas(df): grouped = df.groupby('A') funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] @@ -219,6 +224,7 @@ def test_agg_multiple_functions_too_many_lambdas(df): grouped.agg(funcs) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_more_flexible_frame_multi_function(df): grouped = df.groupby('A') @@ -287,6 +293,7 @@ def test_multi_function_flexible_mix(df): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_agg_coercing_bools(): # issue 14873 dat = pd.DataFrame( @@ -316,6 +323,7 @@ def test_order_aggregate_multiple_funcs(): tm.assert_index_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('dtype', [np.int64, np.uint64]) @pytest.mark.parametrize('how', ['first', 'last', 'min', 'max', 'mean', 'median']) @@ -329,6 +337,7 @@ def test_uint64_type_handling(dtype, how): tm.assert_frame_equal(result, expected, check_exact=True) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestNamedAggregation: def test_agg_relabel(self): diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index c2f98b11bb33e..380f804bb07ca 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -128,6 +128,7 @@ def test_cython_fail_agg(): tm.assert_series_equal(summed, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', np.median), @@ -148,6 +149,7 @@ def test__cython_agg_general(op, targop): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', lambda x: np.median(x) if len(x) > 0 else np.nan), diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index 8168cf06ffdb1..1201e85a434e4 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -19,6 +19,7 @@ from pandas.io.formats.printing import pprint_thing +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_api(): # GH 6337 # http://stackoverflow.com/questions/21706030/pandas-groupby-agg-function-column-dtype-error @@ -83,6 +84,7 @@ def test_agg_period_index(): list(grouped) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_dict_parameter_cast_result_dtypes(): # GH 12821 @@ -121,6 +123,7 @@ def test_agg_dict_parameter_cast_result_dtypes(): tm.assert_series_equal(grouped.time.count(), exp) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_cast_results_dtypes(): # similar to GH12821 # xref #11444 @@ -291,6 +294,7 @@ def test_agg_nested_dicts(): tm.assert_frame_equal(result, expected, check_like=True) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_item_by_item_raise_typeerror(): df = DataFrame(np.random.randint(10, size=(20, 10))) @@ -312,6 +316,7 @@ def test_series_agg_multikey(): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_series_agg_multi_pure_python(): data = DataFrame( {'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar', @@ -333,6 +338,7 @@ def bad(x): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_consistency(): # agg with ([]) and () not consistent # GH 6715 @@ -356,6 +362,7 @@ def P1(a): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_callables(): # GH 7929 df = DataFrame({'foo': [1, 2], 'bar': [3, 4]}).astype(np.int64) @@ -396,6 +403,7 @@ def test_agg_over_numpy_arrays(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_timezone_round_trip(): # GH 15426 ts = pd.Timestamp("2016-01-01 12:00:00", tz='US/Pacific') @@ -427,6 +435,7 @@ def test_agg_timezone_round_trip(): assert ts == grouped.apply(lambda x: x.iloc[-1])[0] +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_sum_uint64_overflow(): # see gh-14758 # Convert to uint64 and don't overflow @@ -447,6 +456,7 @@ def test_sum_uint64_overflow(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.DataFrame({'C': {(1, 1): (1, 1, 1), (3, 4): (3, 4, 4)}})), (list, pd.DataFrame({'C': {(1, 1): [1, 1, 1], (3, 4): [3, 4, 4]}})), @@ -465,6 +475,7 @@ def test_agg_structs_dataframe(structure, expected): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name='C')), (list, pd.Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name='C')), @@ -500,6 +511,7 @@ def test_agg_category_nansum(observed): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_list_like_func(): # GH 18473 df = pd.DataFrame({'A': [str(x) for x in range(3)], @@ -511,6 +523,7 @@ def test_agg_list_like_func(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_lambda_with_timezone(): # GH 23683 df = pd.DataFrame({ diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 5bea749febc76..4202fe2ce4659 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -259,6 +259,7 @@ def desc3(group): assert result3.index.names == ('A', 'B', None) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_series_to_frame(): def f(piece): with np.errstate(invalid='ignore'): @@ -277,6 +278,7 @@ def f(piece): tm.assert_index_equal(result.index, ts.index) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_series_yield_constant(df): result = df.groupby(['A', 'B'])['C'].apply(len) assert result.index.names[:2] == ('A', 'B') @@ -301,6 +303,7 @@ def test_apply_frame_to_series(df): tm.assert_numpy_array_equal(result.values, expected.values) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_frame_concat_series(): def trans(group): return group.groupby('B')['C'].sum().sort_values()[:2] @@ -319,6 +322,7 @@ def trans2(group): assert result.name == 'C' +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_transform(ts): grouped = ts.groupby(lambda x: x.month) result = grouped.apply(lambda x: x * 2) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index f24fa0daa5b18..1e8f70a47a5f4 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -30,6 +30,7 @@ def f(a): return result.reindex(index).sort_index() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_use_categorical_name(df): cats = qcut(df.C, 4) @@ -43,6 +44,7 @@ def get_stats(group): assert result.index.names[0] == 'C' +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_basic(): cats = Categorical(["a", "a", "a", "b", "b", "b", "c", "c", "c"], @@ -991,6 +993,7 @@ def df_cat(df): return df_cat +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('operation, kwargs', [ ('agg', dict(dtype='category')), ('apply', dict())]) @@ -1006,6 +1009,7 @@ def test_seriesgroupby_observed_true(df_cat, operation, kwargs): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('operation', ['agg', 'apply']) @pytest.mark.parametrize('observed', [False, None]) def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): @@ -1022,6 +1026,7 @@ def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("observed, index, data", [ (True, MultiIndex.from_tuples( [('foo', 'one', 'min'), ('foo', 'one', 'max'), diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index 52c4654ae8c73..5e6b6072c85c9 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -6,6 +6,7 @@ import pandas.util.testing as tm +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_series(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) expected_odd = pd.Series([1, 3, 5, 7], index=[0, 1, 3, 6]) @@ -63,6 +64,7 @@ def test_filter_mixed_df(): grouped.filter(lambda x: x['A'].sum() > 10), expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_out_all_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -75,6 +77,7 @@ def test_filter_out_all_groups(): grouped.filter(lambda x: x['A'].sum() > 1000), df.loc[[]]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_out_no_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -103,6 +106,7 @@ def test_filter_out_all_groups_in_df(): tm.assert_frame_equal(expected, res) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_condition_raises(): def raise_if_sum_is_zero(x): if x.sum() == 0: @@ -129,6 +133,7 @@ def test_filter_with_axis_in_groupby(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_bad_shapes(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -162,6 +167,7 @@ def test_filter_bad_shapes(): g_s.filter(f) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_nan_is_false(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -175,6 +181,7 @@ def test_filter_nan_is_false(): tm.assert_series_equal(g_s.filter(f), s[[]]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_against_workaround(): np.random.seed(0) # Series of ints @@ -228,6 +235,7 @@ def test_filter_against_workaround(): tm.assert_frame_equal(new_way, old_way) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_using_len(): # BUG GH4447 df = DataFrame({'A': np.arange(8), @@ -257,6 +265,7 @@ def test_filter_using_len(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_maintains_ordering(): # Simple case: index is sequential. #4621 df = DataFrame({'pid': [1, 1, 1, 2, 2, 3, 3, 3], @@ -300,6 +309,7 @@ def test_filter_maintains_ordering(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_multiple_timestamp(): # GH 10114 df = DataFrame({'A': np.arange(5, dtype='int64'), @@ -327,6 +337,7 @@ def test_filter_multiple_timestamp(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_and_transform_with_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 1, 1, 0, 1] @@ -368,6 +379,7 @@ def test_filter_and_transform_with_non_unique_int_index(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_and_transform_with_multiple_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 0, 0, 0, 1] @@ -571,6 +583,7 @@ def test_filter_non_bool_raises(): df.groupby('a').filter(lambda g: g.c.mean()) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_dropna_with_empty_groups(): # GH 10780 data = pd.Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3)) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 3d9bfcd126377..afe03d8b3911e 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -40,6 +40,7 @@ def test_groupby_bool_aggs(agg_func, skipna, vals): tm.assert_frame_equal(result, exp_df) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_max_min_non_numeric(): # #2700 aa = DataFrame({'nn': [11, 11, 22, 22], @@ -59,6 +60,7 @@ def test_max_min_non_numeric(): assert 'ss' in result +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_intercept_builtin_sum(): s = Series([1., 2., np.nan, 3.]) grouped = s.groupby([0, 1, 2, 2]) @@ -104,6 +106,7 @@ def test_builtins_apply(keys, f): getattr(df, fname)()) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_arg_passthru(): # make sure that we are passing thru kwargs # to our agg functions @@ -222,6 +225,7 @@ def test_arg_passthru(): tm.assert_index_equal(result.columns, expected_columns) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_non_cython_api(): # GH5610 @@ -306,6 +310,7 @@ def test_cython_api2(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_cython_median(): df = DataFrame(np.random.randn(1000)) df.values[::2] = np.nan @@ -323,6 +328,7 @@ def test_cython_median(): tm.assert_frame_equal(rs, xp) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_median_empty_bins(observed): df = pd.DataFrame(np.random.randint(0, 44, 500)) @@ -402,6 +408,7 @@ def test_groupby_non_arithmetic_agg_int_like_precision(i): assert res.iloc[0].b == data["expected"] +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", {'c_int': [0, 2], 'c_float': [1, 3], 'c_date': [1, 2]}), ("idxmax", {'c_int': [1, 3], 'c_float': [0, 2], 'c_date': [0, 3]}) @@ -440,6 +447,7 @@ def test_fill_consistency(): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_cumprod(): # GH 4095 df = pd.DataFrame({'key': ['b'] * 10, 'value': 2}) @@ -459,6 +467,7 @@ def test_groupby_cumprod(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_ops_general(): ops = [('mean', np.mean), ('median', np.median), @@ -490,6 +499,7 @@ def test_ops_general(): raise +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_max_nan_bug(): raw = """,Date,app,File -04-23,2013-04-23 00:00:00,,log080001.log @@ -504,6 +514,7 @@ def test_max_nan_bug(): assert not r['File'].isna().any() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_nlargest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -522,6 +533,7 @@ def test_nlargest(): tm.assert_series_equal(gb.nlargest(3, keep='last'), e) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_nsmallest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -556,6 +568,7 @@ def test_numpy_compat(func): getattr(g, func)(foo=1) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_cummin_cummax(): # GH 15048 num_types = [np.int32, np.int64, np.float32, np.float64] @@ -654,6 +667,7 @@ def test_cummin_cummax(): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly increasing (T), strictly decreasing (F), @@ -687,6 +701,7 @@ def test_is_monotonic_increasing(in_vals, out_vals): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly decreasing (T), strictly increasing (F), # abs val decreasing (F), non-strictly increasing (T) @@ -723,6 +738,7 @@ def test_apply_describe_bug(mframe): grouped.describe() # it works! +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_series_describe_multikey(): ts = tm.makeTimeSeries() grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -741,12 +757,14 @@ def test_series_describe_single(): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_series_index_name(df): grouped = df.loc[:, ['C']].groupby(df['A']) result = grouped.agg(lambda x: x.mean()) assert result.index.name == 'A' +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_frame_describe_multikey(tsframe): grouped = tsframe.groupby([lambda x: x.year, lambda x: x.month]) result = grouped.describe() @@ -789,6 +807,7 @@ def test_frame_describe_tupleindex(): df2.groupby('key').describe() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_frame_describe_unstacked_format(): # GH 4792 prices = {pd.Timestamp('2011-01-06 10:59:05', tz=None): 24990, @@ -812,6 +831,7 @@ def test_frame_describe_unstacked_format(): # nunique # -------------------------------- +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('n', 10 ** np.arange(2, 6)) @pytest.mark.parametrize('m', [10, 100, 1000]) @pytest.mark.parametrize('sort', [False, True]) @@ -904,6 +924,7 @@ def test_nunique_with_empty_series(): tm.assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_nunique_with_timegrouper(): # GH 13453 test = pd.DataFrame({ @@ -1062,6 +1083,7 @@ def __eq__(self, other): # size # -------------------------------- +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_size(df): grouped = df.groupby(['A', 'B']) result = grouped.size() diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index b7abef9357072..32a202a14fe35 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -24,6 +24,7 @@ def test_repr(): assert result == expected +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('dtype', ['int64', 'int32', 'float64', 'float32']) def test_basic(dtype): @@ -187,6 +188,7 @@ def f(grp): assert_series_equal(result, e) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_pass_args_kwargs(ts, tsframe): def f(x, q=None, axis=0): @@ -256,6 +258,7 @@ def test_basic_regression(): grouped.mean() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('dtype', ['float64', 'float32', 'int64', 'int32', 'int16', 'int8']) def test_with_na_groups(dtype): @@ -340,6 +343,7 @@ def f3(x): df2.groupby('a').apply(f3) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_attr_wrapper(ts): grouped = ts.groupby(lambda x: x.weekday()) @@ -657,6 +661,7 @@ def test_groupby_as_index_cython(df): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_as_index_series_scalar(df): grouped = df.groupby(['A', 'B'], as_index=False) @@ -677,6 +682,7 @@ def test_groupby_as_index_corner(df, ts): df.groupby(lambda x: x.lower(), as_index=False, axis=1) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_multiple_key(df): df = tm.makeTimeDataFrame() grouped = df.groupby([lambda x: x.year, lambda x: x.month, @@ -743,6 +749,7 @@ def test_omit_nuisance_python_multiple(three_group): assert_frame_equal(agged, exp) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_empty_groups_corner(mframe): # handle empty groups df = DataFrame({'k1': np.array(['b', 'b', 'b', 'a', 'a', 'a']), @@ -770,6 +777,7 @@ def test_nonsense_func(): df.groupby(lambda x: x + 'foo') +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_wrap_aggregated_output_multindex(mframe): df = mframe.T df['baz', 'two'] = 'peekaboo' @@ -852,6 +860,7 @@ def test_groupby_level_nonmulti(): s.groupby(level=[1]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_complex(): # GH 12902 a = Series(data=np.arange(4) * (1 + 2j), index=[0, 0, 1, 1]) @@ -986,6 +995,7 @@ def test_groupby_series_with_name(df): assert 'B' in result2 +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_seriesgroupby_name_attr(df): # GH 6265 result = df.groupby('A')['C'] @@ -1057,6 +1067,7 @@ def test_groupby_mixed_type_columns(): # TODO: Ensure warning isn't emitted in the first place @pytest.mark.filterwarnings("ignore:Mean of:RuntimeWarning") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_cython_grouper_series_bug_noncontig(): arr = np.empty((100, 100)) arr.fill(np.nan) @@ -1067,6 +1078,7 @@ def test_cython_grouper_series_bug_noncontig(): assert result.isna().all() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_series_grouper_noncontig_index(): index = Index(tm.rands_array(10, 100)) @@ -1081,6 +1093,7 @@ def test_series_grouper_noncontig_index(): grouped.agg(f) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_convert_objects_leave_decimal_alone(): s = Series(range(5)) @@ -1285,6 +1298,7 @@ def test_dont_clobber_name_column(): assert_frame_equal(result, df) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_skip_group_keys(): tsf = tm.makeTimeDataFrame() @@ -1326,6 +1340,7 @@ def test_multifunc_sum_bug(): assert result['fl'].dtype == np.float64 +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_handle_dict_return_value(df): def f(group): return {'max': group.max(), 'min': group.min()} @@ -1340,6 +1355,7 @@ def g(group): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('grouper', ['A', ['A', 'B']]) def test_set_group_name(df, grouper): def f(group): @@ -1409,6 +1425,7 @@ def test_groupby_sort_multiindex_series(): assert_series_equal(result, mseries_result.sort_index()) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_reindex_inside_function(): periods = 1000 @@ -1505,6 +1522,7 @@ def test_groupby_multiindex_not_lexsorted(): tm.assert_frame_equal(expected, result) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_index_label_overlaps_location(): # checking we don't have any label/location confusion in the # the wake of GH5375 @@ -1629,6 +1647,7 @@ def test_pivot_table_values_key_error(): values='badname', aggfunc='count') +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_empty_dataframe_groupby(): # GH8093 df = DataFrame(columns=['A', 'B', 'C']) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 4c84c29ff98cb..5be57f511f15c 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -93,6 +93,7 @@ def test_getitem_numeric_column_names(self): # grouping # -------------------------------- +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGrouping: def test_grouper_index_types(self): @@ -704,6 +705,7 @@ def test_grouping_is_iterable(self, tsframe): for g in grouped.grouper.groupings[0]: pass + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_multi_iter(self): s = Series(np.arange(6)) k1 = np.array(['a', 'a', 'a', 'b', 'b', 'b']) @@ -756,6 +758,7 @@ def test_multi_iter_frame(self, three_group): for key, group in grouped: pass + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_dictify(self, df): dict(iter(df.groupby('A'))) dict(iter(df.groupby(['A', 'B']))) diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index 6a08a8d79b63e..ebf88567d9a99 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -90,6 +90,7 @@ def test_first_last_nth_dtypes(df_mixed_floats): assert f.dtype == 'int64' +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_nth(): df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) g = df.groupby('A') @@ -276,6 +277,7 @@ def test_first_last_tz(data, expected_first, expected_last): assert_frame_equal(result, expected[['id', 'time']]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('method, ts, alpha', [ ['first', Timestamp('2013-01-01', tz='US/Eastern'), 'a'], ['last', Timestamp('2013-01-02', tz='US/Eastern'), 'b'] diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index ef05e6ada4890..dc12ddb41ed63 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -16,6 +16,7 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupBy: def test_groupby_with_timegrouper(self): diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index 6ed2e178a7fc7..d5ec93389a273 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -20,6 +20,7 @@ def assert_fp_equal(a, b): assert (np.abs(a - b) < 1e-12).all() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform(): data = Series(np.arange(9) // 3, index=np.arange(9)) @@ -112,6 +113,7 @@ def test_transform_fast(): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_broadcast(tsframe, ts): grouped = ts.groupby(lambda x: x.month) result = grouped.transform(np.mean) @@ -192,6 +194,7 @@ def test_transform_dtype(): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_bug(): # GH 5712 # transforming on a datetime column @@ -202,6 +205,7 @@ def test_transform_bug(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_numeric_to_boolean(): # GH 16875 # inconsistency in transforming boolean values @@ -216,6 +220,7 @@ def test_transform_numeric_to_boolean(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_datetime_to_timedelta(): # GH 15429 # transforming a datetime to timedelta @@ -234,6 +239,7 @@ def test_transform_datetime_to_timedelta(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_datetime_to_numeric(): # GH 10972 # convert dt to float @@ -255,6 +261,7 @@ def test_transform_datetime_to_numeric(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_casting(): # 13046 data = """ @@ -282,6 +289,7 @@ def test_transform_casting(): assert is_timedelta64_dtype(result.DATETIME.dtype) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_multiple(ts): grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -310,6 +318,7 @@ def test_transform_select_columns(df): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_exclude_nuisance(df): # this also tests orderings in transform between @@ -324,6 +333,7 @@ def test_transform_exclude_nuisance(df): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_function_aliases(df): result = df.groupby('A').transform('mean') expected = df.groupby('A').transform(np.mean) @@ -345,6 +355,7 @@ def test_series_fast_transform_date(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_transform_length(): # GH 9697 df = pd.DataFrame({'col1': [1, 1, 2, 2], 'col2': [1, 2, 3, np.nan]}) @@ -374,6 +385,7 @@ def test_transform_coercion(): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_transform_with_int(): # GH 3740, make sure that we might upcast on item-by-item transform @@ -526,6 +538,7 @@ def test_cython_group_transform_algos(): tm.assert_numpy_array_equal(actual[:, 0].view('m8[ns]'), expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -577,6 +590,7 @@ def test_groupby_cum_skipna(op, skipna, input, exp): tm.assert_series_equal(expected, result) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -770,6 +784,7 @@ def test_pad_stable_sorting(fill_method): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("test_series", [True, False]) @pytest.mark.parametrize("freq", [ None, @@ -816,6 +831,7 @@ def test_any_all_np_func(func): tm.assert_series_equal(res, exp) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_transform_rename(): # https://github.com/pandas-dev/pandas/issues/23461 def demean_rename(x): @@ -850,6 +866,7 @@ def test_groupby_transform_timezone_column(func): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", ["1/1/2011"] * 2 + ["1/3/2011"] * 7 + ["1/10/2011"]), ("idxmax", ["1/2/2011"] * 2 + ["1/9/2011"] * 7 + ["1/10/2011"]) diff --git a/pandas/tests/groupby/test_value_counts.py b/pandas/tests/groupby/test_value_counts.py index 2b5f87aa59a8d..df5a22e90505d 100644 --- a/pandas/tests/groupby/test_value_counts.py +++ b/pandas/tests/groupby/test_value_counts.py @@ -50,6 +50,7 @@ def seed_df(seed_nans, n, m): @pytest.mark.slow +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("df, keys, bins, n, m", binned, ids=ids) def test_series_groupby_value_counts(df, keys, bins, n, m): diff --git a/pandas/tests/groupby/test_whitelist.py b/pandas/tests/groupby/test_whitelist.py index 2bd2f3fb00b56..94090c155688e 100644 --- a/pandas/tests/groupby/test_whitelist.py +++ b/pandas/tests/groupby/test_whitelist.py @@ -159,6 +159,7 @@ def raw_frame(): return raw_frame +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('axis', [0, 1]) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 6b4c6a398962a..a0d9a3fb31afb 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -36,6 +36,8 @@ _mixed_frame = _frame.copy() +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestPandasContainer: @pytest.fixture(scope="function", autouse=True) diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index f568d717211cc..7e6856829702a 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -551,6 +551,8 @@ def test_dataframe_duplicate_column_names(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparse(TestPackers): def _check_roundtrip(self, obj, comparator, **kwargs): diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 8b5907b920cca..461eed72e88d6 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -151,6 +151,8 @@ def teardown_method(self, method): @pytest.mark.single +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestHDFStore(Base): def test_format_kwarg_in_constructor(self): diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 223904048dd99..660ba840aa1e1 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -13,6 +13,7 @@ import pandas.util.testing as tm +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestSeriesStatReductions: # Note: the name TestSeriesStatReductions indicates these tests # were moved from a series-specific test file, _not_ that these tests are diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 5711174ef0c9f..0aa0e64d3f740 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -160,6 +160,7 @@ def test_resample_how(series, downsample_method): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize( '_index_start,_index_end,_index_name', [('1/1/2000 00:00:00', '1/1/2000 00:13:00', 'index')]) @@ -1135,6 +1136,7 @@ def test_resample_timegrouper(): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_resample_nunique(): # GH 12352 diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 7157ecccace00..dbe6c410f2938 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -217,6 +217,7 @@ def test_fillna(): r.fillna(0) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_without_aggregation(): # both resample and groupby should work w/o aggregation @@ -339,6 +340,7 @@ def test_agg(): ('r2', 'B', 'sum')]) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_misc(): # test with all three Resampler apis and TimeGrouper diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 959b6febcf1c9..77bed1bff56c2 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -1,4 +1,5 @@ from textwrap import dedent +import pytest import numpy as np @@ -61,6 +62,7 @@ def f(x): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_getitem(): g = test_frame.groupby('A') @@ -76,6 +78,7 @@ def test_getitem(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_getitem_multiple(): # GH 13174 @@ -96,6 +99,7 @@ def test_getitem_multiple(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_resample_on_api_with_getitem(): # GH 17813 df = pd.DataFrame({'id': list('aabbb'), @@ -125,6 +129,7 @@ def test_nearest(): assert_series_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_methods(): g = test_frame.groupby('A') r = g.resample('2s') @@ -187,6 +192,7 @@ def f(x): assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply_with_mutated_index(): # GH 15169 index = pd.date_range('1-1-2015', '12-31-15', freq='D') diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index 3f767f8e7100f..856e692239b54 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -15,6 +15,7 @@ index=date_range('1/1/2000', periods=1000)) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_apply(): grouper = Grouper(freq='A', label='right', closed='right') diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index cc91bef525eff..62b2c5f8a93b2 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -19,6 +19,7 @@ def dropna(request): return request.param +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestPivotTable: def setup_method(self, method): @@ -1358,6 +1359,7 @@ def test_pivot_table_aggfunc_scalar_dropna(self, dropna): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestCrosstab: def setup_method(self, method): diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 9b4f1f5fd0fe5..760aebb772f5f 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -209,6 +209,7 @@ def test_sparse_accessor_updates_on_inplace(self): assert s.sparse.density == 1.0 +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSeriesMisc(TestData, SharedWithSparse): series_klass = Series diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index f11595febf6ed..01502eacd3ad8 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -10,6 +10,7 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSeriesCombine: def test_append(self, datetime_series, string_series, object_series): diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index 77b43c1414f77..ec9b7c877b33f 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -39,6 +39,7 @@ def _simple_ts(start, end, freq='D'): return Series(np.random.randn(len(rng)), index=rng) +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSeriesMissingData: def test_remove_na_deprecation(self): diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py index afb54a9fa6264..dd4085aee24b4 100644 --- a/pandas/tests/sparse/frame/test_apply.py +++ b/pandas/tests/sparse/frame/test_apply.py @@ -38,6 +38,8 @@ def fill_frame(frame): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") def test_apply(frame): applied = frame.apply(np.sqrt) assert isinstance(applied, SparseDataFrame) @@ -72,6 +74,7 @@ def test_apply_empty(empty): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") def test_apply_nonuq(): orig = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c']) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 931d59c8fad8d..93983d403602e 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -25,6 +25,8 @@ def test_deprecated(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseDataFrame(SharedWithSparse): klass = SparseDataFrame @@ -1304,6 +1306,7 @@ def test_deprecated_to_dense(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameArithmetic: def test_numeric_op_scalar(self): @@ -1334,6 +1337,7 @@ def test_comparison_op_scalar(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameAnalytics: def test_cumsum(self, float_frame): diff --git a/pandas/tests/sparse/frame/test_to_csv.py b/pandas/tests/sparse/frame/test_to_csv.py index 0dda6b5cbbdae..3fdd3e02b796f 100644 --- a/pandas/tests/sparse/frame/test_to_csv.py +++ b/pandas/tests/sparse/frame/test_to_csv.py @@ -6,6 +6,8 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameToCsv: fill_values = [np.nan, 0, None, 1] diff --git a/pandas/tests/sparse/frame/test_to_from_scipy.py b/pandas/tests/sparse/frame/test_to_from_scipy.py index 269d67976b567..749b8b6951ce8 100644 --- a/pandas/tests/sparse/frame/test_to_from_scipy.py +++ b/pandas/tests/sparse/frame/test_to_from_scipy.py @@ -20,6 +20,7 @@ @pytest.mark.parametrize('dtype', [bool, int, float, np.uint16]) @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): # GH 4343 # Make one ndarray and from it one sparse matrix, both to be used for @@ -71,6 +72,7 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:object dtype is not supp:UserWarning") @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_from_to_scipy_object(spmatrix, fill_value): # GH 4343 dtype = object @@ -120,6 +122,7 @@ def test_from_to_scipy_object(spmatrix, fill_value): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_from_scipy_correct_ordering(spmatrix): # GH 16179 arr = np.arange(1, 5).reshape(2, 2) @@ -140,6 +143,7 @@ def test_from_scipy_correct_ordering(spmatrix): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_from_scipy_fillna(spmatrix): # GH 16112 arr = np.eye(3) @@ -174,6 +178,7 @@ def test_from_scipy_fillna(spmatrix): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") def test_index_names_multiple_nones(): # https://github.com/pandas-dev/pandas/pull/24092 sparse = pytest.importorskip("scipy.sparse") diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 5dc28b1445922..7e6bc528ef736 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -61,6 +61,7 @@ def _test_data2_zero(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeries(SharedWithSparse): series_klass = SparseSeries @@ -1051,6 +1052,8 @@ def test_deprecate_to_dense(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseHandlingMultiIndexes: def setup_method(self, method): @@ -1082,6 +1085,7 @@ def test_round_trip_preserve_multiindex_names(self): "ignore:the matrix subclass:PendingDeprecationWarning" ) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeriesScipyInteraction: # Issue 8048: add SparseSeries coo methods @@ -1450,6 +1454,7 @@ def _dense_series_compare(s, f): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeriesAnalytics: def setup_method(self, method): @@ -1544,6 +1549,7 @@ def test_constructor_dict_datetime64_index(datetime_type): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") def test_to_sparse(): # https://github.com/pandas-dev/pandas/issues/22389 arr = pd.SparseArray([1, 2, None, 3]) diff --git a/pandas/tests/sparse/test_combine_concat.py b/pandas/tests/sparse/test_combine_concat.py index ed29f24ae677f..a818d5064a73a 100644 --- a/pandas/tests/sparse/test_combine_concat.py +++ b/pandas/tests/sparse/test_combine_concat.py @@ -180,6 +180,7 @@ def test_concat_sparse_dense(self, kind): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameConcat: def setup_method(self, method): diff --git a/pandas/tests/sparse/test_format.py b/pandas/tests/sparse/test_format.py index 37c2acc587cf6..eb9c114018c6e 100644 --- a/pandas/tests/sparse/test_format.py +++ b/pandas/tests/sparse/test_format.py @@ -1,3 +1,5 @@ +import warnings + import numpy as np import pytest @@ -11,6 +13,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeriesFormatting: @property @@ -108,6 +111,7 @@ def test_sparse_int(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameFormatting: def test_sparse_frame(self): @@ -133,3 +137,14 @@ def test_sparse_repr_after_set(self): repr(sdf) tm.assert_sp_frame_equal(sdf, res) + + +def test_repr_no_warning(): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", FutureWarning) + df = pd.SparseDataFrame({"A": [1, 2]}) + s = df['A'] + + with tm.assert_produces_warning(None): + repr(df) + repr(s) diff --git a/pandas/tests/sparse/test_groupby.py b/pandas/tests/sparse/test_groupby.py index 7abc1530618b8..f29d9e0b0d0ed 100644 --- a/pandas/tests/sparse/test_groupby.py +++ b/pandas/tests/sparse/test_groupby.py @@ -6,6 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseGroupBy: def setup_method(self, method): @@ -61,6 +62,7 @@ def test_aggfuncs(self): @pytest.mark.parametrize("fill_value", [0, np.nan]) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") def test_groupby_includes_fill_value(fill_value): # https://github.com/pandas-dev/pandas/issues/5078 df = pd.DataFrame({'a': [fill_value, 1, fill_value, fill_value], diff --git a/pandas/tests/sparse/test_indexing.py b/pandas/tests/sparse/test_indexing.py index 21c303fa2a064..e16e3fbdeb011 100644 --- a/pandas/tests/sparse/test_indexing.py +++ b/pandas/tests/sparse/test_indexing.py @@ -7,6 +7,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeriesIndexing: def setup_method(self, method): @@ -456,6 +457,7 @@ def tests_indexing_with_sparse(self, kind, fill): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseSeriesMultiIndexing(TestSparseSeriesIndexing): def setup_method(self, method): @@ -602,6 +604,8 @@ def test_reindex(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series:FutureWarning") class TestSparseDataFrameIndexing: def test_getitem(self): diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index 48d0719bc7f2b..c36c34317c362 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -6,6 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestPivotTable: def setup_method(self, method): diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index e8d6b3bcaa77f..22fe97fc5093d 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -674,6 +674,7 @@ def test_unstack_multiple_hierarchical(self): # it works! df.unstack(['b', 'c']) + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_groupby_transform(self): s = self.frame['A'] grouper = s.index.get_level_values(0) @@ -889,6 +890,7 @@ def test_count(self): with pytest.raises(KeyError, match=msg): frame.count(level='x') + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('skipna', [True, False]) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index bc6946cbade4c..7a430ea26306c 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -316,6 +316,7 @@ def test_preserve_metadata(self): assert s2.name == 'foo' assert s3.name == 'foo' + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") @pytest.mark.parametrize("func,window_size,expected_vals", [ ('rolling', 2, [[np.nan, np.nan, np.nan, np.nan], [15., 20., 25., 20.], @@ -418,6 +419,7 @@ def test_numpy_compat(self, method): getattr(w, method)(dtype=np.float64) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestRolling(Base): def setup_method(self, method): @@ -3293,6 +3295,7 @@ def test_rolling_min_max_numeric_types(self): assert result.dtypes[0] == np.dtype("f8") +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGrouperGrouping: def setup_method(self, method): @@ -3462,6 +3465,7 @@ def test_expanding_apply(self, raw): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestRollingTS: # rolling time-series friendly From c7f27fd2e48f83abbd5aaf30ea64319e0ab507a3 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 22:45:17 +0530 Subject: [PATCH 11/33] Beautify --- pandas/tests/resample/test_resampler_grouper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 77bed1bff56c2..3b5f8c6df2332 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -1,7 +1,7 @@ from textwrap import dedent -import pytest import numpy as np +import pytest import pandas as pd from pandas import DataFrame, Series, Timestamp From be1452007e349d7a840bbeec5401993ba98f5f80 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 22:48:19 +0530 Subject: [PATCH 12/33] Propose changes to certain tests --- pandas/tests/plotting/test_boxplot_method.py | 16 ++++++----- pandas/tests/plotting/test_groupby.py | 2 ++ pandas/tests/plotting/test_hist_method.py | 28 +++++++++++--------- pandas/tests/plotting/test_series.py | 19 ++++++------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index de1ac0c293189..221ab28d779a3 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -19,6 +19,7 @@ @td.skip_if_no_mpl +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFramePlots(TestPlotBase): @pytest.mark.slow @@ -33,18 +34,18 @@ def test_boxplot_legacy1(self): _check_plot_works(df.boxplot, column=[ 'one', 'two'], return_type='dict') # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(UserWarning): + with tm.assert_produces_warning(Warning, check_stacklevel=False): _check_plot_works(df.boxplot, column=['one', 'two'], by='indic') _check_plot_works(df.boxplot, column='one', by=['indic', 'indic2']) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(df.boxplot, by='indic') - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(df.boxplot, by=['indic', 'indic2']) _check_plot_works(plotting._core.boxplot, data=df['one'], return_type='dict') _check_plot_works(df.boxplot, notch=1, return_type='dict') - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(df.boxplot, by='indic', notch=1) @pytest.mark.slow @@ -52,7 +53,7 @@ def test_boxplot_legacy2(self): df = DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2']) df['X'] = Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) df['Y'] = Series(['A'] * 10) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(df.boxplot, by='X') # When ax is supplied and required number of axes is 1, @@ -69,7 +70,7 @@ def test_boxplot_legacy2(self): # Multiple columns with an ax argument should use same figure fig, ax = self.plt.subplots() - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = df.boxplot(column=['Col1', 'Col2'], by='X', ax=ax, return_type='axes') assert axes['Col1'].get_figure() is fig @@ -162,6 +163,7 @@ def test_fontsize(self): @td.skip_if_no_mpl +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFrameGroupByPlots(TestPlotBase): @pytest.mark.slow @@ -361,7 +363,7 @@ def test_grouped_box_multiple_axes(self): axes_num=4, layout=(2, 2)) fig, axes = self.plt.subplots(2, 3) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): returned = df.boxplot(column=['height', 'weight', 'category'], by='gender', return_type='axes', ax=axes[0]) returned = np.array(list(returned.values)) diff --git a/pandas/tests/plotting/test_groupby.py b/pandas/tests/plotting/test_groupby.py index 5a5ee75928c97..ac2d3a8656641 100644 --- a/pandas/tests/plotting/test_groupby.py +++ b/pandas/tests/plotting/test_groupby.py @@ -4,6 +4,7 @@ import numpy as np +import pytest import pandas.util._test_decorators as td @@ -13,6 +14,7 @@ @td.skip_if_no_mpl +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFrameGroupByPlots(TestPlotBase): def test_series_groupby_plotting_nominally_works(self): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index f3f6c9c7fc2d4..ccb01ec8844ab 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -16,6 +16,7 @@ @td.skip_if_no_mpl +@pytest.mark.filterwarnings('ignore::FutureWarning') class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -32,9 +33,9 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) fig, ax = self.plt.subplots(1, 1) @@ -72,37 +73,37 @@ def test_hist_layout_with_by(self): # _check_plot_works adds an `ax` kwarg to the method call # so we get a warning about an axis being cleared, even # though we don't explicing pass one, see GH #13188 - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works( df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) @@ -261,6 +262,7 @@ def test_tight_layout(self): @td.skip_if_no_mpl +@pytest.mark.filterwarnings('ignore::FutureWarning') class TestDataFrameGroupByPlots(TestPlotBase): @pytest.mark.slow @@ -343,12 +345,12 @@ def test_grouped_hist_layout(self): with pytest.raises(ValueError, match=msg): df.hist(column='height', by=df.category, layout=(-1, -1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, -1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) @@ -366,13 +368,13 @@ def test_grouped_hist_layout(self): tm.close() # GH 6769 - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works( df.hist, column='height', by='classroom', layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) # without column - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.hist, by='classroom') self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 737a69a06af5a..0fc9b3bddf597 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -21,6 +21,7 @@ @td.skip_if_no_mpl +@pytest.mark.filterwarnings('ignore::FutureWarning') class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -369,10 +370,10 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) @@ -409,37 +410,37 @@ def test_hist_layout_with_by(self): df = self.hist_df # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with tm.assert_produces_warning(UserWarning): + with pytest.warns(UserWarning): axes = _check_plot_works(df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) From b12e447cd717dd1ea301c138f7334c536e65752b Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sat, 8 Jun 2019 23:32:58 +0530 Subject: [PATCH 13/33] Propose changes to tests. IGNORE PREV COMMIT. --- .../tests/extension/decimal/test_decimal.py | 1 + pandas/tests/plotting/test_boxplot_method.py | 21 ++++++---- pandas/tests/plotting/test_hist_method.py | 39 ++++++++++++------- pandas/tests/plotting/test_series.py | 27 ++++++++----- 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index 97fae41bcc720..a1225939117f7 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -191,6 +191,7 @@ class TestCasting(BaseDecimal, base.BaseCastingTests): pass +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BaseDecimal, base.BaseGroupbyTests): pass diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 221ab28d779a3..5efe7fc2391c5 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -34,18 +34,22 @@ def test_boxplot_legacy1(self): _check_plot_works(df.boxplot, column=[ 'one', 'two'], return_type='dict') # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(Warning, check_stacklevel=False): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(df.boxplot, column=['one', 'two'], by='indic') _check_plot_works(df.boxplot, column='one', by=['indic', 'indic2']) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(df.boxplot, by='indic') - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(df.boxplot, by=['indic', 'indic2']) _check_plot_works(plotting._core.boxplot, data=df['one'], return_type='dict') _check_plot_works(df.boxplot, notch=1, return_type='dict') - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(df.boxplot, by='indic', notch=1) @pytest.mark.slow @@ -53,7 +57,8 @@ def test_boxplot_legacy2(self): df = DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2']) df['X'] = Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) df['Y'] = Series(['A'] * 10) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(df.boxplot, by='X') # When ax is supplied and required number of axes is 1, @@ -70,7 +75,8 @@ def test_boxplot_legacy2(self): # Multiple columns with an ax argument should use same figure fig, ax = self.plt.subplots() - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = df.boxplot(column=['Col1', 'Col2'], by='X', ax=ax, return_type='axes') assert axes['Col1'].get_figure() is fig @@ -363,7 +369,8 @@ def test_grouped_box_multiple_axes(self): axes_num=4, layout=(2, 2)) fig, axes = self.plt.subplots(2, 3) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): returned = df.boxplot(column=['height', 'weight', 'category'], by='gender', return_type='axes', ax=axes[0]) returned = np.array(list(returned.values)) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index ccb01ec8844ab..77b54576f605c 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -33,9 +33,11 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) fig, ax = self.plt.subplots(1, 1) @@ -73,37 +75,44 @@ def test_hist_layout_with_by(self): # _check_plot_works adds an `ax` kwarg to the method call # so we get a warning about an axis being cleared, even # though we don't explicing pass one, see GH #13188 - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works( df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works( df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works( df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works( df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) @@ -345,12 +354,14 @@ def test_grouped_hist_layout(self): with pytest.raises(ValueError, match=msg): df.hist(column='height', by=df.category, layout=(-1, -1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, -1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) @@ -368,13 +379,15 @@ def test_grouped_hist_layout(self): tm.close() # GH 6769 - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works( df.hist, column='height', by='classroom', layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) # without column - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.hist, by='classroom') self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 0fc9b3bddf597..db61c59edf7ef 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -370,10 +370,12 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) @@ -410,37 +412,44 @@ def test_hist_layout_with_by(self): df = self.hist_df # _check_plot_works adds an ax so catch warning. see GH #13188 - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with pytest.warns(UserWarning): + with tm.assert_produces_warning(Warning, + check_stacklevel=False): axes = _check_plot_works(df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) From 2d4de514654c31a73fc0b3124b9c3e45d8d2baf3 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sun, 9 Jun 2019 11:29:41 +0530 Subject: [PATCH 14/33] Silence test time deprecation warnings --- pandas/tests/groupby/aggregate/test_cython.py | 2 ++ pandas/tests/groupby/test_filters.py | 3 +++ pandas/tests/groupby/test_function.py | 1 + pandas/tests/test_multilevel.py | 1 + 4 files changed, 7 insertions(+) diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index 380f804bb07ca..b3e6892526b01 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -102,6 +102,7 @@ def test_cython_agg_frame_columns(): df.groupby(level=0, axis='columns').mean() +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_cython_agg_return_dict(): # GH 16741 df = DataFrame( @@ -118,6 +119,7 @@ def test_cython_agg_return_dict(): tm.assert_series_equal(ts, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_cython_fail_agg(): dr = bdate_range('1/1/2000', periods=50) ts = Series(['A', 'B', 'C', 'D', 'E'] * 10, index=dr) diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index 5e6b6072c85c9..4b72c1d2df234 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -421,6 +421,7 @@ def test_filter_and_transform_with_multiple_non_unique_int_index(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_and_transform_with_non_unique_float_index(): # GH4620 index = np.array([1, 1, 1, 2, 1, 1, 0, 1], dtype=float) @@ -462,6 +463,7 @@ def test_filter_and_transform_with_non_unique_float_index(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_and_transform_with_non_unique_timestamp_index(): # GH4620 t0 = Timestamp('2013-09-30 00:05:00') @@ -506,6 +508,7 @@ def test_filter_and_transform_with_non_unique_timestamp_index(): tm.assert_series_equal(actual, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_filter_and_transform_with_non_unique_string_index(): # GH4620 index = list('bbbcbbab') diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index afe03d8b3911e..a6424c1a16936 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -749,6 +749,7 @@ def test_series_describe_multikey(): tm.assert_series_equal(result['min'], grouped.min(), check_names=False) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_series_describe_single(): ts = tm.makeTimeSeries() grouped = ts.groupby(lambda x: x.month) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 22fe97fc5093d..535523cd382c6 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -965,6 +965,7 @@ def test_frame_any_all_group(self): ex = DataFrame({'data': [False, False]}, index=['one', 'two']) tm.assert_frame_equal(result, ex) + @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_std_var_pass_ddof(self): index = MultiIndex.from_arrays([np.arange(5).repeat(10), np.tile( np.arange(10), 5)]) From eede9b8b830165f281b51dfb45aae49f9a706db2 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sun, 9 Jun 2019 14:48:47 +0530 Subject: [PATCH 15/33] Add tests for Series/DataFrame.to_sparse --- pandas/tests/frame/test_deprecations.py | 20 ++++++++++++++++++++ pandas/tests/groupby/aggregate/test_other.py | 1 + pandas/tests/series/test_deprecations.py | 20 ++++++++++++++++++++ pandas/tests/sparse/frame/test_frame.py | 18 ++++++++++-------- pandas/tests/sparse/series/test_series.py | 20 +++++++++++--------- pandas/tests/test_multilevel.py | 1 + 6 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 pandas/tests/frame/test_deprecations.py create mode 100644 pandas/tests/series/test_deprecations.py diff --git a/pandas/tests/frame/test_deprecations.py b/pandas/tests/frame/test_deprecations.py new file mode 100644 index 0000000000000..73c034416dc98 --- /dev/null +++ b/pandas/tests/frame/test_deprecations.py @@ -0,0 +1,20 @@ +import numpy as np +from numpy import nan +import pytest + +import pandas as pd +from pandas import DataFrame +from pandas.core.sparse import frame as spf +from pandas.util import testing as tm + + +@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +def test_deprecated_to_sparse(): + df = pd.DataFrame({"A": [1, np.nan, 3]}) + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = df.to_sparse() + tm.assert_frame_equal(result, sparse_df) diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index 1201e85a434e4..bedfb3839bff4 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -385,6 +385,7 @@ def __call__(self, x): tm.assert_frame_equal(result, expected) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") def test_agg_over_numpy_arrays(): # GH 3788 df = pd.DataFrame([[1, np.array([10, 20, 30])], diff --git a/pandas/tests/series/test_deprecations.py b/pandas/tests/series/test_deprecations.py new file mode 100644 index 0000000000000..6c190cff8d9d7 --- /dev/null +++ b/pandas/tests/series/test_deprecations.py @@ -0,0 +1,20 @@ +import numpy as np +from numpy import nan +import pytest + +import pandas as pd +from pandas import Series +from pandas.core.sparse import series as sps +from pandas.util import testing as tm + + +@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +def test_deprecated_to_sparse(): + ser = Series([1, np.nan, 3]) + sparse_ser = pd.SparseSeries([1, np.nan, 3]) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = ser.to_sparse() + tm.assert_series_equal(result, sparse_ser) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 93983d403602e..4538d3b459406 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -1294,15 +1294,17 @@ def test_default_fill_value_with_no_data(self): default_fill_value=1.0) tm.assert_frame_equal(expected, result) - def test_deprecated_to_dense(self): - df = pd.DataFrame({"A": [1, np.nan, 3]}) - sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = sparse_df.to_dense() - tm.assert_frame_equal(result, df) +#@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +def test_deprecated_to_dense(): + df = pd.DataFrame({"A": [1, np.nan, 3]}) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + result = sparse_df.to_dense() + tm.assert_frame_equal(result, df) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 7e6bc528ef736..5a8791b5e65f5 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1041,15 +1041,6 @@ def test_memory_usage_deep(self, deep, fill_value): assert sparse_usage < dense_usage - def test_deprecate_to_dense(self): - ser = pd.Series([1, 2, 3]) - sparse_ser = pd.SparseSeries([1, 2, 3]) - - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning): - result = sparse_ser.to_dense() - tm.assert_series_equal(result, ser) - @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @pytest.mark.filterwarnings("ignore:Series:FutureWarning") @@ -1570,3 +1561,14 @@ def test_block_deprecated(): s = SparseSeries([1]) with tm.assert_produces_warning(FutureWarning): s.block + + +@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +def test_deprecate_to_dense(): + ser = pd.Series([1, 2, 3]) + sparse_ser = pd.SparseSeries([1, 2, 3]) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning): + result = sparse_ser.to_dense() + tm.assert_series_equal(result, ser) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 535523cd382c6..fae806487968d 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -55,6 +55,7 @@ def setup_method(self, method): self.ymd.index.set_names(['year', 'month', 'day'], inplace=True) +@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestMultiLevel(Base): def test_append(self): From 0b08795915116e61dc071a5fe17837686f9e8c6c Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Sun, 9 Jun 2019 14:59:24 +0530 Subject: [PATCH 16/33] Beautify --- pandas/tests/frame/test_deprecations.py | 5 +---- pandas/tests/series/test_deprecations.py | 2 -- pandas/tests/sparse/frame/test_frame.py | 23 +++++++++++------------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pandas/tests/frame/test_deprecations.py b/pandas/tests/frame/test_deprecations.py index 73c034416dc98..03c9f0d6ed107 100644 --- a/pandas/tests/frame/test_deprecations.py +++ b/pandas/tests/frame/test_deprecations.py @@ -1,10 +1,7 @@ import numpy as np -from numpy import nan import pytest import pandas as pd -from pandas import DataFrame -from pandas.core.sparse import frame as spf from pandas.util import testing as tm @@ -16,5 +13,5 @@ def test_deprecated_to_sparse(): # Deprecated 0.25.0 with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = df.to_sparse() + result = df.to_sparse() tm.assert_frame_equal(result, sparse_df) diff --git a/pandas/tests/series/test_deprecations.py b/pandas/tests/series/test_deprecations.py index 6c190cff8d9d7..a539558166e3f 100644 --- a/pandas/tests/series/test_deprecations.py +++ b/pandas/tests/series/test_deprecations.py @@ -1,10 +1,8 @@ import numpy as np -from numpy import nan import pytest import pandas as pd from pandas import Series -from pandas.core.sparse import series as sps from pandas.util import testing as tm diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 4538d3b459406..25ecca9596bd3 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -1295,18 +1295,6 @@ def test_default_fill_value_with_no_data(self): tm.assert_frame_equal(expected, result) -#@pytest.mark.filterwarnings("ignore:Series:FutureWarning") -def test_deprecated_to_dense(): - df = pd.DataFrame({"A": [1, np.nan, 3]}) - - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - result = sparse_df.to_dense() - tm.assert_frame_equal(result, df) - - @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameArithmetic: @@ -1431,3 +1419,14 @@ def test_dropna(self, inplace, how): if inplace: result_df = input_df tm.assert_sp_frame_equal(expected, result_df) + + +def test_deprecated_to_dense(): + df = pd.DataFrame({"A": [1, np.nan, 3]}) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + result = sparse_df.to_dense() + tm.assert_frame_equal(result, df) From 5182a1f1b8417afdaeeb8062609dff5ae9b7dca6 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Wed, 12 Jun 2019 18:12:26 +0530 Subject: [PATCH 17/33] Modify test time warning silence --- .../tests/arrays/sparse/test_arithmetics.py | 2 +- pandas/tests/arrays/test_integer.py | 4 +- pandas/tests/extension/test_datetime.py | 2 +- pandas/tests/extension/test_integer.py | 2 +- pandas/tests/extension/test_interval.py | 2 +- pandas/tests/extension/test_numpy.py | 2 +- pandas/tests/extension/test_period.py | 2 +- pandas/tests/frame/test_analytics.py | 2 +- .../tests/groupby/aggregate/test_aggregate.py | 18 ++++---- pandas/tests/groupby/aggregate/test_cython.py | 8 ++-- pandas/tests/groupby/aggregate/test_other.py | 28 +++++------ pandas/tests/groupby/test_apply.py | 8 ++-- pandas/tests/groupby/test_categorical.py | 10 ++-- pandas/tests/groupby/test_filters.py | 32 ++++++------- pandas/tests/groupby/test_function.py | 46 +++++++++---------- pandas/tests/groupby/test_groupby.py | 38 +++++++-------- pandas/tests/groupby/test_grouping.py | 6 +-- pandas/tests/groupby/test_nth.py | 4 +- pandas/tests/groupby/test_timegrouper.py | 2 +- pandas/tests/groupby/test_transform.py | 34 +++++++------- pandas/tests/groupby/test_value_counts.py | 2 +- pandas/tests/groupby/test_whitelist.py | 2 +- pandas/tests/io/json/test_pandas.py | 4 +- pandas/tests/io/test_packers.py | 4 +- pandas/tests/io/test_pytables.py | 4 +- .../tests/reductions/test_stat_reductions.py | 2 +- pandas/tests/resample/test_datetime_index.py | 4 +- pandas/tests/resample/test_resample_api.py | 4 +- .../tests/resample/test_resampler_grouper.py | 10 ++-- pandas/tests/resample/test_time_grouper.py | 2 +- pandas/tests/reshape/test_pivot.py | 4 +- pandas/tests/series/test_api.py | 2 +- pandas/tests/series/test_combine_concat.py | 2 +- pandas/tests/series/test_missing.py | 2 +- pandas/tests/sparse/frame/test_apply.py | 6 +-- pandas/tests/sparse/frame/test_frame.py | 8 ++-- pandas/tests/sparse/frame/test_to_csv.py | 4 +- .../tests/sparse/frame/test_to_from_scipy.py | 10 ++-- pandas/tests/sparse/series/test_series.py | 12 ++--- pandas/tests/sparse/test_format.py | 4 +- pandas/tests/sparse/test_groupby.py | 4 +- pandas/tests/sparse/test_indexing.py | 8 ++-- pandas/tests/sparse/test_pivot.py | 2 +- pandas/tests/test_multilevel.py | 8 ++-- pandas/tests/test_window.py | 8 ++-- 45 files changed, 187 insertions(+), 187 deletions(-) diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index b5541352be07e..31a8f13571d16 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -9,7 +9,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseArrayArithmetics: _base = np.array diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index b218bebaf97b6..17f07a041843e 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -659,7 +659,7 @@ def test_cross_type_arithmetic(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', ['sum', 'min', 'max', 'prod']) def test_preserve_dtypes(op): # TODO(#22346): preserve Int64 dtype @@ -685,7 +685,7 @@ def test_preserve_dtypes(op): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', ['mean']) def test_reduce_to_float(op): # some reduce ops always return float, even if the result diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 6ca86ab44b9f9..76c8ff59bdbb9 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -232,7 +232,7 @@ class TestSetitem(BaseDatetimeTests, base.BaseSetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BaseDatetimeTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 090f38daeba6e..8ed0b0812835c 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -204,7 +204,7 @@ class TestCasting(base.BaseCastingTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index f60301b3ccb0e..c9eebae1699a4 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -90,7 +90,7 @@ class TestGetitem(BaseInterval, base.BaseGetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouping(BaseInterval, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index 2f9f6ec15b2be..c38a7acc858cc 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -181,7 +181,7 @@ def test_take_series(self, data): super().test_take_series(data) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BaseNumPyTests, base.BaseGroupbyTests): @skip_nested def test_groupby_extension_apply( diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 501ec15301ead..9762b7968391a 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -151,7 +151,7 @@ class TestSetitem(BasePeriodTests, base.BaseSetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BasePeriodTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 0197c718d99c4..53eed99b6f300 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -948,7 +948,7 @@ def test_sem(self, datetime_frame): result = nanops.nansem(arr, axis=0) assert not (result < 0).any() - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @td.skip_if_no_scipy def test_kurt(self): index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]], diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 18469b9b619f6..1f58a569652c9 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -21,7 +21,7 @@ def test_agg_regression1(tsframe): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_must_agg(df): grouped = df.groupby('A')['C'] @@ -32,7 +32,7 @@ def test_agg_must_agg(df): grouped.agg(lambda x: x.index[:2]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_ser_multi_key(df): # TODO(wesm): unused ser = df.C # noqa @@ -147,7 +147,7 @@ def test_aggregate_str_func(tsframe, groupbyfunc): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_aggregate_item_by_item(df): grouped = df.groupby('A') @@ -175,7 +175,7 @@ def aggfun(ser): assert len(result) == 0 -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_wrap_agg_out(three_group): grouped = three_group.groupby(['A', 'B']) @@ -214,7 +214,7 @@ def test_multiple_functions_tuples_and_non_tuples(df): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_multiple_functions_too_many_lambdas(df): grouped = df.groupby('A') funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] @@ -224,7 +224,7 @@ def test_agg_multiple_functions_too_many_lambdas(df): grouped.agg(funcs) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_more_flexible_frame_multi_function(df): grouped = df.groupby('A') @@ -293,7 +293,7 @@ def test_multi_function_flexible_mix(df): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_agg_coercing_bools(): # issue 14873 dat = pd.DataFrame( @@ -323,7 +323,7 @@ def test_order_aggregate_multiple_funcs(): tm.assert_index_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', [np.int64, np.uint64]) @pytest.mark.parametrize('how', ['first', 'last', 'min', 'max', 'mean', 'median']) @@ -337,7 +337,7 @@ def test_uint64_type_handling(dtype, how): tm.assert_frame_equal(result, expected, check_exact=True) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestNamedAggregation: def test_agg_relabel(self): diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index b3e6892526b01..ba0f861d8d84c 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -102,7 +102,7 @@ def test_cython_agg_frame_columns(): df.groupby(level=0, axis='columns').mean() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_agg_return_dict(): # GH 16741 df = DataFrame( @@ -119,7 +119,7 @@ def test_cython_agg_return_dict(): tm.assert_series_equal(ts, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_fail_agg(): dr = bdate_range('1/1/2000', periods=50) ts = Series(['A', 'B', 'C', 'D', 'E'] * 10, index=dr) @@ -130,7 +130,7 @@ def test_cython_fail_agg(): tm.assert_series_equal(summed, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', np.median), @@ -151,7 +151,7 @@ def test__cython_agg_general(op, targop): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', lambda x: np.median(x) if len(x) > 0 else np.nan), diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index bedfb3839bff4..773be7a02996f 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -19,7 +19,7 @@ from pandas.io.formats.printing import pprint_thing -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_api(): # GH 6337 # http://stackoverflow.com/questions/21706030/pandas-groupby-agg-function-column-dtype-error @@ -84,7 +84,7 @@ def test_agg_period_index(): list(grouped) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_dict_parameter_cast_result_dtypes(): # GH 12821 @@ -123,7 +123,7 @@ def test_agg_dict_parameter_cast_result_dtypes(): tm.assert_series_equal(grouped.time.count(), exp) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_cast_results_dtypes(): # similar to GH12821 # xref #11444 @@ -294,7 +294,7 @@ def test_agg_nested_dicts(): tm.assert_frame_equal(result, expected, check_like=True) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_item_by_item_raise_typeerror(): df = DataFrame(np.random.randint(10, size=(20, 10))) @@ -316,7 +316,7 @@ def test_series_agg_multikey(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_agg_multi_pure_python(): data = DataFrame( {'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar', @@ -338,7 +338,7 @@ def bad(x): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_consistency(): # agg with ([]) and () not consistent # GH 6715 @@ -362,7 +362,7 @@ def P1(a): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_callables(): # GH 7929 df = DataFrame({'foo': [1, 2], 'bar': [3, 4]}).astype(np.int64) @@ -385,7 +385,7 @@ def __call__(self, x): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_over_numpy_arrays(): # GH 3788 df = pd.DataFrame([[1, np.array([10, 20, 30])], @@ -404,7 +404,7 @@ def test_agg_over_numpy_arrays(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_timezone_round_trip(): # GH 15426 ts = pd.Timestamp("2016-01-01 12:00:00", tz='US/Pacific') @@ -436,7 +436,7 @@ def test_agg_timezone_round_trip(): assert ts == grouped.apply(lambda x: x.iloc[-1])[0] -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_sum_uint64_overflow(): # see gh-14758 # Convert to uint64 and don't overflow @@ -457,7 +457,7 @@ def test_sum_uint64_overflow(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.DataFrame({'C': {(1, 1): (1, 1, 1), (3, 4): (3, 4, 4)}})), (list, pd.DataFrame({'C': {(1, 1): [1, 1, 1], (3, 4): [3, 4, 4]}})), @@ -476,7 +476,7 @@ def test_agg_structs_dataframe(structure, expected): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name='C')), (list, pd.Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name='C')), @@ -512,7 +512,7 @@ def test_agg_category_nansum(observed): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_list_like_func(): # GH 18473 df = pd.DataFrame({'A': [str(x) for x in range(3)], @@ -524,7 +524,7 @@ def test_agg_list_like_func(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_lambda_with_timezone(): # GH 23683 df = pd.DataFrame({ diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 4202fe2ce4659..21798e1e62a0c 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -259,7 +259,7 @@ def desc3(group): assert result3.index.names == ('A', 'B', None) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_series_to_frame(): def f(piece): with np.errstate(invalid='ignore'): @@ -278,7 +278,7 @@ def f(piece): tm.assert_index_equal(result.index, ts.index) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_series_yield_constant(df): result = df.groupby(['A', 'B'])['C'].apply(len) assert result.index.names[:2] == ('A', 'B') @@ -303,7 +303,7 @@ def test_apply_frame_to_series(df): tm.assert_numpy_array_equal(result.values, expected.values) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_frame_concat_series(): def trans(group): return group.groupby('B')['C'].sum().sort_values()[:2] @@ -322,7 +322,7 @@ def trans2(group): assert result.name == 'C' -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_transform(ts): grouped = ts.groupby(lambda x: x.month) result = grouped.apply(lambda x: x * 2) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 1e8f70a47a5f4..798d85fcfd71b 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -30,7 +30,7 @@ def f(a): return result.reindex(index).sort_index() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_use_categorical_name(df): cats = qcut(df.C, 4) @@ -44,7 +44,7 @@ def get_stats(group): assert result.index.names[0] == 'C' -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_basic(): cats = Categorical(["a", "a", "a", "b", "b", "b", "c", "c", "c"], @@ -993,7 +993,7 @@ def df_cat(df): return df_cat -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('operation, kwargs', [ ('agg', dict(dtype='category')), ('apply', dict())]) @@ -1009,7 +1009,7 @@ def test_seriesgroupby_observed_true(df_cat, operation, kwargs): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('operation', ['agg', 'apply']) @pytest.mark.parametrize('observed', [False, None]) def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): @@ -1026,7 +1026,7 @@ def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("observed, index, data", [ (True, MultiIndex.from_tuples( [('foo', 'one', 'min'), ('foo', 'one', 'max'), diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index 4b72c1d2df234..83b275c9b9091 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -6,7 +6,7 @@ import pandas.util.testing as tm -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_series(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) expected_odd = pd.Series([1, 3, 5, 7], index=[0, 1, 3, 6]) @@ -64,7 +64,7 @@ def test_filter_mixed_df(): grouped.filter(lambda x: x['A'].sum() > 10), expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_out_all_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -77,7 +77,7 @@ def test_filter_out_all_groups(): grouped.filter(lambda x: x['A'].sum() > 1000), df.loc[[]]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_out_no_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -106,7 +106,7 @@ def test_filter_out_all_groups_in_df(): tm.assert_frame_equal(expected, res) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_condition_raises(): def raise_if_sum_is_zero(x): if x.sum() == 0: @@ -133,7 +133,7 @@ def test_filter_with_axis_in_groupby(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_bad_shapes(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -167,7 +167,7 @@ def test_filter_bad_shapes(): g_s.filter(f) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_nan_is_false(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -181,7 +181,7 @@ def test_filter_nan_is_false(): tm.assert_series_equal(g_s.filter(f), s[[]]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_against_workaround(): np.random.seed(0) # Series of ints @@ -235,7 +235,7 @@ def test_filter_against_workaround(): tm.assert_frame_equal(new_way, old_way) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_using_len(): # BUG GH4447 df = DataFrame({'A': np.arange(8), @@ -265,7 +265,7 @@ def test_filter_using_len(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_maintains_ordering(): # Simple case: index is sequential. #4621 df = DataFrame({'pid': [1, 1, 1, 2, 2, 3, 3, 3], @@ -309,7 +309,7 @@ def test_filter_maintains_ordering(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_multiple_timestamp(): # GH 10114 df = DataFrame({'A': np.arange(5, dtype='int64'), @@ -337,7 +337,7 @@ def test_filter_multiple_timestamp(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 1, 1, 0, 1] @@ -379,7 +379,7 @@ def test_filter_and_transform_with_non_unique_int_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_multiple_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 0, 0, 0, 1] @@ -421,7 +421,7 @@ def test_filter_and_transform_with_multiple_non_unique_int_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_float_index(): # GH4620 index = np.array([1, 1, 1, 2, 1, 1, 0, 1], dtype=float) @@ -463,7 +463,7 @@ def test_filter_and_transform_with_non_unique_float_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_timestamp_index(): # GH4620 t0 = Timestamp('2013-09-30 00:05:00') @@ -508,7 +508,7 @@ def test_filter_and_transform_with_non_unique_timestamp_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_string_index(): # GH4620 index = list('bbbcbbab') @@ -586,7 +586,7 @@ def test_filter_non_bool_raises(): df.groupby('a').filter(lambda g: g.c.mean()) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_dropna_with_empty_groups(): # GH 10780 data = pd.Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3)) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index a6424c1a16936..18301a809c8ab 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -40,7 +40,7 @@ def test_groupby_bool_aggs(agg_func, skipna, vals): tm.assert_frame_equal(result, exp_df) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_max_min_non_numeric(): # #2700 aa = DataFrame({'nn': [11, 11, 22, 22], @@ -60,7 +60,7 @@ def test_max_min_non_numeric(): assert 'ss' in result -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_intercept_builtin_sum(): s = Series([1., 2., np.nan, 3.]) grouped = s.groupby([0, 1, 2, 2]) @@ -106,7 +106,7 @@ def test_builtins_apply(keys, f): getattr(df, fname)()) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_arg_passthru(): # make sure that we are passing thru kwargs # to our agg functions @@ -225,7 +225,7 @@ def test_arg_passthru(): tm.assert_index_equal(result.columns, expected_columns) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_non_cython_api(): # GH5610 @@ -310,7 +310,7 @@ def test_cython_api2(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_median(): df = DataFrame(np.random.randn(1000)) df.values[::2] = np.nan @@ -328,7 +328,7 @@ def test_cython_median(): tm.assert_frame_equal(rs, xp) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_median_empty_bins(observed): df = pd.DataFrame(np.random.randint(0, 44, 500)) @@ -408,7 +408,7 @@ def test_groupby_non_arithmetic_agg_int_like_precision(i): assert res.iloc[0].b == data["expected"] -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", {'c_int': [0, 2], 'c_float': [1, 3], 'c_date': [1, 2]}), ("idxmax", {'c_int': [1, 3], 'c_float': [0, 2], 'c_date': [0, 3]}) @@ -447,7 +447,7 @@ def test_fill_consistency(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_cumprod(): # GH 4095 df = pd.DataFrame({'key': ['b'] * 10, 'value': 2}) @@ -467,7 +467,7 @@ def test_groupby_cumprod(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_ops_general(): ops = [('mean', np.mean), ('median', np.median), @@ -499,7 +499,7 @@ def test_ops_general(): raise -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_max_nan_bug(): raw = """,Date,app,File -04-23,2013-04-23 00:00:00,,log080001.log @@ -514,7 +514,7 @@ def test_max_nan_bug(): assert not r['File'].isna().any() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nlargest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -533,7 +533,7 @@ def test_nlargest(): tm.assert_series_equal(gb.nlargest(3, keep='last'), e) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nsmallest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -568,7 +568,7 @@ def test_numpy_compat(func): getattr(g, func)(foo=1) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cummin_cummax(): # GH 15048 num_types = [np.int32, np.int64, np.float32, np.float64] @@ -667,7 +667,7 @@ def test_cummin_cummax(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly increasing (T), strictly decreasing (F), @@ -701,7 +701,7 @@ def test_is_monotonic_increasing(in_vals, out_vals): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly decreasing (T), strictly increasing (F), # abs val decreasing (F), non-strictly increasing (T) @@ -738,7 +738,7 @@ def test_apply_describe_bug(mframe): grouped.describe() # it works! -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_describe_multikey(): ts = tm.makeTimeSeries() grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -749,7 +749,7 @@ def test_series_describe_multikey(): tm.assert_series_equal(result['min'], grouped.min(), check_names=False) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_describe_single(): ts = tm.makeTimeSeries() grouped = ts.groupby(lambda x: x.month) @@ -758,14 +758,14 @@ def test_series_describe_single(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_index_name(df): grouped = df.loc[:, ['C']].groupby(df['A']) result = grouped.agg(lambda x: x.mean()) assert result.index.name == 'A' -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_frame_describe_multikey(tsframe): grouped = tsframe.groupby([lambda x: x.year, lambda x: x.month]) result = grouped.describe() @@ -808,7 +808,7 @@ def test_frame_describe_tupleindex(): df2.groupby('key').describe() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_frame_describe_unstacked_format(): # GH 4792 prices = {pd.Timestamp('2011-01-06 10:59:05', tz=None): 24990, @@ -832,7 +832,7 @@ def test_frame_describe_unstacked_format(): # nunique # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('n', 10 ** np.arange(2, 6)) @pytest.mark.parametrize('m', [10, 100, 1000]) @pytest.mark.parametrize('sort', [False, True]) @@ -925,7 +925,7 @@ def test_nunique_with_empty_series(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nunique_with_timegrouper(): # GH 13453 test = pd.DataFrame({ @@ -1084,7 +1084,7 @@ def __eq__(self, other): # size # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_size(df): grouped = df.groupby(['A', 'B']) result = grouped.size() diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 32a202a14fe35..3043c27c43f59 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -24,7 +24,7 @@ def test_repr(): assert result == expected -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', ['int64', 'int32', 'float64', 'float32']) def test_basic(dtype): @@ -188,7 +188,7 @@ def f(grp): assert_series_equal(result, e) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_pass_args_kwargs(ts, tsframe): def f(x, q=None, axis=0): @@ -258,7 +258,7 @@ def test_basic_regression(): grouped.mean() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', ['float64', 'float32', 'int64', 'int32', 'int16', 'int8']) def test_with_na_groups(dtype): @@ -343,7 +343,7 @@ def f3(x): df2.groupby('a').apply(f3) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_attr_wrapper(ts): grouped = ts.groupby(lambda x: x.weekday()) @@ -661,7 +661,7 @@ def test_groupby_as_index_cython(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_as_index_series_scalar(df): grouped = df.groupby(['A', 'B'], as_index=False) @@ -682,7 +682,7 @@ def test_groupby_as_index_corner(df, ts): df.groupby(lambda x: x.lower(), as_index=False, axis=1) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_multiple_key(df): df = tm.makeTimeDataFrame() grouped = df.groupby([lambda x: x.year, lambda x: x.month, @@ -749,7 +749,7 @@ def test_omit_nuisance_python_multiple(three_group): assert_frame_equal(agged, exp) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_empty_groups_corner(mframe): # handle empty groups df = DataFrame({'k1': np.array(['b', 'b', 'b', 'a', 'a', 'a']), @@ -777,7 +777,7 @@ def test_nonsense_func(): df.groupby(lambda x: x + 'foo') -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_wrap_aggregated_output_multindex(mframe): df = mframe.T df['baz', 'two'] = 'peekaboo' @@ -860,7 +860,7 @@ def test_groupby_level_nonmulti(): s.groupby(level=[1]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_complex(): # GH 12902 a = Series(data=np.arange(4) * (1 + 2j), index=[0, 0, 1, 1]) @@ -995,7 +995,7 @@ def test_groupby_series_with_name(df): assert 'B' in result2 -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_seriesgroupby_name_attr(df): # GH 6265 result = df.groupby('A')['C'] @@ -1067,7 +1067,7 @@ def test_groupby_mixed_type_columns(): # TODO: Ensure warning isn't emitted in the first place @pytest.mark.filterwarnings("ignore:Mean of:RuntimeWarning") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_grouper_series_bug_noncontig(): arr = np.empty((100, 100)) arr.fill(np.nan) @@ -1078,7 +1078,7 @@ def test_cython_grouper_series_bug_noncontig(): assert result.isna().all() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_grouper_noncontig_index(): index = Index(tm.rands_array(10, 100)) @@ -1093,7 +1093,7 @@ def test_series_grouper_noncontig_index(): grouped.agg(f) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_convert_objects_leave_decimal_alone(): s = Series(range(5)) @@ -1298,7 +1298,7 @@ def test_dont_clobber_name_column(): assert_frame_equal(result, df) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_skip_group_keys(): tsf = tm.makeTimeDataFrame() @@ -1340,7 +1340,7 @@ def test_multifunc_sum_bug(): assert result['fl'].dtype == np.float64 -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_handle_dict_return_value(df): def f(group): return {'max': group.max(), 'min': group.min()} @@ -1355,7 +1355,7 @@ def g(group): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('grouper', ['A', ['A', 'B']]) def test_set_group_name(df, grouper): def f(group): @@ -1425,7 +1425,7 @@ def test_groupby_sort_multiindex_series(): assert_series_equal(result, mseries_result.sort_index()) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_reindex_inside_function(): periods = 1000 @@ -1522,7 +1522,7 @@ def test_groupby_multiindex_not_lexsorted(): tm.assert_frame_equal(expected, result) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_index_label_overlaps_location(): # checking we don't have any label/location confusion in the # the wake of GH5375 @@ -1647,7 +1647,7 @@ def test_pivot_table_values_key_error(): values='badname', aggfunc='count') -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_empty_dataframe_groupby(): # GH8093 df = DataFrame(columns=['A', 'B', 'C']) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 5be57f511f15c..6b5839680da0a 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -93,7 +93,7 @@ def test_getitem_numeric_column_names(self): # grouping # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouping: def test_grouper_index_types(self): @@ -705,7 +705,7 @@ def test_grouping_is_iterable(self, tsframe): for g in grouped.grouper.groupings[0]: pass - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_multi_iter(self): s = Series(np.arange(6)) k1 = np.array(['a', 'a', 'a', 'b', 'b', 'b']) @@ -758,7 +758,7 @@ def test_multi_iter_frame(self, three_group): for key, group in grouped: pass - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_dictify(self, df): dict(iter(df.groupby('A'))) dict(iter(df.groupby(['A', 'B']))) diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index ebf88567d9a99..574f4101a13e8 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -90,7 +90,7 @@ def test_first_last_nth_dtypes(df_mixed_floats): assert f.dtype == 'int64' -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nth(): df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) g = df.groupby('A') @@ -277,7 +277,7 @@ def test_first_last_tz(data, expected_first, expected_last): assert_frame_equal(result, expected[['id', 'time']]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('method, ts, alpha', [ ['first', Timestamp('2013-01-01', tz='US/Eastern'), 'a'], ['last', Timestamp('2013-01-02', tz='US/Eastern'), 'b'] diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index dc12ddb41ed63..793160b5d34cc 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -16,7 +16,7 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupBy: def test_groupby_with_timegrouper(self): diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index d5ec93389a273..937804c223c4b 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -20,7 +20,7 @@ def assert_fp_equal(a, b): assert (np.abs(a - b) < 1e-12).all() -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform(): data = Series(np.arange(9) // 3, index=np.arange(9)) @@ -113,7 +113,7 @@ def test_transform_fast(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_broadcast(tsframe, ts): grouped = ts.groupby(lambda x: x.month) result = grouped.transform(np.mean) @@ -194,7 +194,7 @@ def test_transform_dtype(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_bug(): # GH 5712 # transforming on a datetime column @@ -205,7 +205,7 @@ def test_transform_bug(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_numeric_to_boolean(): # GH 16875 # inconsistency in transforming boolean values @@ -220,7 +220,7 @@ def test_transform_numeric_to_boolean(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_datetime_to_timedelta(): # GH 15429 # transforming a datetime to timedelta @@ -239,7 +239,7 @@ def test_transform_datetime_to_timedelta(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_datetime_to_numeric(): # GH 10972 # convert dt to float @@ -261,7 +261,7 @@ def test_transform_datetime_to_numeric(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_casting(): # 13046 data = """ @@ -289,7 +289,7 @@ def test_transform_casting(): assert is_timedelta64_dtype(result.DATETIME.dtype) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_multiple(ts): grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -318,7 +318,7 @@ def test_transform_select_columns(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_exclude_nuisance(df): # this also tests orderings in transform between @@ -333,7 +333,7 @@ def test_transform_exclude_nuisance(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_function_aliases(df): result = df.groupby('A').transform('mean') expected = df.groupby('A').transform(np.mean) @@ -355,7 +355,7 @@ def test_series_fast_transform_date(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_length(): # GH 9697 df = pd.DataFrame({'col1': [1, 1, 2, 2], 'col2': [1, 2, 3, np.nan]}) @@ -385,7 +385,7 @@ def test_transform_coercion(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform_with_int(): # GH 3740, make sure that we might upcast on item-by-item transform @@ -538,7 +538,7 @@ def test_cython_group_transform_algos(): tm.assert_numpy_array_equal(actual[:, 0].view('m8[ns]'), expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -590,7 +590,7 @@ def test_groupby_cum_skipna(op, skipna, input, exp): tm.assert_series_equal(expected, result) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -784,7 +784,7 @@ def test_pad_stable_sorting(fill_method): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("test_series", [True, False]) @pytest.mark.parametrize("freq", [ None, @@ -831,7 +831,7 @@ def test_any_all_np_func(func): tm.assert_series_equal(res, exp) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform_rename(): # https://github.com/pandas-dev/pandas/issues/23461 def demean_rename(x): @@ -866,7 +866,7 @@ def test_groupby_transform_timezone_column(func): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", ["1/1/2011"] * 2 + ["1/3/2011"] * 7 + ["1/10/2011"]), ("idxmax", ["1/2/2011"] * 2 + ["1/9/2011"] * 7 + ["1/10/2011"]) diff --git a/pandas/tests/groupby/test_value_counts.py b/pandas/tests/groupby/test_value_counts.py index df5a22e90505d..1185bb10bf50f 100644 --- a/pandas/tests/groupby/test_value_counts.py +++ b/pandas/tests/groupby/test_value_counts.py @@ -50,7 +50,7 @@ def seed_df(seed_nans, n, m): @pytest.mark.slow -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("df, keys, bins, n, m", binned, ids=ids) def test_series_groupby_value_counts(df, keys, bins, n, m): diff --git a/pandas/tests/groupby/test_whitelist.py b/pandas/tests/groupby/test_whitelist.py index 94090c155688e..825b1cc5a4493 100644 --- a/pandas/tests/groupby/test_whitelist.py +++ b/pandas/tests/groupby/test_whitelist.py @@ -159,7 +159,7 @@ def raw_frame(): return raw_frame -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('axis', [0, 1]) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index a0d9a3fb31afb..7b6029e00f432 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -36,8 +36,8 @@ _mixed_frame = _frame.copy() -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestPandasContainer: @pytest.fixture(scope="function", autouse=True) diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index 7e6856829702a..ebdba08e4449d 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -551,8 +551,8 @@ def test_dataframe_duplicate_column_names(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparse(TestPackers): def _check_roundtrip(self, obj, comparator, **kwargs): diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 461eed72e88d6..71ea303cac9a6 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -151,8 +151,8 @@ def teardown_method(self, method): @pytest.mark.single -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestHDFStore(Base): def test_format_kwarg_in_constructor(self): diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 660ba840aa1e1..46e685165bbed 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -13,7 +13,7 @@ import pandas.util.testing as tm -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestSeriesStatReductions: # Note: the name TestSeriesStatReductions indicates these tests # were moved from a series-specific test file, _not_ that these tests are diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 0aa0e64d3f740..3360cb74e3193 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -160,7 +160,7 @@ def test_resample_how(series, downsample_method): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( '_index_start,_index_end,_index_name', [('1/1/2000 00:00:00', '1/1/2000 00:13:00', 'index')]) @@ -1136,7 +1136,7 @@ def test_resample_timegrouper(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_resample_nunique(): # GH 12352 diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index dbe6c410f2938..89793c78dd04d 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -217,7 +217,7 @@ def test_fillna(): r.fillna(0) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_without_aggregation(): # both resample and groupby should work w/o aggregation @@ -340,7 +340,7 @@ def test_agg(): ('r2', 'B', 'sum')]) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_misc(): # test with all three Resampler apis and TimeGrouper diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 3b5f8c6df2332..52d033ec6e535 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -62,7 +62,7 @@ def f(x): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_getitem(): g = test_frame.groupby('A') @@ -78,7 +78,7 @@ def test_getitem(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_getitem_multiple(): # GH 13174 @@ -99,7 +99,7 @@ def test_getitem_multiple(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_resample_on_api_with_getitem(): # GH 17813 df = pd.DataFrame({'id': list('aabbb'), @@ -129,7 +129,7 @@ def test_nearest(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_methods(): g = test_frame.groupby('A') r = g.resample('2s') @@ -192,7 +192,7 @@ def f(x): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_with_mutated_index(): # GH 15169 index = pd.date_range('1-1-2015', '12-31-15', freq='D') diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index 856e692239b54..dc7cd99c36ced 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -15,7 +15,7 @@ index=date_range('1/1/2000', periods=1000)) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply(): grouper = Grouper(freq='A', label='right', closed='right') diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 62b2c5f8a93b2..92e31302947b2 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -19,7 +19,7 @@ def dropna(request): return request.param -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestPivotTable: def setup_method(self, method): @@ -1359,7 +1359,7 @@ def test_pivot_table_aggfunc_scalar_dropna(self, dropna): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestCrosstab: def setup_method(self, method): diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 760aebb772f5f..065f70d31ec78 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -209,7 +209,7 @@ def test_sparse_accessor_updates_on_inplace(self): assert s.sparse.density == 1.0 -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesMisc(TestData, SharedWithSparse): series_klass = Series diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index 01502eacd3ad8..e48645e59ddf1 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -10,7 +10,7 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesCombine: def test_append(self, datetime_series, string_series, object_series): diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index ec9b7c877b33f..e0cd55d5f9dd2 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -39,7 +39,7 @@ def _simple_ts(start, end, freq='D'): return Series(np.random.randn(len(rng)), index=rng) -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesMissingData: def test_remove_na_deprecation(self): diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py index dd4085aee24b4..cc33cf295e046 100644 --- a/pandas/tests/sparse/frame/test_apply.py +++ b/pandas/tests/sparse/frame/test_apply.py @@ -38,8 +38,8 @@ def fill_frame(frame): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_apply(frame): applied = frame.apply(np.sqrt) assert isinstance(applied, SparseDataFrame) @@ -74,7 +74,7 @@ def test_apply_empty(empty): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_apply_nonuq(): orig = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c']) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 25ecca9596bd3..6af6e6d41b335 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -25,8 +25,8 @@ def test_deprecated(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseDataFrame(SharedWithSparse): klass = SparseDataFrame @@ -1296,7 +1296,7 @@ def test_default_fill_value_with_no_data(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameArithmetic: def test_numeric_op_scalar(self): @@ -1327,7 +1327,7 @@ def test_comparison_op_scalar(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameAnalytics: def test_cumsum(self, float_frame): diff --git a/pandas/tests/sparse/frame/test_to_csv.py b/pandas/tests/sparse/frame/test_to_csv.py index 3fdd3e02b796f..84b29b1c2ddee 100644 --- a/pandas/tests/sparse/frame/test_to_csv.py +++ b/pandas/tests/sparse/frame/test_to_csv.py @@ -6,8 +6,8 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameToCsv: fill_values = [np.nan, 0, None, 1] diff --git a/pandas/tests/sparse/frame/test_to_from_scipy.py b/pandas/tests/sparse/frame/test_to_from_scipy.py index 749b8b6951ce8..28a173d0bc8ba 100644 --- a/pandas/tests/sparse/frame/test_to_from_scipy.py +++ b/pandas/tests/sparse/frame/test_to_from_scipy.py @@ -20,7 +20,7 @@ @pytest.mark.parametrize('dtype', [bool, int, float, np.uint16]) @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): # GH 4343 # Make one ndarray and from it one sparse matrix, both to be used for @@ -72,7 +72,7 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:object dtype is not supp:UserWarning") @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_to_scipy_object(spmatrix, fill_value): # GH 4343 dtype = object @@ -122,7 +122,7 @@ def test_from_to_scipy_object(spmatrix, fill_value): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_scipy_correct_ordering(spmatrix): # GH 16179 arr = np.arange(1, 5).reshape(2, 2) @@ -143,7 +143,7 @@ def test_from_scipy_correct_ordering(spmatrix): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_scipy_fillna(spmatrix): # GH 16112 arr = np.eye(3) @@ -178,7 +178,7 @@ def test_from_scipy_fillna(spmatrix): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_index_names_multiple_nones(): # https://github.com/pandas-dev/pandas/pull/24092 sparse = pytest.importorskip("scipy.sparse") diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 5a8791b5e65f5..912965582b048 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -61,7 +61,7 @@ def _test_data2_zero(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeries(SharedWithSparse): series_klass = SparseSeries @@ -1043,8 +1043,8 @@ def test_memory_usage_deep(self, deep, fill_value): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseHandlingMultiIndexes: def setup_method(self, method): @@ -1076,7 +1076,7 @@ def test_round_trip_preserve_multiindex_names(self): "ignore:the matrix subclass:PendingDeprecationWarning" ) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesScipyInteraction: # Issue 8048: add SparseSeries coo methods @@ -1445,7 +1445,7 @@ def _dense_series_compare(s, f): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesAnalytics: def setup_method(self, method): @@ -1540,7 +1540,7 @@ def test_constructor_dict_datetime64_index(datetime_type): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_to_sparse(): # https://github.com/pandas-dev/pandas/issues/22389 arr = pd.SparseArray([1, 2, None, 3]) diff --git a/pandas/tests/sparse/test_format.py b/pandas/tests/sparse/test_format.py index eb9c114018c6e..805f77eb21c2f 100644 --- a/pandas/tests/sparse/test_format.py +++ b/pandas/tests/sparse/test_format.py @@ -13,7 +13,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesFormatting: @property @@ -111,7 +111,7 @@ def test_sparse_int(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameFormatting: def test_sparse_frame(self): diff --git a/pandas/tests/sparse/test_groupby.py b/pandas/tests/sparse/test_groupby.py index f29d9e0b0d0ed..531a4360c78a2 100644 --- a/pandas/tests/sparse/test_groupby.py +++ b/pandas/tests/sparse/test_groupby.py @@ -6,7 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseGroupBy: def setup_method(self, method): @@ -62,7 +62,7 @@ def test_aggfuncs(self): @pytest.mark.parametrize("fill_value", [0, np.nan]) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_groupby_includes_fill_value(fill_value): # https://github.com/pandas-dev/pandas/issues/5078 df = pd.DataFrame({'a': [fill_value, 1, fill_value, fill_value], diff --git a/pandas/tests/sparse/test_indexing.py b/pandas/tests/sparse/test_indexing.py index e16e3fbdeb011..c4f9d26ac556d 100644 --- a/pandas/tests/sparse/test_indexing.py +++ b/pandas/tests/sparse/test_indexing.py @@ -7,7 +7,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesIndexing: def setup_method(self, method): @@ -457,7 +457,7 @@ def tests_indexing_with_sparse(self, kind, fill): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesMultiIndexing(TestSparseSeriesIndexing): def setup_method(self, method): @@ -604,8 +604,8 @@ def test_reindex(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseDataFrameIndexing: def test_getitem(self): diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index c36c34317c362..f3965a7f4dda3 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -6,7 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestPivotTable: def setup_method(self, method): diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index fae806487968d..d64bb52cf5f83 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -55,7 +55,7 @@ def setup_method(self, method): self.ymd.index.set_names(['year', 'month', 'day'], inplace=True) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestMultiLevel(Base): def test_append(self): @@ -675,7 +675,7 @@ def test_unstack_multiple_hierarchical(self): # it works! df.unstack(['b', 'c']) - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform(self): s = self.frame['A'] grouper = s.index.get_level_values(0) @@ -891,7 +891,7 @@ def test_count(self): with pytest.raises(KeyError, match=msg): frame.count(level='x') - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('skipna', [True, False]) @@ -966,7 +966,7 @@ def test_frame_any_all_group(self): ex = DataFrame({'data': [False, False]}, index=['one', 'two']) tm.assert_frame_equal(result, ex) - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_std_var_pass_ddof(self): index = MultiIndex.from_arrays([np.arange(5).repeat(10), np.tile( np.arange(10), 5)]) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 7a430ea26306c..e4c78b3424bda 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -316,7 +316,7 @@ def test_preserve_metadata(self): assert s2.name == 'foo' assert s3.name == 'foo' - @pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") + @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func,window_size,expected_vals", [ ('rolling', 2, [[np.nan, np.nan, np.nan, np.nan], [15., 20., 25., 20.], @@ -419,7 +419,7 @@ def test_numpy_compat(self, method): getattr(w, method)(dtype=np.float64) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestRolling(Base): def setup_method(self, method): @@ -3295,7 +3295,7 @@ def test_rolling_min_max_numeric_types(self): assert result.dtypes[0] == np.dtype("f8") -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouperGrouping: def setup_method(self, method): @@ -3465,7 +3465,7 @@ def test_expanding_apply(self, raw): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") +@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestRollingTS: # rolling time-series friendly From 15909c5dc3c44b509a221fd74f94ba57bbd0b61c Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 13:39:42 +0530 Subject: [PATCH 18/33] Modify groupby ops to remove NDFrame test warnings and add wcatch for direct usages --- pandas/core/groupby/ops.py | 6 +- .../tests/arrays/sparse/test_arithmetics.py | 1 - pandas/tests/arrays/test_integer.py | 2 - pandas/tests/extension/test_datetime.py | 1 - pandas/tests/extension/test_integer.py | 1 - pandas/tests/extension/test_interval.py | 1 - pandas/tests/extension/test_numpy.py | 1 - pandas/tests/extension/test_period.py | 1 - pandas/tests/frame/test_analytics.py | 1 - .../tests/groupby/aggregate/test_aggregate.py | 9 - pandas/tests/groupby/aggregate/test_cython.py | 4 - pandas/tests/groupby/aggregate/test_other.py | 14 - pandas/tests/groupby/test_apply.py | 4 - pandas/tests/groupby/test_categorical.py | 5 - pandas/tests/groupby/test_filters.py | 16 - pandas/tests/groupby/test_function.py | 23 - pandas/tests/groupby/test_groupby.py | 19 - pandas/tests/groupby/test_grouping.py | 3 - pandas/tests/groupby/test_nth.py | 2 - pandas/tests/groupby/test_timegrouper.py | 1 - pandas/tests/groupby/test_transform.py | 17 - pandas/tests/groupby/test_value_counts.py | 1 - pandas/tests/groupby/test_whitelist.py | 1 - pandas/tests/io/json/test_pandas.py | 12 +- pandas/tests/io/test_packers.py | 32 +- pandas/tests/io/test_pytables.py | 42 +- pandas/tests/plotting/test_boxplot_method.py | 23 +- pandas/tests/plotting/test_groupby.py | 2 - pandas/tests/plotting/test_hist_method.py | 40 +- pandas/tests/plotting/test_series.py | 28 +- .../tests/reductions/test_stat_reductions.py | 1 - pandas/tests/resample/test_datetime_index.py | 2 - pandas/tests/resample/test_resample_api.py | 2 - .../tests/resample/test_resampler_grouper.py | 6 - pandas/tests/resample/test_time_grouper.py | 1 - pandas/tests/reshape/test_pivot.py | 2 - pandas/tests/series/test_api.py | 6 +- pandas/tests/series/test_combine_concat.py | 22 +- pandas/tests/series/test_missing.py | 36 +- pandas/tests/sparse/frame/test_apply.py | 20 +- pandas/tests/sparse/frame/test_frame.py | 165 +++- pandas/tests/sparse/frame/test_to_csv.py | 8 +- .../tests/sparse/frame/test_to_from_scipy.py | 11 +- pandas/tests/sparse/series/test_series.py | 295 +++--- pandas/tests/sparse/test_combine_concat.py | 230 +++-- pandas/tests/sparse/test_format.py | 24 +- pandas/tests/sparse/test_groupby.py | 40 +- pandas/tests/sparse/test_indexing.py | 843 +++++++++++++----- pandas/tests/sparse/test_pivot.py | 5 +- pandas/tests/test_multilevel.py | 4 - pandas/tests/test_window.py | 4 - 51 files changed, 1309 insertions(+), 731 deletions(-) diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index ee9d57a537340..010047a8be4ed 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -630,9 +630,9 @@ def _aggregate_series_fast(self, obj, func): group_index, _, ngroups = self.group_info # avoids object / Series creation overhead - dummy = obj._get_values(slice(None, 0)).to_dense() + dummy = obj._get_values(slice(None, 0)) indexer = get_group_index_sorter(group_index, ngroups) - obj = obj._take(indexer).to_dense() + obj = obj._take(indexer) group_index = algorithms.take_nd( group_index, indexer, allow_fill=False) grouper = reduction.SeriesGrouper(obj, func, group_index, ngroups, @@ -879,7 +879,7 @@ def apply(self, f): class SeriesSplitter(DataSplitter): def _chop(self, sdata, slice_obj): - return sdata._get_values(slice_obj).to_dense() + return sdata._get_values(slice_obj) class FrameSplitter(DataSplitter): diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index 31a8f13571d16..eb3af4e6dea73 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -9,7 +9,6 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseArrayArithmetics: _base = np.array diff --git a/pandas/tests/arrays/test_integer.py b/pandas/tests/arrays/test_integer.py index 17f07a041843e..066eadc9b68bc 100644 --- a/pandas/tests/arrays/test_integer.py +++ b/pandas/tests/arrays/test_integer.py @@ -659,7 +659,6 @@ def test_cross_type_arithmetic(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', ['sum', 'min', 'max', 'prod']) def test_preserve_dtypes(op): # TODO(#22346): preserve Int64 dtype @@ -685,7 +684,6 @@ def test_preserve_dtypes(op): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', ['mean']) def test_reduce_to_float(op): # some reduce ops always return float, even if the result diff --git a/pandas/tests/extension/test_datetime.py b/pandas/tests/extension/test_datetime.py index 76c8ff59bdbb9..baee04c3b79eb 100644 --- a/pandas/tests/extension/test_datetime.py +++ b/pandas/tests/extension/test_datetime.py @@ -232,7 +232,6 @@ class TestSetitem(BaseDatetimeTests, base.BaseSetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BaseDatetimeTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_integer.py b/pandas/tests/extension/test_integer.py index 8ed0b0812835c..22bb086a919ca 100644 --- a/pandas/tests/extension/test_integer.py +++ b/pandas/tests/extension/test_integer.py @@ -204,7 +204,6 @@ class TestCasting(base.BaseCastingTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_interval.py b/pandas/tests/extension/test_interval.py index c9eebae1699a4..f1f90b298ffe2 100644 --- a/pandas/tests/extension/test_interval.py +++ b/pandas/tests/extension/test_interval.py @@ -90,7 +90,6 @@ class TestGetitem(BaseInterval, base.BaseGetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouping(BaseInterval, base.BaseGroupbyTests): pass diff --git a/pandas/tests/extension/test_numpy.py b/pandas/tests/extension/test_numpy.py index c38a7acc858cc..f31fa5b87cfe5 100644 --- a/pandas/tests/extension/test_numpy.py +++ b/pandas/tests/extension/test_numpy.py @@ -181,7 +181,6 @@ def test_take_series(self, data): super().test_take_series(data) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BaseNumPyTests, base.BaseGroupbyTests): @skip_nested def test_groupby_extension_apply( diff --git a/pandas/tests/extension/test_period.py b/pandas/tests/extension/test_period.py index 9762b7968391a..b988dcb211dd0 100644 --- a/pandas/tests/extension/test_period.py +++ b/pandas/tests/extension/test_period.py @@ -151,7 +151,6 @@ class TestSetitem(BasePeriodTests, base.BaseSetitemTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupby(BasePeriodTests, base.BaseGroupbyTests): pass diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 53eed99b6f300..487ff7932ec5f 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -948,7 +948,6 @@ def test_sem(self, datetime_frame): result = nanops.nansem(arr, axis=0) assert not (result < 0).any() - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @td.skip_if_no_scipy def test_kurt(self): index = MultiIndex(levels=[['bar'], ['one', 'two', 'three'], [0, 1]], diff --git a/pandas/tests/groupby/aggregate/test_aggregate.py b/pandas/tests/groupby/aggregate/test_aggregate.py index 1f58a569652c9..9e714a1086037 100644 --- a/pandas/tests/groupby/aggregate/test_aggregate.py +++ b/pandas/tests/groupby/aggregate/test_aggregate.py @@ -21,7 +21,6 @@ def test_agg_regression1(tsframe): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_must_agg(df): grouped = df.groupby('A')['C'] @@ -32,7 +31,6 @@ def test_agg_must_agg(df): grouped.agg(lambda x: x.index[:2]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_ser_multi_key(df): # TODO(wesm): unused ser = df.C # noqa @@ -147,7 +145,6 @@ def test_aggregate_str_func(tsframe, groupbyfunc): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_aggregate_item_by_item(df): grouped = df.groupby('A') @@ -175,7 +172,6 @@ def aggfun(ser): assert len(result) == 0 -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_wrap_agg_out(three_group): grouped = three_group.groupby(['A', 'B']) @@ -214,7 +210,6 @@ def test_multiple_functions_tuples_and_non_tuples(df): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_multiple_functions_too_many_lambdas(df): grouped = df.groupby('A') funcs = ['mean', lambda x: x.mean(), lambda x: x.std()] @@ -224,7 +219,6 @@ def test_agg_multiple_functions_too_many_lambdas(df): grouped.agg(funcs) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_more_flexible_frame_multi_function(df): grouped = df.groupby('A') @@ -293,7 +287,6 @@ def test_multi_function_flexible_mix(df): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_agg_coercing_bools(): # issue 14873 dat = pd.DataFrame( @@ -323,7 +316,6 @@ def test_order_aggregate_multiple_funcs(): tm.assert_index_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', [np.int64, np.uint64]) @pytest.mark.parametrize('how', ['first', 'last', 'min', 'max', 'mean', 'median']) @@ -337,7 +329,6 @@ def test_uint64_type_handling(dtype, how): tm.assert_frame_equal(result, expected, check_exact=True) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestNamedAggregation: def test_agg_relabel(self): diff --git a/pandas/tests/groupby/aggregate/test_cython.py b/pandas/tests/groupby/aggregate/test_cython.py index ba0f861d8d84c..c2f98b11bb33e 100644 --- a/pandas/tests/groupby/aggregate/test_cython.py +++ b/pandas/tests/groupby/aggregate/test_cython.py @@ -102,7 +102,6 @@ def test_cython_agg_frame_columns(): df.groupby(level=0, axis='columns').mean() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_agg_return_dict(): # GH 16741 df = DataFrame( @@ -119,7 +118,6 @@ def test_cython_agg_return_dict(): tm.assert_series_equal(ts, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_fail_agg(): dr = bdate_range('1/1/2000', periods=50) ts = Series(['A', 'B', 'C', 'D', 'E'] * 10, index=dr) @@ -130,7 +128,6 @@ def test_cython_fail_agg(): tm.assert_series_equal(summed, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', np.median), @@ -151,7 +148,6 @@ def test__cython_agg_general(op, targop): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op, targop', [ ('mean', np.mean), ('median', lambda x: np.median(x) if len(x) > 0 else np.nan), diff --git a/pandas/tests/groupby/aggregate/test_other.py b/pandas/tests/groupby/aggregate/test_other.py index 773be7a02996f..8168cf06ffdb1 100644 --- a/pandas/tests/groupby/aggregate/test_other.py +++ b/pandas/tests/groupby/aggregate/test_other.py @@ -19,7 +19,6 @@ from pandas.io.formats.printing import pprint_thing -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_api(): # GH 6337 # http://stackoverflow.com/questions/21706030/pandas-groupby-agg-function-column-dtype-error @@ -84,7 +83,6 @@ def test_agg_period_index(): list(grouped) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_dict_parameter_cast_result_dtypes(): # GH 12821 @@ -123,7 +121,6 @@ def test_agg_dict_parameter_cast_result_dtypes(): tm.assert_series_equal(grouped.time.count(), exp) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_cast_results_dtypes(): # similar to GH12821 # xref #11444 @@ -294,7 +291,6 @@ def test_agg_nested_dicts(): tm.assert_frame_equal(result, expected, check_like=True) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_item_by_item_raise_typeerror(): df = DataFrame(np.random.randint(10, size=(20, 10))) @@ -316,7 +312,6 @@ def test_series_agg_multikey(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_agg_multi_pure_python(): data = DataFrame( {'A': ['foo', 'foo', 'foo', 'foo', 'bar', 'bar', 'bar', 'bar', @@ -338,7 +333,6 @@ def bad(x): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_consistency(): # agg with ([]) and () not consistent # GH 6715 @@ -362,7 +356,6 @@ def P1(a): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_callables(): # GH 7929 df = DataFrame({'foo': [1, 2], 'bar': [3, 4]}).astype(np.int64) @@ -385,7 +378,6 @@ def __call__(self, x): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_over_numpy_arrays(): # GH 3788 df = pd.DataFrame([[1, np.array([10, 20, 30])], @@ -404,7 +396,6 @@ def test_agg_over_numpy_arrays(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_timezone_round_trip(): # GH 15426 ts = pd.Timestamp("2016-01-01 12:00:00", tz='US/Pacific') @@ -436,7 +427,6 @@ def test_agg_timezone_round_trip(): assert ts == grouped.apply(lambda x: x.iloc[-1])[0] -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_sum_uint64_overflow(): # see gh-14758 # Convert to uint64 and don't overflow @@ -457,7 +447,6 @@ def test_sum_uint64_overflow(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.DataFrame({'C': {(1, 1): (1, 1, 1), (3, 4): (3, 4, 4)}})), (list, pd.DataFrame({'C': {(1, 1): [1, 1, 1], (3, 4): [3, 4, 4]}})), @@ -476,7 +465,6 @@ def test_agg_structs_dataframe(structure, expected): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("structure, expected", [ (tuple, pd.Series([(1, 1, 1), (3, 4, 4)], index=[1, 3], name='C')), (list, pd.Series([[1, 1, 1], [3, 4, 4]], index=[1, 3], name='C')), @@ -512,7 +500,6 @@ def test_agg_category_nansum(observed): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_list_like_func(): # GH 18473 df = pd.DataFrame({'A': [str(x) for x in range(3)], @@ -524,7 +511,6 @@ def test_agg_list_like_func(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_lambda_with_timezone(): # GH 23683 df = pd.DataFrame({ diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 21798e1e62a0c..5bea749febc76 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -259,7 +259,6 @@ def desc3(group): assert result3.index.names == ('A', 'B', None) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_series_to_frame(): def f(piece): with np.errstate(invalid='ignore'): @@ -278,7 +277,6 @@ def f(piece): tm.assert_index_equal(result.index, ts.index) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_series_yield_constant(df): result = df.groupby(['A', 'B'])['C'].apply(len) assert result.index.names[:2] == ('A', 'B') @@ -303,7 +301,6 @@ def test_apply_frame_to_series(df): tm.assert_numpy_array_equal(result.values, expected.values) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_frame_concat_series(): def trans(group): return group.groupby('B')['C'].sum().sort_values()[:2] @@ -322,7 +319,6 @@ def trans2(group): assert result.name == 'C' -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_transform(ts): grouped = ts.groupby(lambda x: x.month) result = grouped.apply(lambda x: x * 2) diff --git a/pandas/tests/groupby/test_categorical.py b/pandas/tests/groupby/test_categorical.py index 798d85fcfd71b..f24fa0daa5b18 100644 --- a/pandas/tests/groupby/test_categorical.py +++ b/pandas/tests/groupby/test_categorical.py @@ -30,7 +30,6 @@ def f(a): return result.reindex(index).sort_index() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_use_categorical_name(df): cats = qcut(df.C, 4) @@ -44,7 +43,6 @@ def get_stats(group): assert result.index.names[0] == 'C' -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_basic(): cats = Categorical(["a", "a", "a", "b", "b", "b", "c", "c", "c"], @@ -993,7 +991,6 @@ def df_cat(df): return df_cat -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('operation, kwargs', [ ('agg', dict(dtype='category')), ('apply', dict())]) @@ -1009,7 +1006,6 @@ def test_seriesgroupby_observed_true(df_cat, operation, kwargs): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('operation', ['agg', 'apply']) @pytest.mark.parametrize('observed', [False, None]) def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): @@ -1026,7 +1022,6 @@ def test_seriesgroupby_observed_false_or_none(df_cat, observed, operation): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("observed, index, data", [ (True, MultiIndex.from_tuples( [('foo', 'one', 'min'), ('foo', 'one', 'max'), diff --git a/pandas/tests/groupby/test_filters.py b/pandas/tests/groupby/test_filters.py index 83b275c9b9091..52c4654ae8c73 100644 --- a/pandas/tests/groupby/test_filters.py +++ b/pandas/tests/groupby/test_filters.py @@ -6,7 +6,6 @@ import pandas.util.testing as tm -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_series(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) expected_odd = pd.Series([1, 3, 5, 7], index=[0, 1, 3, 6]) @@ -64,7 +63,6 @@ def test_filter_mixed_df(): grouped.filter(lambda x: x['A'].sum() > 10), expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_out_all_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -77,7 +75,6 @@ def test_filter_out_all_groups(): grouped.filter(lambda x: x['A'].sum() > 1000), df.loc[[]]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_out_no_groups(): s = pd.Series([1, 3, 20, 5, 22, 24, 7]) grouper = s.apply(lambda x: x % 2) @@ -106,7 +103,6 @@ def test_filter_out_all_groups_in_df(): tm.assert_frame_equal(expected, res) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_condition_raises(): def raise_if_sum_is_zero(x): if x.sum() == 0: @@ -133,7 +129,6 @@ def test_filter_with_axis_in_groupby(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_bad_shapes(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -167,7 +162,6 @@ def test_filter_bad_shapes(): g_s.filter(f) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_nan_is_false(): df = DataFrame({'A': np.arange(8), 'B': list('aabbbbcc'), @@ -181,7 +175,6 @@ def test_filter_nan_is_false(): tm.assert_series_equal(g_s.filter(f), s[[]]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_against_workaround(): np.random.seed(0) # Series of ints @@ -235,7 +228,6 @@ def test_filter_against_workaround(): tm.assert_frame_equal(new_way, old_way) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_using_len(): # BUG GH4447 df = DataFrame({'A': np.arange(8), @@ -265,7 +257,6 @@ def test_filter_using_len(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_maintains_ordering(): # Simple case: index is sequential. #4621 df = DataFrame({'pid': [1, 1, 1, 2, 2, 3, 3, 3], @@ -309,7 +300,6 @@ def test_filter_maintains_ordering(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_multiple_timestamp(): # GH 10114 df = DataFrame({'A': np.arange(5, dtype='int64'), @@ -337,7 +327,6 @@ def test_filter_multiple_timestamp(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 1, 1, 0, 1] @@ -379,7 +368,6 @@ def test_filter_and_transform_with_non_unique_int_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_multiple_non_unique_int_index(): # GH4620 index = [1, 1, 1, 2, 0, 0, 0, 1] @@ -421,7 +409,6 @@ def test_filter_and_transform_with_multiple_non_unique_int_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_float_index(): # GH4620 index = np.array([1, 1, 1, 2, 1, 1, 0, 1], dtype=float) @@ -463,7 +450,6 @@ def test_filter_and_transform_with_non_unique_float_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_timestamp_index(): # GH4620 t0 = Timestamp('2013-09-30 00:05:00') @@ -508,7 +494,6 @@ def test_filter_and_transform_with_non_unique_timestamp_index(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_and_transform_with_non_unique_string_index(): # GH4620 index = list('bbbcbbab') @@ -586,7 +571,6 @@ def test_filter_non_bool_raises(): df.groupby('a').filter(lambda g: g.c.mean()) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_filter_dropna_with_empty_groups(): # GH 10780 data = pd.Series(np.random.rand(9), index=np.repeat([1, 2, 3], 3)) diff --git a/pandas/tests/groupby/test_function.py b/pandas/tests/groupby/test_function.py index 18301a809c8ab..3d9bfcd126377 100644 --- a/pandas/tests/groupby/test_function.py +++ b/pandas/tests/groupby/test_function.py @@ -40,7 +40,6 @@ def test_groupby_bool_aggs(agg_func, skipna, vals): tm.assert_frame_equal(result, exp_df) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_max_min_non_numeric(): # #2700 aa = DataFrame({'nn': [11, 11, 22, 22], @@ -60,7 +59,6 @@ def test_max_min_non_numeric(): assert 'ss' in result -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_intercept_builtin_sum(): s = Series([1., 2., np.nan, 3.]) grouped = s.groupby([0, 1, 2, 2]) @@ -106,7 +104,6 @@ def test_builtins_apply(keys, f): getattr(df, fname)()) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_arg_passthru(): # make sure that we are passing thru kwargs # to our agg functions @@ -225,7 +222,6 @@ def test_arg_passthru(): tm.assert_index_equal(result.columns, expected_columns) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_non_cython_api(): # GH5610 @@ -310,7 +306,6 @@ def test_cython_api2(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_median(): df = DataFrame(np.random.randn(1000)) df.values[::2] = np.nan @@ -328,7 +323,6 @@ def test_cython_median(): tm.assert_frame_equal(rs, xp) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_median_empty_bins(observed): df = pd.DataFrame(np.random.randint(0, 44, 500)) @@ -408,7 +402,6 @@ def test_groupby_non_arithmetic_agg_int_like_precision(i): assert res.iloc[0].b == data["expected"] -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", {'c_int': [0, 2], 'c_float': [1, 3], 'c_date': [1, 2]}), ("idxmax", {'c_int': [1, 3], 'c_float': [0, 2], 'c_date': [0, 3]}) @@ -447,7 +440,6 @@ def test_fill_consistency(): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_cumprod(): # GH 4095 df = pd.DataFrame({'key': ['b'] * 10, 'value': 2}) @@ -467,7 +459,6 @@ def test_groupby_cumprod(): tm.assert_series_equal(actual, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_ops_general(): ops = [('mean', np.mean), ('median', np.median), @@ -499,7 +490,6 @@ def test_ops_general(): raise -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_max_nan_bug(): raw = """,Date,app,File -04-23,2013-04-23 00:00:00,,log080001.log @@ -514,7 +504,6 @@ def test_max_nan_bug(): assert not r['File'].isna().any() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nlargest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -533,7 +522,6 @@ def test_nlargest(): tm.assert_series_equal(gb.nlargest(3, keep='last'), e) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nsmallest(): a = Series([1, 3, 5, 7, 2, 9, 0, 4, 6, 10]) b = Series(list('a' * 5 + 'b' * 5)) @@ -568,7 +556,6 @@ def test_numpy_compat(func): getattr(g, func)(foo=1) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cummin_cummax(): # GH 15048 num_types = [np.int32, np.int64, np.float32, np.float64] @@ -667,7 +654,6 @@ def test_cummin_cummax(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly increasing (T), strictly decreasing (F), @@ -701,7 +687,6 @@ def test_is_monotonic_increasing(in_vals, out_vals): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('in_vals, out_vals', [ # Basics: strictly decreasing (T), strictly increasing (F), # abs val decreasing (F), non-strictly increasing (T) @@ -738,7 +723,6 @@ def test_apply_describe_bug(mframe): grouped.describe() # it works! -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_describe_multikey(): ts = tm.makeTimeSeries() grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -749,7 +733,6 @@ def test_series_describe_multikey(): tm.assert_series_equal(result['min'], grouped.min(), check_names=False) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_describe_single(): ts = tm.makeTimeSeries() grouped = ts.groupby(lambda x: x.month) @@ -758,14 +741,12 @@ def test_series_describe_single(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_index_name(df): grouped = df.loc[:, ['C']].groupby(df['A']) result = grouped.agg(lambda x: x.mean()) assert result.index.name == 'A' -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_frame_describe_multikey(tsframe): grouped = tsframe.groupby([lambda x: x.year, lambda x: x.month]) result = grouped.describe() @@ -808,7 +789,6 @@ def test_frame_describe_tupleindex(): df2.groupby('key').describe() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_frame_describe_unstacked_format(): # GH 4792 prices = {pd.Timestamp('2011-01-06 10:59:05', tz=None): 24990, @@ -832,7 +812,6 @@ def test_frame_describe_unstacked_format(): # nunique # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('n', 10 ** np.arange(2, 6)) @pytest.mark.parametrize('m', [10, 100, 1000]) @pytest.mark.parametrize('sort', [False, True]) @@ -925,7 +904,6 @@ def test_nunique_with_empty_series(): tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nunique_with_timegrouper(): # GH 13453 test = pd.DataFrame({ @@ -1084,7 +1062,6 @@ def __eq__(self, other): # size # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_size(df): grouped = df.groupby(['A', 'B']) result = grouped.size() diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 3043c27c43f59..b7abef9357072 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -24,7 +24,6 @@ def test_repr(): assert result == expected -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', ['int64', 'int32', 'float64', 'float32']) def test_basic(dtype): @@ -188,7 +187,6 @@ def f(grp): assert_series_equal(result, e) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_pass_args_kwargs(ts, tsframe): def f(x, q=None, axis=0): @@ -258,7 +256,6 @@ def test_basic_regression(): grouped.mean() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('dtype', ['float64', 'float32', 'int64', 'int32', 'int16', 'int8']) def test_with_na_groups(dtype): @@ -343,7 +340,6 @@ def f3(x): df2.groupby('a').apply(f3) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_attr_wrapper(ts): grouped = ts.groupby(lambda x: x.weekday()) @@ -661,7 +657,6 @@ def test_groupby_as_index_cython(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_as_index_series_scalar(df): grouped = df.groupby(['A', 'B'], as_index=False) @@ -682,7 +677,6 @@ def test_groupby_as_index_corner(df, ts): df.groupby(lambda x: x.lower(), as_index=False, axis=1) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_multiple_key(df): df = tm.makeTimeDataFrame() grouped = df.groupby([lambda x: x.year, lambda x: x.month, @@ -749,7 +743,6 @@ def test_omit_nuisance_python_multiple(three_group): assert_frame_equal(agged, exp) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_empty_groups_corner(mframe): # handle empty groups df = DataFrame({'k1': np.array(['b', 'b', 'b', 'a', 'a', 'a']), @@ -777,7 +770,6 @@ def test_nonsense_func(): df.groupby(lambda x: x + 'foo') -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_wrap_aggregated_output_multindex(mframe): df = mframe.T df['baz', 'two'] = 'peekaboo' @@ -860,7 +852,6 @@ def test_groupby_level_nonmulti(): s.groupby(level=[1]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_complex(): # GH 12902 a = Series(data=np.arange(4) * (1 + 2j), index=[0, 0, 1, 1]) @@ -995,7 +986,6 @@ def test_groupby_series_with_name(df): assert 'B' in result2 -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_seriesgroupby_name_attr(df): # GH 6265 result = df.groupby('A')['C'] @@ -1067,7 +1057,6 @@ def test_groupby_mixed_type_columns(): # TODO: Ensure warning isn't emitted in the first place @pytest.mark.filterwarnings("ignore:Mean of:RuntimeWarning") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_cython_grouper_series_bug_noncontig(): arr = np.empty((100, 100)) arr.fill(np.nan) @@ -1078,7 +1067,6 @@ def test_cython_grouper_series_bug_noncontig(): assert result.isna().all() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_series_grouper_noncontig_index(): index = Index(tm.rands_array(10, 100)) @@ -1093,7 +1081,6 @@ def test_series_grouper_noncontig_index(): grouped.agg(f) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_convert_objects_leave_decimal_alone(): s = Series(range(5)) @@ -1298,7 +1285,6 @@ def test_dont_clobber_name_column(): assert_frame_equal(result, df) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_skip_group_keys(): tsf = tm.makeTimeDataFrame() @@ -1340,7 +1326,6 @@ def test_multifunc_sum_bug(): assert result['fl'].dtype == np.float64 -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_handle_dict_return_value(df): def f(group): return {'max': group.max(), 'min': group.min()} @@ -1355,7 +1340,6 @@ def g(group): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('grouper', ['A', ['A', 'B']]) def test_set_group_name(df, grouper): def f(group): @@ -1425,7 +1409,6 @@ def test_groupby_sort_multiindex_series(): assert_series_equal(result, mseries_result.sort_index()) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_reindex_inside_function(): periods = 1000 @@ -1522,7 +1505,6 @@ def test_groupby_multiindex_not_lexsorted(): tm.assert_frame_equal(expected, result) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_index_label_overlaps_location(): # checking we don't have any label/location confusion in the # the wake of GH5375 @@ -1647,7 +1629,6 @@ def test_pivot_table_values_key_error(): values='badname', aggfunc='count') -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_empty_dataframe_groupby(): # GH8093 df = DataFrame(columns=['A', 'B', 'C']) diff --git a/pandas/tests/groupby/test_grouping.py b/pandas/tests/groupby/test_grouping.py index 6b5839680da0a..4c84c29ff98cb 100644 --- a/pandas/tests/groupby/test_grouping.py +++ b/pandas/tests/groupby/test_grouping.py @@ -93,7 +93,6 @@ def test_getitem_numeric_column_names(self): # grouping # -------------------------------- -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouping: def test_grouper_index_types(self): @@ -705,7 +704,6 @@ def test_grouping_is_iterable(self, tsframe): for g in grouped.grouper.groupings[0]: pass - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_multi_iter(self): s = Series(np.arange(6)) k1 = np.array(['a', 'a', 'a', 'b', 'b', 'b']) @@ -758,7 +756,6 @@ def test_multi_iter_frame(self, three_group): for key, group in grouped: pass - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_dictify(self, df): dict(iter(df.groupby('A'))) dict(iter(df.groupby(['A', 'B']))) diff --git a/pandas/tests/groupby/test_nth.py b/pandas/tests/groupby/test_nth.py index 574f4101a13e8..6a08a8d79b63e 100644 --- a/pandas/tests/groupby/test_nth.py +++ b/pandas/tests/groupby/test_nth.py @@ -90,7 +90,6 @@ def test_first_last_nth_dtypes(df_mixed_floats): assert f.dtype == 'int64' -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_nth(): df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B']) g = df.groupby('A') @@ -277,7 +276,6 @@ def test_first_last_tz(data, expected_first, expected_last): assert_frame_equal(result, expected[['id', 'time']]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('method, ts, alpha', [ ['first', Timestamp('2013-01-01', tz='US/Eastern'), 'a'], ['last', Timestamp('2013-01-02', tz='US/Eastern'), 'b'] diff --git a/pandas/tests/groupby/test_timegrouper.py b/pandas/tests/groupby/test_timegrouper.py index 793160b5d34cc..ef05e6ada4890 100644 --- a/pandas/tests/groupby/test_timegrouper.py +++ b/pandas/tests/groupby/test_timegrouper.py @@ -16,7 +16,6 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGroupBy: def test_groupby_with_timegrouper(self): diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index 937804c223c4b..6ed2e178a7fc7 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -20,7 +20,6 @@ def assert_fp_equal(a, b): assert (np.abs(a - b) < 1e-12).all() -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform(): data = Series(np.arange(9) // 3, index=np.arange(9)) @@ -113,7 +112,6 @@ def test_transform_fast(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_broadcast(tsframe, ts): grouped = ts.groupby(lambda x: x.month) result = grouped.transform(np.mean) @@ -194,7 +192,6 @@ def test_transform_dtype(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_bug(): # GH 5712 # transforming on a datetime column @@ -205,7 +202,6 @@ def test_transform_bug(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_numeric_to_boolean(): # GH 16875 # inconsistency in transforming boolean values @@ -220,7 +216,6 @@ def test_transform_numeric_to_boolean(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_datetime_to_timedelta(): # GH 15429 # transforming a datetime to timedelta @@ -239,7 +234,6 @@ def test_transform_datetime_to_timedelta(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_datetime_to_numeric(): # GH 10972 # convert dt to float @@ -261,7 +255,6 @@ def test_transform_datetime_to_numeric(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_casting(): # 13046 data = """ @@ -289,7 +282,6 @@ def test_transform_casting(): assert is_timedelta64_dtype(result.DATETIME.dtype) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_multiple(ts): grouped = ts.groupby([lambda x: x.year, lambda x: x.month]) @@ -318,7 +310,6 @@ def test_transform_select_columns(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_exclude_nuisance(df): # this also tests orderings in transform between @@ -333,7 +324,6 @@ def test_transform_exclude_nuisance(df): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_function_aliases(df): result = df.groupby('A').transform('mean') expected = df.groupby('A').transform(np.mean) @@ -355,7 +345,6 @@ def test_series_fast_transform_date(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_transform_length(): # GH 9697 df = pd.DataFrame({'col1': [1, 1, 2, 2], 'col2': [1, 2, 3, np.nan]}) @@ -385,7 +374,6 @@ def test_transform_coercion(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform_with_int(): # GH 3740, make sure that we might upcast on item-by-item transform @@ -538,7 +526,6 @@ def test_cython_group_transform_algos(): tm.assert_numpy_array_equal(actual[:, 0].view('m8[ns]'), expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -590,7 +577,6 @@ def test_groupby_cum_skipna(op, skipna, input, exp): tm.assert_series_equal(expected, result) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( "op, args, targop", [('cumprod', (), lambda x: x.cumprod()), @@ -784,7 +770,6 @@ def test_pad_stable_sorting(fill_method): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("test_series", [True, False]) @pytest.mark.parametrize("freq", [ None, @@ -831,7 +816,6 @@ def test_any_all_np_func(func): tm.assert_series_equal(res, exp) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform_rename(): # https://github.com/pandas-dev/pandas/issues/23461 def demean_rename(x): @@ -866,7 +850,6 @@ def test_groupby_transform_timezone_column(func): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func, values", [ ("idxmin", ["1/1/2011"] * 2 + ["1/3/2011"] * 7 + ["1/10/2011"]), ("idxmax", ["1/2/2011"] * 2 + ["1/9/2011"] * 7 + ["1/10/2011"]) diff --git a/pandas/tests/groupby/test_value_counts.py b/pandas/tests/groupby/test_value_counts.py index 1185bb10bf50f..2b5f87aa59a8d 100644 --- a/pandas/tests/groupby/test_value_counts.py +++ b/pandas/tests/groupby/test_value_counts.py @@ -50,7 +50,6 @@ def seed_df(seed_nans, n, m): @pytest.mark.slow -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("df, keys, bins, n, m", binned, ids=ids) def test_series_groupby_value_counts(df, keys, bins, n, m): diff --git a/pandas/tests/groupby/test_whitelist.py b/pandas/tests/groupby/test_whitelist.py index 825b1cc5a4493..2bd2f3fb00b56 100644 --- a/pandas/tests/groupby/test_whitelist.py +++ b/pandas/tests/groupby/test_whitelist.py @@ -159,7 +159,6 @@ def raw_frame(): return raw_frame -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('axis', [0, 1]) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 7b6029e00f432..47c00018f170c 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -36,8 +36,6 @@ _mixed_frame = _frame.copy() -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestPandasContainer: @pytest.fixture(scope="function", autouse=True) @@ -1020,13 +1018,19 @@ def test_sparse(self): df = pd.DataFrame(np.random.randn(10, 4)) df.loc[:8] = np.nan - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sdf = df.to_sparse() expected = df.to_json() assert expected == sdf.to_json() s = pd.Series(np.random.randn(10)) s.loc[:8] = np.nan - ss = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s.to_sparse() expected = s.to_json() assert expected == ss.to_json() diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index ebdba08e4449d..bb8d6d415c123 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -551,8 +551,6 @@ def test_dataframe_duplicate_column_names(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparse(TestPackers): def _check_roundtrip(self, obj, comparator, **kwargs): @@ -568,15 +566,24 @@ def test_sparse_series(self): s = tm.makeStringSeries() s[3:5] = np.nan - ss = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_series_equal, check_series_type=True) - ss2 = s.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_series_equal, check_series_type=True) - ss3 = s.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_series_equal, check_series_type=True) @@ -585,16 +592,25 @@ def test_sparse_frame(self): s = tm.makeDataFrame() s.loc[3:5, 1:3] = np.nan s.loc[8:10, -2] = np.nan - ss = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_frame_equal, check_frame_type=True) - ss2 = s.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_frame_equal, check_frame_type=True) - ss3 = s.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_frame_equal, check_frame_type=True) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 71ea303cac9a6..b2a740b6bf202 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -151,8 +151,6 @@ def teardown_method(self, method): @pytest.mark.single -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestHDFStore(Base): def test_format_kwarg_in_constructor(self): @@ -2251,15 +2249,24 @@ def test_sparse_series(self): s = tm.makeStringSeries() s.iloc[3:5] = np.nan - ss = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_series_equal, check_series_type=True) - ss2 = s.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_series_equal, check_series_type=True) - ss3 = s.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_series_equal, check_series_type=True) @@ -2269,16 +2276,25 @@ def test_sparse_frame(self): s = tm.makeDataFrame() s.iloc[3:5, 1:3] = np.nan s.iloc[8:10, -2] = np.nan - ss = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s.to_sparse() self._check_double_roundtrip(ss, tm.assert_frame_equal, check_frame_type=True) - ss2 = s.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss2 = s.to_sparse(kind='integer') self._check_double_roundtrip(ss2, tm.assert_frame_equal, check_frame_type=True) - ss3 = s.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss3 = s.to_sparse(fill_value=0) self._check_double_roundtrip(ss3, tm.assert_frame_equal, check_frame_type=True) @@ -2609,7 +2625,10 @@ def test_sparse_with_compression(self): # make sparse dataframe arr = np.random.binomial(n=1, p=.01, size=(1000, 10)) - df = DataFrame(arr).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + df = DataFrame(arr).to_sparse(fill_value=0) # case 1: store uncompressed self._check_double_roundtrip(df, tm.assert_frame_equal, @@ -3789,7 +3808,10 @@ def test_start_stop_fixed(self): df = tm.makeDataFrame() df.iloc[3:5, 1:3] = np.nan df.iloc[8:10, -2] = np.nan - dfs = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + dfs = df.to_sparse() store.put('dfs', dfs) with pytest.raises(NotImplementedError): store.select('dfs', start=0, stop=5) diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 5efe7fc2391c5..de1ac0c293189 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -19,7 +19,6 @@ @td.skip_if_no_mpl -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFramePlots(TestPlotBase): @pytest.mark.slow @@ -34,22 +33,18 @@ def test_boxplot_legacy1(self): _check_plot_works(df.boxplot, column=[ 'one', 'two'], return_type='dict') # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, column=['one', 'two'], by='indic') _check_plot_works(df.boxplot, column='one', by=['indic', 'indic2']) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, by='indic') - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, by=['indic', 'indic2']) _check_plot_works(plotting._core.boxplot, data=df['one'], return_type='dict') _check_plot_works(df.boxplot, notch=1, return_type='dict') - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, by='indic', notch=1) @pytest.mark.slow @@ -57,8 +52,7 @@ def test_boxplot_legacy2(self): df = DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2']) df['X'] = Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) df['Y'] = Series(['A'] * 10) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(df.boxplot, by='X') # When ax is supplied and required number of axes is 1, @@ -75,8 +69,7 @@ def test_boxplot_legacy2(self): # Multiple columns with an ax argument should use same figure fig, ax = self.plt.subplots() - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = df.boxplot(column=['Col1', 'Col2'], by='X', ax=ax, return_type='axes') assert axes['Col1'].get_figure() is fig @@ -169,7 +162,6 @@ def test_fontsize(self): @td.skip_if_no_mpl -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFrameGroupByPlots(TestPlotBase): @pytest.mark.slow @@ -369,8 +361,7 @@ def test_grouped_box_multiple_axes(self): axes_num=4, layout=(2, 2)) fig, axes = self.plt.subplots(2, 3) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): returned = df.boxplot(column=['height', 'weight', 'category'], by='gender', return_type='axes', ax=axes[0]) returned = np.array(list(returned.values)) diff --git a/pandas/tests/plotting/test_groupby.py b/pandas/tests/plotting/test_groupby.py index ac2d3a8656641..5a5ee75928c97 100644 --- a/pandas/tests/plotting/test_groupby.py +++ b/pandas/tests/plotting/test_groupby.py @@ -4,7 +4,6 @@ import numpy as np -import pytest import pandas.util._test_decorators as td @@ -14,7 +13,6 @@ @td.skip_if_no_mpl -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestDataFrameGroupByPlots(TestPlotBase): def test_series_groupby_plotting_nominally_works(self): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 77b54576f605c..5fd2510d8a96f 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -16,7 +16,6 @@ @td.skip_if_no_mpl -@pytest.mark.filterwarnings('ignore::FutureWarning') class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -33,11 +32,9 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) fig, ax = self.plt.subplots(1, 1) @@ -75,44 +72,37 @@ def test_hist_layout_with_by(self): # _check_plot_works adds an `ax` kwarg to the method call # so we get a warning about an axis being cleared, even # though we don't explicing pass one, see GH #13188 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) @@ -354,14 +344,12 @@ def test_grouped_hist_layout(self): with pytest.raises(ValueError, match=msg): df.hist(column='height', by=df.category, layout=(-1, -1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.hist, column='height', by=df.gender, layout=(2, -1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) @@ -379,15 +367,13 @@ def test_grouped_hist_layout(self): tm.close() # GH 6769 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works( df.hist, column='height', by='classroom', layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) # without column - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.hist, by='classroom') self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index db61c59edf7ef..737a69a06af5a 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -21,7 +21,6 @@ @td.skip_if_no_mpl -@pytest.mark.filterwarnings('ignore::FutureWarning') class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -370,12 +369,10 @@ def test_hist_legacy(self): _check_plot_works(self.ts.hist, grid=False) _check_plot_works(self.ts.hist, figsize=(8, 10)) # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): _check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5) @@ -412,44 +409,37 @@ def test_hist_layout_with_by(self): df = self.hist_df # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(2, 1)) self._check_axes_shape(axes, axes_num=2, layout=(2, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.gender, layout=(3, -1)) self._check_axes_shape(axes, axes_num=2, layout=(3, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(4, 1)) self._check_axes_shape(axes, axes_num=4, layout=(4, 1)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(2, -1)) self._check_axes_shape(axes, axes_num=4, layout=(2, 2)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(3, -1)) self._check_axes_shape(axes, axes_num=4, layout=(3, 2)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.category, layout=(-1, 4)) self._check_axes_shape(axes, axes_num=4, layout=(1, 4)) - with tm.assert_produces_warning(Warning, - check_stacklevel=False): + with tm.assert_produces_warning(UserWarning): axes = _check_plot_works(df.height.hist, by=df.classroom, layout=(2, 2)) self._check_axes_shape(axes, axes_num=3, layout=(2, 2)) diff --git a/pandas/tests/reductions/test_stat_reductions.py b/pandas/tests/reductions/test_stat_reductions.py index 46e685165bbed..223904048dd99 100644 --- a/pandas/tests/reductions/test_stat_reductions.py +++ b/pandas/tests/reductions/test_stat_reductions.py @@ -13,7 +13,6 @@ import pandas.util.testing as tm -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestSeriesStatReductions: # Note: the name TestSeriesStatReductions indicates these tests # were moved from a series-specific test file, _not_ that these tests are diff --git a/pandas/tests/resample/test_datetime_index.py b/pandas/tests/resample/test_datetime_index.py index 3360cb74e3193..5711174ef0c9f 100644 --- a/pandas/tests/resample/test_datetime_index.py +++ b/pandas/tests/resample/test_datetime_index.py @@ -160,7 +160,6 @@ def test_resample_how(series, downsample_method): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize( '_index_start,_index_end,_index_name', [('1/1/2000 00:00:00', '1/1/2000 00:13:00', 'index')]) @@ -1136,7 +1135,6 @@ def test_resample_timegrouper(): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_resample_nunique(): # GH 12352 diff --git a/pandas/tests/resample/test_resample_api.py b/pandas/tests/resample/test_resample_api.py index 89793c78dd04d..7157ecccace00 100644 --- a/pandas/tests/resample/test_resample_api.py +++ b/pandas/tests/resample/test_resample_api.py @@ -217,7 +217,6 @@ def test_fillna(): r.fillna(0) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_without_aggregation(): # both resample and groupby should work w/o aggregation @@ -340,7 +339,6 @@ def test_agg(): ('r2', 'B', 'sum')]) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_agg_misc(): # test with all three Resampler apis and TimeGrouper diff --git a/pandas/tests/resample/test_resampler_grouper.py b/pandas/tests/resample/test_resampler_grouper.py index 52d033ec6e535..959b6febcf1c9 100644 --- a/pandas/tests/resample/test_resampler_grouper.py +++ b/pandas/tests/resample/test_resampler_grouper.py @@ -1,7 +1,6 @@ from textwrap import dedent import numpy as np -import pytest import pandas as pd from pandas import DataFrame, Series, Timestamp @@ -62,7 +61,6 @@ def f(x): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_getitem(): g = test_frame.groupby('A') @@ -78,7 +76,6 @@ def test_getitem(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_getitem_multiple(): # GH 13174 @@ -99,7 +96,6 @@ def test_getitem_multiple(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_resample_on_api_with_getitem(): # GH 17813 df = pd.DataFrame({'id': list('aabbb'), @@ -129,7 +125,6 @@ def test_nearest(): assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_methods(): g = test_frame.groupby('A') r = g.resample('2s') @@ -192,7 +187,6 @@ def f(x): assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply_with_mutated_index(): # GH 15169 index = pd.date_range('1-1-2015', '12-31-15', freq='D') diff --git a/pandas/tests/resample/test_time_grouper.py b/pandas/tests/resample/test_time_grouper.py index dc7cd99c36ced..3f767f8e7100f 100644 --- a/pandas/tests/resample/test_time_grouper.py +++ b/pandas/tests/resample/test_time_grouper.py @@ -15,7 +15,6 @@ index=date_range('1/1/2000', periods=1000)) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_apply(): grouper = Grouper(freq='A', label='right', closed='right') diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 92e31302947b2..cc91bef525eff 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -19,7 +19,6 @@ def dropna(request): return request.param -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestPivotTable: def setup_method(self, method): @@ -1359,7 +1358,6 @@ def test_pivot_table_aggfunc_scalar_dropna(self, dropna): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestCrosstab: def setup_method(self, method): diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 065f70d31ec78..9cfce092255a1 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -124,7 +124,10 @@ def test_sort_index_name(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_to_sparse_pass_name(self): - result = self.ts.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = self.ts.to_sparse() assert result.name == self.ts.name def test_constructor_dict(self): @@ -209,7 +212,6 @@ def test_sparse_accessor_updates_on_inplace(self): assert s.sparse.density == 1.0 -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesMisc(TestData, SharedWithSparse): series_klass = Series diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index e48645e59ddf1..bc1ed3f532fde 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -10,7 +10,6 @@ from pandas.util.testing import assert_frame_equal, assert_series_equal -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesCombine: def test_append(self, datetime_series, string_series, object_series): @@ -245,20 +244,29 @@ def test_concat_empty_series_dtypes(self): # sparse # TODO: move? - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='float64').to_sparse()]) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = pd.concat([Series(dtype='float64').to_sparse(), Series( + dtype='float64').to_sparse()]) assert result.dtype == 'Sparse[float64]' assert result.ftype == 'float64:sparse' - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='float64')]) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = pd.concat([Series(dtype='float64').to_sparse(), Series( + dtype='float64')]) # TODO: release-note: concat sparse dtype expected = pd.core.sparse.api.SparseDtype(np.float64) assert result.dtype == expected assert result.ftype == 'float64:sparse' - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='object')]) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = pd.concat([Series(dtype='float64').to_sparse(), Series( + dtype='object')]) # TODO: release-note: concat sparse dtype expected = pd.core.sparse.api.SparseDtype('object') assert result.dtype == expected diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index e0cd55d5f9dd2..ed6c1d7376ba8 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -39,7 +39,6 @@ def _simple_ts(start, end, freq='D'): return Series(np.random.randn(len(rng)), index=rng) -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSeriesMissingData: def test_remove_na_deprecation(self): @@ -786,7 +785,10 @@ def test_sparse_series_fillna_limit(self): index = np.arange(10) s = Series(np.random.randn(10), index=index) - ss = s[:2].reindex(index).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s[:2].reindex(index).to_sparse() # TODO: what is this test doing? why are result an expected # the same call to fillna? with tm.assert_produces_warning(PerformanceWarning, @@ -796,24 +798,36 @@ def test_sparse_series_fillna_limit(self): expected = ss.fillna(method='pad', limit=5) expected = expected.to_dense() expected[-3:] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() assert_series_equal(result, expected) - ss = s[-2:].reindex(index).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = s[-2:].reindex(index).to_sparse() with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): result = ss.fillna(method='backfill', limit=5) expected = ss.fillna(method='backfill') expected = expected.to_dense() expected[:3] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() assert_series_equal(result, expected) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_sparse_series_pad_backfill_limit(self): index = np.arange(10) s = Series(np.random.randn(10), index=index) - s = s.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = s.to_sparse() result = s[:2].reindex(index, method='pad', limit=5) with tm.assert_produces_warning(PerformanceWarning, @@ -821,7 +835,10 @@ def test_sparse_series_pad_backfill_limit(self): expected = s[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected[-3:] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() assert_series_equal(result, expected) result = s[-2:].reindex(index, method='backfill', limit=5) @@ -830,7 +847,10 @@ def test_sparse_series_pad_backfill_limit(self): expected = s[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected[:3] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() assert_series_equal(result, expected) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py index cc33cf295e046..388d4ca67b4c9 100644 --- a/pandas/tests/sparse/frame/test_apply.py +++ b/pandas/tests/sparse/frame/test_apply.py @@ -38,8 +38,6 @@ def fill_frame(frame): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_apply(frame): applied = frame.apply(np.sqrt) assert isinstance(applied, SparseDataFrame) @@ -58,8 +56,11 @@ def test_apply(frame): tm.assert_frame_equal(broadcasted.to_dense(), exp) applied = frame.apply(np.sum) - tm.assert_series_equal(applied, - frame.to_dense().apply(nanops.nansum).to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_series_equal(applied, + frame.to_dense().apply(nanops.nansum) + .to_sparse()) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @@ -74,11 +75,12 @@ def test_apply_empty(empty): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_apply_nonuq(): orig = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c']) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sparse = orig.to_sparse() res = sparse.apply(lambda s: s[0], axis=1) exp = orig.apply(lambda s: s[0], axis=1) @@ -89,8 +91,10 @@ def test_apply_nonuq(): assert isinstance(res, Series) tm.assert_series_equal(res.to_dense(), exp) - # df.T breaks - sparse = orig.T.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + # df.T breaks + sparse = orig.T.to_sparse() res = sparse.apply(lambda s: s[0], axis=0) # noqa exp = orig.T.apply(lambda s: s[0], axis=0) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 6af6e6d41b335..d661ba3378870 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -25,7 +25,6 @@ def test_deprecated(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseDataFrame(SharedWithSparse): klass = SparseDataFrame @@ -182,7 +181,9 @@ def test_constructor_from_series(self): # GH 2873 x = Series(np.random.randn(10000), name='a') - x = x.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + x = x.to_sparse(fill_value=0) assert isinstance(x, SparseSeries) df = SparseDataFrame(x) assert isinstance(df, SparseDataFrame) @@ -192,14 +193,18 @@ def test_constructor_from_series(self): x2 = x.astype(float) x2.loc[:9998] = np.NaN # TODO: x_sparse is unused...fix - x_sparse = x2.to_sparse(fill_value=np.NaN) # noqa + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + x_sparse = x2.to_sparse(fill_value=np.NaN) # noqa # Currently fails too with weird ufunc error # df1 = SparseDataFrame([x_sparse, y]) y.loc[:9998] = 0 # TODO: y_sparse is unsused...fix - y_sparse = y.to_sparse(fill_value=0) # noqa + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + y_sparse = y.to_sparse(fill_value=0) # noqa # without sparse value raises error # df2 = SparseDataFrame([x2_sparse, y]) @@ -208,13 +213,17 @@ def test_constructor_from_dense_series(self): # series with name x = Series(np.random.randn(10000), name='a') result = SparseDataFrame(x) - expected = x.to_frame().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + expected = x.to_frame().to_sparse() tm.assert_sp_frame_equal(result, expected) # series with no name x = Series(np.random.randn(10000)) result = SparseDataFrame(x) - expected = x.to_frame().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + expected = x.to_frame().to_sparse() tm.assert_sp_frame_equal(result, expected) def test_constructor_from_unknown_type(self): @@ -258,7 +267,9 @@ def test_constructor_nan_dataframe(self): matrix = np.empty((len(index), len(trains))) matrix.fill(np.nan) df = pd.DataFrame(matrix, index=index, columns=trains, dtype=float) - result = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + result = df.to_sparse() expected = pd.SparseDataFrame(matrix, index=index, columns=trains, dtype=float) tm.assert_sp_frame_equal(result, expected) @@ -291,7 +302,9 @@ def test_nan_data_with_int_dtype_raises_error(self): def test_dtypes(self): df = DataFrame(np.random.randn(10000, 4)) df.loc[:9998] = np.nan - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sdf = df.to_sparse() result = sdf.get_dtype_counts() expected = Series({'Sparse[float64, nan]': 4}) @@ -309,7 +322,9 @@ def test_str(self): df = DataFrame(np.random.randn(10000, 4)) df.loc[:9998] = np.nan - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sdf = df.to_sparse() str(sdf) def test_array_interface(self, float_frame): @@ -335,18 +350,24 @@ def _test_roundtrip(frame, orig): def test_dense_to_sparse(self): df = DataFrame({'A': [nan, nan, nan, 1, 2], 'B': [1, 2, nan, nan, nan]}) - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sdf = df.to_sparse() assert isinstance(sdf, SparseDataFrame) assert np.isnan(sdf.default_fill_value) assert isinstance(sdf['A'].sp_index, BlockIndex) tm.assert_frame_equal(sdf.to_dense(), df) - sdf = df.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sdf = df.to_sparse(kind='integer') assert isinstance(sdf['A'].sp_index, IntIndex) df = DataFrame({'A': [0, 0, 0, 1, 2], 'B': [1, 2, 0, 0, 0]}, dtype=float) - sdf = df.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + sdf = df.to_sparse(fill_value=0) assert sdf.default_fill_value == 0 tm.assert_frame_equal(sdf.to_dense(), df) @@ -383,7 +404,10 @@ def _compare_to_dense(a, b, da, db, op): dense_result = op(da, db) fill = sparse_result.default_fill_value - dense_result = dense_result.to_sparse(fill_value=fill) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + dense_result = dense_result.to_sparse(fill_value=fill) tm.assert_sp_frame_equal(sparse_result, dense_result, exact_indices=False) @@ -779,16 +803,20 @@ def test_fillna(self, float_frame_fill0, float_frame_fill0_dense): result = df.fillna(0) expected = dense.fillna(0) - tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), - exact_indices=False) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), + exact_indices=False) tm.assert_frame_equal(result.to_dense(), expected) result = df.copy() result.fillna(0, inplace=True) expected = dense.fillna(0) - tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), - exact_indices=False) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), + exact_indices=False) tm.assert_frame_equal(result.to_dense(), expected) result = df.copy() @@ -814,7 +842,10 @@ def test_fillna_fill_value(self): def test_sparse_frame_pad_backfill_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sdf = df.to_sparse() result = sdf[:2].reindex(index, method='pad', limit=5) @@ -823,7 +854,10 @@ def test_sparse_frame_pad_backfill_limit(self): expected = sdf[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected.values[-3:] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) result = sdf[-2:].reindex(index, method='backfill', limit=5) @@ -833,13 +867,19 @@ def test_sparse_frame_pad_backfill_limit(self): expected = sdf[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected.values[:3] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) def test_sparse_frame_fillna_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) - sdf = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sdf = df.to_sparse() result = sdf[:2].reindex(index) with tm.assert_produces_warning(PerformanceWarning, @@ -851,7 +891,10 @@ def test_sparse_frame_fillna_limit(self): expected = sdf[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected.values[-3:] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) result = sdf[-2:].reindex(index) @@ -864,7 +907,10 @@ def test_sparse_frame_fillna_limit(self): expected = sdf[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected.values[:3] = np.nan - expected = expected.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) def test_rename(self, float_frame): @@ -886,7 +932,11 @@ def test_rename(self, float_frame): def test_corr(self, float_frame): res = float_frame.corr() # XXX: this stays sparse - tm.assert_frame_equal(res, float_frame.to_dense().corr().to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_frame_equal(res, + float_frame.to_dense().corr().to_sparse()) def test_describe(self, float_frame): float_frame['foo'] = np.nan @@ -974,7 +1024,10 @@ def test_reindex_fill_value(self, float_frame_fill0, result = float_frame_fill0.reindex(rng, fill_value=0) exp = float_frame_fill0_dense.reindex(rng, fill_value=0) - exp = exp.to_sparse(float_frame_fill0.default_fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = exp.to_sparse(float_frame_fill0.default_fill_value) tm.assert_sp_frame_equal(result, exp) def test_reindex_method(self): @@ -1127,14 +1180,20 @@ def _check(frame, orig): shifted = frame.shift(2, freq='B') exp = orig.shift(2, freq='B') - exp = exp.to_sparse(frame.default_fill_value, - kind=frame.default_kind) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = exp.to_sparse(frame.default_fill_value, + kind=frame.default_kind) tm.assert_frame_equal(shifted, exp) shifted = frame.shift(2, freq=BDay()) exp = orig.shift(2, freq=BDay()) - exp = exp.to_sparse(frame.default_fill_value, - kind=frame.default_kind) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = exp.to_sparse(frame.default_fill_value, + kind=frame.default_kind) tm.assert_frame_equal(shifted, exp) _check(float_frame, float_frame_dense) @@ -1175,7 +1234,10 @@ def test_combine_first(self, float_frame): result = df[::2].combine_first(df) expected = df[::2].to_dense().combine_first(df.to_dense()) - expected = expected.to_sparse(fill_value=df.default_fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse(fill_value=df.default_fill_value) tm.assert_sp_frame_equal(result, expected) @@ -1188,7 +1250,10 @@ def test_combine_first_with_dense(self): result = df[::2].combine_first(df.to_dense()) expected = df[::2].to_dense().combine_first(df.to_dense()) - expected = expected.to_sparse(fill_value=df.default_fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse(fill_value=df.default_fill_value) tm.assert_sp_frame_equal(result, expected) @@ -1198,12 +1263,19 @@ def test_combine_add(self, float_frame): df2['C'][:3] = np.nan df['A'][:3] = 5.7 - result = df.to_sparse().add(df2.to_sparse(), fill_value=0) - expected = df.add(df2, fill_value=0).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = df.to_sparse().add(df2.to_sparse(), fill_value=0) + expected = df.add(df2, fill_value=0).to_sparse() tm.assert_sp_frame_equal(result, expected) def test_isin(self): - sparse_df = DataFrame({'flag': [1., 0., 1.]}).to_sparse(fill_value=0.) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_df = DataFrame({'flag': [1., 0., 1.]}) + sparse_df = sparse_df.to_sparse(fill_value=0.) xp = sparse_df[sparse_df.flag == 1.] rs = sparse_df[sparse_df.flag.isin([1.])] tm.assert_frame_equal(xp, rs) @@ -1239,7 +1311,10 @@ def test_as_blocks(self): def test_nan_columnname(self): # GH 8822 nan_colname = DataFrame(Series(1.0, index=[0]), columns=[nan]) - nan_colname_sparse = nan_colname.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + nan_colname_sparse = nan_colname.to_sparse() assert np.isnan(nan_colname_sparse.columns[0]) def test_isna(self): @@ -1296,7 +1371,6 @@ def test_default_fill_value_with_no_data(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameArithmetic: def test_numeric_op_scalar(self): @@ -1304,9 +1378,12 @@ def test_numeric_op_scalar(self): 'B': [0, 1, 2, nan], 'C': [1., 2., 3., 4.], 'D': [nan, nan, nan, nan]}) - sparse = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = df.to_sparse() - tm.assert_sp_frame_equal(sparse + 1, (df + 1).to_sparse()) + tm.assert_sp_frame_equal(sparse + 1, (df + 1).to_sparse()) def test_comparison_op_scalar(self): # GH 13001 @@ -1314,7 +1391,10 @@ def test_comparison_op_scalar(self): 'B': [0, 1, 2, nan], 'C': [1., 2., 3., 4.], 'D': [nan, nan, nan, nan]}) - sparse = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = df.to_sparse() # comparison changes internal repr, compare with dense res = sparse > 1 @@ -1327,7 +1407,6 @@ def test_comparison_op_scalar(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameAnalytics: def test_cumsum(self, float_frame): @@ -1399,8 +1478,10 @@ def test_quantile_multi(self): def test_assign_with_sparse_frame(self): # GH 19163 df = pd.DataFrame({"a": [1, 2, 3]}) - res = df.to_sparse(fill_value=False).assign(newcol=False) - exp = df.assign(newcol=False).to_sparse(fill_value=False) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + res = df.to_sparse(fill_value=False).assign(newcol=False) + exp = df.assign(newcol=False).to_sparse(fill_value=False) tm.assert_sp_frame_equal(res, exp) diff --git a/pandas/tests/sparse/frame/test_to_csv.py b/pandas/tests/sparse/frame/test_to_csv.py index 84b29b1c2ddee..7e38cc15abf46 100644 --- a/pandas/tests/sparse/frame/test_to_csv.py +++ b/pandas/tests/sparse/frame/test_to_csv.py @@ -6,8 +6,6 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameToCsv: fill_values = [np.nan, 0, None, 1] @@ -21,4 +19,8 @@ def test_to_csv_sparse_dataframe(self, fill_value): sdf.to_csv(path, index=False) df = read_csv(path, skip_blank_lines=False) - tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), sdf) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), + sdf) diff --git a/pandas/tests/sparse/frame/test_to_from_scipy.py b/pandas/tests/sparse/frame/test_to_from_scipy.py index 28a173d0bc8ba..fbf83339c3fdb 100644 --- a/pandas/tests/sparse/frame/test_to_from_scipy.py +++ b/pandas/tests/sparse/frame/test_to_from_scipy.py @@ -20,7 +20,6 @@ @pytest.mark.parametrize('dtype', [bool, int, float, np.uint16]) @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): # GH 4343 # Make one ndarray and from it one sparse matrix, both to be used for @@ -72,7 +71,6 @@ def test_from_to_scipy(spmatrix, index, columns, fill_value, dtype): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:object dtype is not supp:UserWarning") @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_to_scipy_object(spmatrix, fill_value): # GH 4343 dtype = object @@ -122,7 +120,6 @@ def test_from_to_scipy_object(spmatrix, fill_value): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_scipy_correct_ordering(spmatrix): # GH 16179 arr = np.arange(1, 5).reshape(2, 2) @@ -143,7 +140,6 @@ def test_from_scipy_correct_ordering(spmatrix): @ignore_matrix_warning @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_from_scipy_fillna(spmatrix): # GH 16112 arr = np.eye(3) @@ -183,8 +179,11 @@ def test_index_names_multiple_nones(): # https://github.com/pandas-dev/pandas/pull/24092 sparse = pytest.importorskip("scipy.sparse") - s = (pd.Series(1, index=pd.MultiIndex.from_product([['A', 'B'], [0, 1]])) - .to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = (pd.Series(1, index=pd.MultiIndex + .from_product([['A', 'B'], [0, 1]])).to_sparse()) result, _, _ = s.to_coo() assert isinstance(result, sparse.coo_matrix) result = result.toarray() diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 912965582b048..9d744144a94e0 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -61,7 +61,6 @@ def _test_data2_zero(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeries(SharedWithSparse): series_klass = SparseSeries @@ -181,7 +180,10 @@ def test_series_density(self): # GH2803 ts = Series(np.random.randn(10)) ts[2:-2] = nan - sts = ts.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sts = ts.to_sparse() density = sts.density # don't die assert density == 4 / 10.0 @@ -225,8 +227,11 @@ def test_to_dense_fill_value(self): def test_dense_to_sparse(self): series = self.bseries.to_dense() - bseries = series.to_sparse(kind='block') - iseries = series.to_sparse(kind='integer') + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + bseries = series.to_sparse(kind='block') + iseries = series.to_sparse(kind='integer') tm.assert_sp_series_equal(bseries, self.bseries) tm.assert_sp_series_equal(iseries, self.iseries, check_names=False) assert iseries.name == self.bseries.name @@ -238,8 +243,11 @@ def test_dense_to_sparse(self): # non-NaN fill value series = self.zbseries.to_dense() - zbseries = series.to_sparse(kind='block', fill_value=0) - ziseries = series.to_sparse(kind='integer', fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + zbseries = series.to_sparse(kind='block', fill_value=0) + ziseries = series.to_sparse(kind='integer', fill_value=0) tm.assert_sp_series_equal(zbseries, self.zbseries) tm.assert_sp_series_equal(ziseries, self.ziseries, check_names=False) assert ziseries.name == self.zbseries.name @@ -381,10 +389,13 @@ def test_shape(self): def test_astype(self): result = self.bseries.astype(SparseDtype(np.int64, 0)) - expected = (self.bseries.to_dense() - .fillna(0) - .astype(np.int64) - .to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = (self.bseries.to_dense() + .fillna(0) + .astype(np.int64) + .to_sparse(fill_value=0)) tm.assert_sp_series_equal(result, expected) def test_astype_all(self): @@ -537,7 +548,10 @@ def _compare(idx): # XXX: changed test. Why wsa this considered a corner case? sp = SparseSeries(np.ones(10) * nan) exp = pd.Series(np.repeat(nan, 5)) - tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp.to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp.to_sparse()) # multiple FutureWarnings, can't check stacklevel with tm.assert_produces_warning(FutureWarning, @@ -699,7 +713,10 @@ def _compare_with_series(sps, new_index): series = sps.to_dense() seriesre = series.reindex(new_index) - seriesre = seriesre.to_sparse(fill_value=sps.fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + seriesre = seriesre.to_sparse(fill_value=sps.fill_value) tm.assert_sp_series_equal(spsre, seriesre) tm.assert_series_equal(spsre.to_dense(), seriesre.to_dense()) @@ -826,12 +843,19 @@ def _compare_all(obj): series.fill_value = 2 _compare_all(series) - nonna = Series(np.random.randn(20)).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + nonna = Series(np.random.randn(20)).to_sparse() _compare_all(nonna) - nonna2 = Series(np.random.randn(20)).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + nonna2 = Series(np.random.randn(20)).to_sparse(fill_value=0) _compare_all(nonna2) + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_dropna(self): sp = SparseSeries([0, 0, 0, nan, nan, 5, 6], fill_value=0) @@ -921,83 +945,106 @@ def test_shift(self): def test_shift_nan(self): # GH 12908 orig = pd.Series([np.nan, 2, np.nan, 4, 0, np.nan, 0]) - sparse = orig.to_sparse() - - tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(1), orig.shift(1).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(2), orig.shift(2).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(3), orig.shift(3).to_sparse(), - check_kind=False) - - tm.assert_sp_series_equal(sparse.shift(-1), orig.shift(-1).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-2), orig.shift(-2).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-3), orig.shift(-3).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-4), orig.shift(-4).to_sparse()) - - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal( - sparse.shift(0), - orig.shift(0).to_sparse(fill_value=sparse.fill_value) - ) - tm.assert_sp_series_equal(sparse.shift(1), - orig.shift(1).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(2), - orig.shift(2).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(3), - orig.shift(3).to_sparse(fill_value=0), - check_kind=False) - - tm.assert_sp_series_equal(sparse.shift(-1), - orig.shift(-1).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-2), - orig.shift(-2).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-3), - orig.shift(-3).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-4), - orig.shift(-4).to_sparse(fill_value=0), - check_kind=False) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(1), + orig.shift(1).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(2), + orig.shift(2).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(3), + orig.shift(3).to_sparse(), + check_kind=False) + + tm.assert_sp_series_equal(sparse.shift(-1), + orig.shift(-1).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-2), + orig.shift(-2).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-3), + orig.shift(-3).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-4), + orig.shift(-4).to_sparse()) + + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal( + sparse.shift(0), + orig.shift(0).to_sparse(fill_value=sparse.fill_value) + ) + tm.assert_sp_series_equal(sparse.shift(1), + orig.shift(1).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(2), + orig.shift(2).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(3), + orig.shift(3).to_sparse(fill_value=0), + check_kind=False) + + tm.assert_sp_series_equal(sparse.shift(-1), + orig.shift(-1).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-2), + orig.shift(-2).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-3), + orig.shift(-3).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-4), + orig.shift(-4).to_sparse(fill_value=0), + check_kind=False) def test_shift_dtype(self): # GH 12908 orig = pd.Series([1, 2, 3, 4], dtype=np.int64) - sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse()) - - sparse = orig.to_sparse(fill_value=np.nan) - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0).to_sparse(fill_value=np.nan)) - # shift(1) or more span changes dtype to float64 - # XXX: SparseSeries doesn't need to shift dtype here. - # Do we want to astype in shift, for backwards compat? - # If not, document it. - tm.assert_sp_series_equal(sparse.shift(1).astype('f8'), - orig.shift(1).to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.shift(2).astype('f8'), - orig.shift(2).to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.shift(3).astype('f8'), - orig.shift(3).to_sparse(kind='integer')) - - tm.assert_sp_series_equal(sparse.shift(-1).astype('f8'), - orig.shift(-1).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-2).astype('f8'), - orig.shift(-2).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-3).astype('f8'), - orig.shift(-3).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-4).astype('f8'), - orig.shift(-4).to_sparse(), - check_kind=False) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0).to_sparse()) + + sparse = orig.to_sparse(fill_value=np.nan) + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0). + to_sparse(fill_value=np.nan)) + + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + # shift(1) or more span changes dtype to float64 + # XXX: SparseSeries doesn't need to shift dtype here. + # Do we want to astype in shift, for backwards compat? + # If not, document it. + tm.assert_sp_series_equal(sparse.shift(1).astype('f8'), + orig.shift(1).to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.shift(2).astype('f8'), + orig.shift(2).to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.shift(3).astype('f8'), + orig.shift(3).to_sparse(kind='integer')) + + tm.assert_sp_series_equal(sparse.shift(-1).astype('f8'), + orig.shift(-1).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-2).astype('f8'), + orig.shift(-2).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-3).astype('f8'), + orig.shift(-3).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-4).astype('f8'), + orig.shift(-4).to_sparse(), + check_kind=False) @pytest.mark.parametrize("fill_value", [ 0, @@ -1008,16 +1055,22 @@ def test_shift_dtype(self): def test_shift_dtype_fill_value(self, fill_value, periods): # GH 12908 orig = pd.Series([1, 0, 0, 4], dtype=np.dtype('int64')) - - sparse = orig.to_sparse(fill_value=fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=fill_value) result = sparse.shift(periods) - expected = orig.shift(periods).to_sparse(fill_value=fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = orig.shift(periods).to_sparse(fill_value=fill_value) tm.assert_sp_series_equal(result, expected, check_kind=False, consolidate_block_indices=True) + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_combine_first(self): s = self.bseries @@ -1025,7 +1078,10 @@ def test_combine_first(self): result2 = s[::2].combine_first(s.to_dense()) expected = s[::2].to_dense().combine_first(s.to_dense()) - expected = expected.to_sparse(fill_value=s.fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = expected.to_sparse(fill_value=s.fill_value) tm.assert_sp_series_equal(result, result2) tm.assert_sp_series_equal(result, expected) @@ -1043,8 +1099,6 @@ def test_memory_usage_deep(self, deep, fill_value): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseHandlingMultiIndexes: def setup_method(self, method): @@ -1057,13 +1111,19 @@ def setup_method(self, method): self.dense_multiindex_frame = dense_multiindex_frame.fillna(value=3.14) def test_to_sparse_preserve_multiindex_names_columns(self): - sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() sparse_multiindex_frame = sparse_multiindex_frame.copy() tm.assert_index_equal(sparse_multiindex_frame.columns, self.dense_multiindex_frame.columns) def test_round_trip_preserve_multiindex_names(self): - sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() round_trip_multiindex_frame = sparse_multiindex_frame.to_dense() tm.assert_frame_equal(self.dense_multiindex_frame, round_trip_multiindex_frame, @@ -1092,17 +1152,23 @@ def setup_method(self, method): (2, 1, 'b', 0), (2, 1, 'b', 1)], names=['A', 'B', 'C', 'D']) - self.sparse_series.append(s.to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.sparse_series.append(s.to_sparse()) ss = self.sparse_series[0].copy() ss.index.names = [3, 0, 1, 2] self.sparse_series.append(ss) - ss = pd.Series([ - nan - ] * 12, index=cartesian_product((range(3), range(4)))).to_sparse() - for k, v in zip([(0, 0), (1, 2), (1, 3)], [3.0, 1.0, 2.0]): - ss[k] = v + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = pd.Series([ + nan + ] * 12, index=cartesian_product((range(3), range(4)))).to_sparse() + for k, v in zip([(0, 0), (1, 2), (1, 3)], [3.0, 1.0, 2.0]): + ss[k] = v self.sparse_series.append(ss) # results used in tests @@ -1176,8 +1242,11 @@ def test_to_coo_bad_ilevel(self): ss.to_coo(['A', 'B'], ['C', 'D', 'E']) def test_to_coo_duplicate_index_entries(self): - ss = pd.concat([self.sparse_series[0], - self.sparse_series[0]]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + ss = pd.concat([self.sparse_series[0], + self.sparse_series[0]]).to_sparse() msg = ("Duplicate index entries are not allowed in to_coo" " transformation") with pytest.raises(ValueError, match=msg): @@ -1191,7 +1260,10 @@ def test_from_coo_dense_index(self): def test_from_coo_nodense_index(self): ss = SparseSeries.from_coo(self.coo_matrices[0], dense_index=False) check = self.sparse_series[2] - check = check.dropna().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + check = check.dropna().to_sparse() tm.assert_sp_series_equal(ss, check) def test_from_coo_long_repr(self): @@ -1445,7 +1517,6 @@ def _dense_series_compare(s, f): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesAnalytics: def setup_method(self, method): @@ -1463,7 +1534,10 @@ def test_cumsum(self): tm.assert_sp_series_equal(result, expected) result = self.zbseries.cumsum() - expected = self.zbseries.to_dense().cumsum().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = self.zbseries.to_dense().cumsum().to_sparse() tm.assert_series_equal(result, expected) axis = 1 # Series is 1-D, so only axis = 0 is valid. @@ -1477,7 +1551,10 @@ def test_numpy_cumsum(self): tm.assert_sp_series_equal(result, expected) result = np.cumsum(self.zbseries) - expected = self.zbseries.to_dense().cumsum().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = self.zbseries.to_dense().cumsum().to_sparse() tm.assert_series_equal(result, expected) msg = "the 'dtype' parameter is not supported" @@ -1540,11 +1617,13 @@ def test_constructor_dict_datetime64_index(datetime_type): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_to_sparse(): # https://github.com/pandas-dev/pandas/issues/22389 arr = pd.SparseArray([1, 2, None, 3]) - result = pd.Series(arr).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = pd.Series(arr).to_sparse() assert len(result) == 4 tm.assert_sp_array_equal(result.values, arr, check_kind=False) diff --git a/pandas/tests/sparse/test_combine_concat.py b/pandas/tests/sparse/test_combine_concat.py index a818d5064a73a..92537cd8710ba 100644 --- a/pandas/tests/sparse/test_combine_concat.py +++ b/pandas/tests/sparse/test_combine_concat.py @@ -180,7 +180,6 @@ def test_concat_sparse_dense(self, kind): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame:FutureWarning") class TestSparseDataFrameConcat: def setup_method(self, method): @@ -202,70 +201,112 @@ def setup_method(self, method): def test_concat(self): # fill_value = np.nan - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse() res = pd.concat([sparse, sparse]) - exp = pd.concat([self.dense1, self.dense1]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse2]) - exp = pd.concat([self.dense2, self.dense2]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse, sparse2]) - exp = pd.concat([self.dense1, self.dense2]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse]) - exp = pd.concat([self.dense2, self.dense1]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2, self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) # fill_value = 0 - sparse = self.dense1.to_sparse(fill_value=0) - sparse2 = self.dense2.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse(fill_value=0) + sparse2 = self.dense2.to_sparse(fill_value=0) res = pd.concat([sparse, sparse]) - exp = pd.concat([self.dense1, self.dense1]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse2]) - exp = pd.concat([self.dense2, self.dense2]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2, self.dense2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse, sparse2]) - exp = pd.concat([self.dense1, self.dense2]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse]) - exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) def test_concat_different_fill_value(self): # 1st fill_value will be used - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse(fill_value=0) with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): res = pd.concat([sparse, sparse2]) - exp = pd.concat([self.dense1, self.dense2]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): res = pd.concat([sparse2, sparse]) - exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) def test_concat_different_columns_sort_warns(self): - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() # stacklevel is wrong since we have two FutureWarnings, # one for depr, one for sorting. @@ -278,20 +319,32 @@ def test_concat_different_columns_sort_warns(self): raise_on_extra_warnings=False,): exp = pd.concat([self.dense1, self.dense3]) - exp = exp.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = exp.to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) def test_concat_different_columns(self): # fill_value = np.nan - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() res = pd.concat([sparse, sparse3], sort=True) - exp = pd.concat([self.dense1, self.dense3], sort=True).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense3], sort=True).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) res = pd.concat([sparse3, sparse], sort=True) - exp = pd.concat([self.dense3, self.dense1], sort=True).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense3, self.dense1], sort=True).to_sparse() exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False) @@ -306,27 +359,39 @@ def test_concat_bug(self): tm.assert_frame_equal(res, exp) def test_concat_different_columns_buggy(self): - sparse = self.dense1.to_sparse(fill_value=0) - sparse3 = self.dense3.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse(fill_value=0) + sparse3 = self.dense3.to_sparse(fill_value=0) res = pd.concat([sparse, sparse3], sort=True) - exp = (pd.concat([self.dense1, self.dense3], sort=True) - .to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = (pd.concat([self.dense1, self.dense3], sort=True) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) res = pd.concat([sparse3, sparse], sort=True) - exp = (pd.concat([self.dense3, self.dense1], sort=True) - .to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = (pd.concat([self.dense3, self.dense1], sort=True) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) # different fill values - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse(fill_value=0) # each columns keeps its fill_value, thus compare in dense res = pd.concat([sparse, sparse3], sort=True) exp = pd.concat([self.dense1, self.dense3], sort=True) @@ -340,71 +405,110 @@ def test_concat_different_columns_buggy(self): def test_concat_series(self): # fill_value = np.nan - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse() for col in ['A', 'D']: res = pd.concat([sparse, sparse2[col]]) - exp = pd.concat([self.dense1, self.dense2[col]]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense2[col]]).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) res = pd.concat([sparse2[col], sparse]) - exp = pd.concat([self.dense2[col], self.dense1]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2[col], self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) # fill_value = 0 - sparse = self.dense1.to_sparse(fill_value=0) - sparse2 = self.dense2.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse(fill_value=0) + sparse2 = self.dense2.to_sparse(fill_value=0) for col in ['C', 'D']: res = pd.concat([sparse, sparse2[col]]) - exp = pd.concat([self.dense1, - self.dense2[col]]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, + self.dense2[col]]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) res = pd.concat([sparse2[col], sparse]) - exp = pd.concat([self.dense2[col], - self.dense1]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense2[col], + self.dense1]).to_sparse(fill_value=0) exp['C'] = res['C'] exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True, check_kind=False) def test_concat_axis1(self): - # fill_value = np.nan - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + # fill_value = np.nan + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() res = pd.concat([sparse, sparse3], axis=1) - exp = pd.concat([self.dense1, self.dense3], axis=1).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense3], axis=1).to_sparse() tm.assert_sp_frame_equal(res, exp) res = pd.concat([sparse3, sparse], axis=1) - exp = pd.concat([self.dense3, self.dense1], axis=1).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense3, self.dense1], axis=1).to_sparse() exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) # fill_value = 0 - sparse = self.dense1.to_sparse(fill_value=0) - sparse3 = self.dense3.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse(fill_value=0) + sparse3 = self.dense3.to_sparse(fill_value=0) res = pd.concat([sparse, sparse3], axis=1) - exp = pd.concat([self.dense1, self.dense3], - axis=1).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense1, self.dense3], + axis=1).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) res = pd.concat([sparse3, sparse], axis=1) - exp = pd.concat([self.dense3, self.dense1], - axis=1).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = pd.concat([self.dense3, self.dense1], + axis=1).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) # different fill values - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse(fill_value=0) # each columns keeps its fill_value, thus compare in dense res = pd.concat([sparse, sparse3], axis=1) exp = pd.concat([self.dense1, self.dense3], axis=1) @@ -422,8 +526,12 @@ def test_concat_axis1(self): [1, 0])) def test_concat_sparse_dense_rows(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense2] - sparse_frame = [frames[dense_idx], - frames[sparse_idx].to_sparse(fill_value=fill_value)] + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_frame = [frames[dense_idx], + frames[sparse_idx] + .to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse @@ -449,8 +557,12 @@ def test_concat_sparse_dense_cols(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense3] - sparse_frame = [frames[dense_idx], - frames[sparse_idx].to_sparse(fill_value=fill_value)] + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse_frame = [frames[dense_idx], + frames[sparse_idx] + .to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse diff --git a/pandas/tests/sparse/test_format.py b/pandas/tests/sparse/test_format.py index 805f77eb21c2f..a0bc965031f33 100644 --- a/pandas/tests/sparse/test_format.py +++ b/pandas/tests/sparse/test_format.py @@ -13,7 +13,6 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesFormatting: @property @@ -21,7 +20,10 @@ def dtype_format_for_platform(self): return '' if use_32bit_repr else ', dtype=int32' def test_sparse_max_row(self): - s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() result = repr(s) dfm = self.dtype_format_for_platform exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n" @@ -31,7 +33,10 @@ def test_sparse_max_row(self): assert result == exp def test_sparsea_max_row_truncated(self): - s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() dfm = self.dtype_format_for_platform with option_context("display.max_rows", 3): @@ -46,8 +51,11 @@ def test_sparsea_max_row_truncated(self): def test_sparse_mi_max_row(self): idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), ('C', 0), ('C', 1), ('C', 2)]) - s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan], - index=idx).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan], + index=idx).to_sparse() result = repr(s) dfm = self.dtype_format_for_platform exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n" @@ -111,7 +119,6 @@ def test_sparse_int(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameFormatting: def test_sparse_frame(self): @@ -120,7 +127,10 @@ def test_sparse_frame(self): 'B': [True, False, True, False, True], 'C': [0, 0, 3, 0, 5], 'D': [np.nan, np.nan, np.nan, 1, 2]}) - sparse = df.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = df.to_sparse() assert repr(sparse) == repr(df) with option_context("display.max_rows", 3): diff --git a/pandas/tests/sparse/test_groupby.py b/pandas/tests/sparse/test_groupby.py index 531a4360c78a2..e72cfd381ccb3 100644 --- a/pandas/tests/sparse/test_groupby.py +++ b/pandas/tests/sparse/test_groupby.py @@ -6,7 +6,6 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseGroupBy: def setup_method(self, method): @@ -18,7 +17,10 @@ def setup_method(self, method): 'D': np.random.randn(8), 'E': [np.nan, np.nan, 1, 2, np.nan, 1, np.nan, np.nan]}) - self.sparse = self.dense.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.sparse = self.dense.to_sparse() def test_first_last_nth(self): # tests for first / last / nth @@ -29,9 +31,12 @@ def test_first_last_nth(self): sparse_grouped_last = sparse_grouped.last() sparse_grouped_nth = sparse_grouped.nth(1) - dense_grouped_first = dense_grouped.first().to_sparse() - dense_grouped_last = dense_grouped.last().to_sparse() - dense_grouped_nth = dense_grouped.nth(1).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + dense_grouped_first = dense_grouped.first().to_sparse() + dense_grouped_last = dense_grouped.last().to_sparse() + dense_grouped_nth = dense_grouped.nth(1).to_sparse() # TODO: shouldn't these all be spares or not? tm.assert_frame_equal(sparse_grouped_first, @@ -45,8 +50,11 @@ def test_aggfuncs(self): sparse_grouped = self.sparse.groupby('A') dense_grouped = self.dense.groupby('A') - result = sparse_grouped.mean().to_sparse() - expected = dense_grouped.mean().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = sparse_grouped.mean().to_sparse() + expected = dense_grouped.mean().to_sparse() tm.assert_frame_equal(result, expected) @@ -54,20 +62,28 @@ def test_aggfuncs(self): # tm.assert_frame_equal(sparse_grouped.sum(), # dense_grouped.sum()) - result = sparse_grouped.count().to_sparse() - expected = dense_grouped.count().to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = sparse_grouped.count().to_sparse() + expected = dense_grouped.count().to_sparse() tm.assert_frame_equal(result, expected) @pytest.mark.parametrize("fill_value", [0, np.nan]) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_groupby_includes_fill_value(fill_value): # https://github.com/pandas-dev/pandas/issues/5078 df = pd.DataFrame({'a': [fill_value, 1, fill_value, fill_value], 'b': [fill_value, 1, fill_value, fill_value]}) - sdf = df.to_sparse(fill_value=fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sdf = df.to_sparse(fill_value=fill_value) result = sdf.groupby('a').sum() - expected = df.groupby('a').sum().to_sparse(fill_value=fill_value) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = df.groupby('a').sum().to_sparse(fill_value=fill_value) tm.assert_frame_equal(result, expected, check_index_type=False) diff --git a/pandas/tests/sparse/test_indexing.py b/pandas/tests/sparse/test_indexing.py index c4f9d26ac556d..d6d5298adac06 100644 --- a/pandas/tests/sparse/test_indexing.py +++ b/pandas/tests/sparse/test_indexing.py @@ -7,12 +7,14 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesIndexing: def setup_method(self, method): self.orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - self.sparse = self.orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.sparse = self.orig.to_sparse() def test_getitem(self): orig = self.orig @@ -23,17 +25,26 @@ def test_getitem(self): assert sparse[3] == 3 result = sparse[[1, 3, 4]] - exp = orig[[1, 3, 4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -44,10 +55,13 @@ def test_getitem_slice(self): orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse[:2], orig[:2].to_sparse()) - tm.assert_sp_series_equal(sparse[4:2], orig[4:2].to_sparse()) - tm.assert_sp_series_equal(sparse[::2], orig[::2].to_sparse()) - tm.assert_sp_series_equal(sparse[-5:], orig[-5:].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse[:2], orig[:2].to_sparse()) + tm.assert_sp_series_equal(sparse[4:2], orig[4:2].to_sparse()) + tm.assert_sp_series_equal(sparse[::2], orig[::2].to_sparse()) + tm.assert_sp_series_equal(sparse[-5:], orig[-5:].to_sparse()) def test_getitem_int_dtype(self): # GH 8292 @@ -66,7 +80,10 @@ def test_getitem_int_dtype(self): def test_getitem_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse[0] == 1 assert np.isnan(sparse[1]) @@ -74,17 +91,26 @@ def test_getitem_fill_value(self): assert sparse[3] == 3 result = sparse[[1, 3, 4]] - exp = orig[[1, 3, 4]].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[[1, 3, 4]].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array @@ -101,15 +127,18 @@ def test_getitem_ellipsis(self): def test_getitem_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse[:2], - orig[:2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[4:2], - orig[4:2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[::2], - orig[::2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[-5:], - orig[-5:].to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse[:2], + orig[:2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[4:2], + orig[4:2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[::2], + orig[::2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[-5:], + orig[-5:].to_sparse(fill_value=0)) def test_loc(self): orig = self.orig @@ -119,24 +148,36 @@ def test_loc(self): assert np.isnan(sparse.loc[1]) result = sparse.loc[[1, 3, 4]] - exp = orig.loc[[1, 3, 4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # exceeds the bounds result = sparse.reindex([1, 3, 4, 5]) - exp = orig.reindex([1, 3, 4, 5]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex([1, 3, 4, 5]).to_sparse() tm.assert_sp_series_equal(result, exp) # padded with NaN assert np.isnan(result[-1]) # dense array result = sparse.loc[orig % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -145,23 +186,35 @@ def test_loc(self): def test_loc_index(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.loc['A'] == 1 assert np.isnan(sparse.loc['B']) result = sparse.loc[['A', 'C', 'D']] - exp = orig.loc[['A', 'C', 'D']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['A', 'C', 'D']].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -170,42 +223,63 @@ def test_loc_index(self): def test_loc_index_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse.loc['A'] == 1 assert np.isnan(sparse.loc['B']) result = sparse.loc[['A', 'C', 'D']] - exp = orig.loc[['A', 'C', 'D']].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['A', 'C', 'D']].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) def test_loc_slice(self): orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) def test_loc_slice_index_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse(fill_value=0)) def test_loc_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.loc[2:], - orig.loc[2:].to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse.loc[2:], + orig.loc[2:].to_sparse(fill_value=0)) def test_iloc(self): orig = self.orig @@ -215,11 +289,17 @@ def test_iloc(self): assert np.isnan(sparse.iloc[2]) result = sparse.iloc[[1, 3, 4]] - exp = orig.iloc[[1, 3, 4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) result = sparse.iloc[[1, -2, -4]] - exp = orig.iloc[[1, -2, -4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, -2, -4]].to_sparse() tm.assert_sp_series_equal(result, exp) with pytest.raises(IndexError): @@ -227,30 +307,46 @@ def test_iloc(self): def test_iloc_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse.iloc[3] == 3 assert np.isnan(sparse.iloc[1]) assert sparse.iloc[4] == 0 result = sparse.iloc[[1, 3, 4]] - exp = orig.iloc[[1, 3, 4]].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, 3, 4]].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) def test_iloc_slice(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.iloc[2:], orig.iloc[2:].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + tm.assert_sp_series_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse()) def test_iloc_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse(fill_value=0)) def test_at(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.at[0] == orig.at[0] assert np.isnan(sparse.at[1]) assert np.isnan(sparse.at[2]) @@ -259,7 +355,10 @@ def test_at(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('abcde')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.at['a'] == orig.at['a'] assert np.isnan(sparse.at['b']) assert np.isnan(sparse.at['c']) @@ -269,7 +368,10 @@ def test_at(self): def test_at_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('abcde')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse.at['a'] == orig.at['a'] assert np.isnan(sparse.at['b']) assert sparse.at['c'] == orig.at['c'] @@ -291,7 +393,10 @@ def test_iat(self): def test_iat_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.iat[0] == orig.iat[0] assert np.isnan(sparse.iat[1]) assert sparse.iat[2] == orig.iat[2] @@ -323,106 +428,172 @@ def test_get(self): def test_take(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - sparse = orig.to_sparse() - - tm.assert_sp_series_equal(sparse.take([0]), - orig.take([0]).to_sparse()) - tm.assert_sp_series_equal(sparse.take([0, 1, 3]), - orig.take([0, 1, 3]).to_sparse()) - tm.assert_sp_series_equal(sparse.take([-1, -2]), - orig.take([-1, -2]).to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + + tm.assert_sp_series_equal(sparse.take([0]), + orig.take([0]).to_sparse()) + tm.assert_sp_series_equal(sparse.take([0, 1, 3]), + orig.take([0, 1, 3]).to_sparse()) + tm.assert_sp_series_equal(sparse.take([-1, -2]), + orig.take([-1, -2]).to_sparse()) def test_take_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.take([0]), - orig.take([0]).to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse.take([0]), + orig.take([0]).to_sparse(fill_value=0)) - exp = orig.take([0, 1, 3]).to_sparse(fill_value=0) + exp = orig.take([0, 1, 3]).to_sparse(fill_value=0) tm.assert_sp_series_equal(sparse.take([0, 1, 3]), exp) - exp = orig.take([-1, -2]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.take([-1, -2]).to_sparse(fill_value=0) tm.assert_sp_series_equal(sparse.take([-1, -2]), exp) def test_reindex(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() res = sparse.reindex(['A', 'E', 'C', 'D']) - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() tm.assert_sp_series_equal(res, exp) # all missing & fill_value res = sparse.reindex(['B', 'E', 'C']) - exp = orig.reindex(['B', 'E', 'C']).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['B', 'E', 'C']).to_sparse() tm.assert_sp_series_equal(res, exp) orig = pd.Series([np.nan, np.nan, np.nan, np.nan, np.nan], index=list('ABCDE')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() res = sparse.reindex(['A', 'E', 'C', 'D']) - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() tm.assert_sp_series_equal(res, exp) def test_fill_value_reindex(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # includes missing and fill_value res = sparse.reindex(['A', 'B', 'C']) - exp = orig.reindex(['A', 'B', 'C']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'B', 'C']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # all missing orig = pd.Series([np.nan, np.nan, np.nan, np.nan, np.nan], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # all fill_value orig = pd.Series([0., 0., 0., 0., 0.], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) def test_fill_value_reindex_coerces_float_int(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) def test_reindex_fill_value(self): - floats = pd.Series([1., 2., 3.]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + floats = pd.Series([1., 2., 3.]).to_sparse() result = floats.reindex([1, 2, 3], fill_value=0) - expected = pd.Series([2., 3., 0], index=[1, 2, 3]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = pd.Series([2., 3., 0], index=[1, 2, 3]).to_sparse() tm.assert_sp_series_equal(result, expected) def test_reindex_nearest(self): - s = pd.Series(np.arange(10, dtype='float64')).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + s = pd.Series(np.arange(10, dtype='float64')).to_sparse() target = [0.1, 0.9, 1.5, 2.0] actual = s.reindex(target, method='nearest') - expected = pd.Series(np.around(target), target).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = pd.Series(np.around(target), target).to_sparse() tm.assert_sp_series_equal(expected, actual) actual = s.reindex(target, method='nearest', tolerance=0.2) - expected = pd.Series([0, 1, np.nan, 2], target).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = pd.Series([0, 1, np.nan, 2], target).to_sparse() tm.assert_sp_series_equal(expected, actual) actual = s.reindex(target, method='nearest', tolerance=[0.3, 0.01, 0.4, 3]) - expected = pd.Series([0, np.nan, np.nan, 2], target).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = pd.Series([0, np.nan, np.nan, 2], target).to_sparse() tm.assert_sp_series_equal(expected, actual) @pytest.mark.parametrize("kind", ["integer", "block"]) @@ -457,7 +628,6 @@ def tests_indexing_with_sparse(self, kind, fill): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesMultiIndexing(TestSparseSeriesIndexing): def setup_method(self, method): @@ -465,7 +635,10 @@ def setup_method(self, method): idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), ('C', 0), ('C', 1)]) self.orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=idx) - self.sparse = self.orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + self.sparse = self.orig.to_sparse() def test_getitem_multi(self): orig = self.orig @@ -475,21 +648,33 @@ def test_getitem_multi(self): assert np.isnan(sparse[1]) assert sparse[3] == orig[3] - tm.assert_sp_series_equal(sparse['A'], orig['A'].to_sparse()) - tm.assert_sp_series_equal(sparse['B'], orig['B'].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse['A'], orig['A'].to_sparse()) + tm.assert_sp_series_equal(sparse['B'], orig['B'].to_sparse()) result = sparse[[1, 3, 4]] - exp = orig[[1, 3, 4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - exp = orig[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -508,46 +693,70 @@ def test_getitems_slice_multi(self): orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse[2:], orig[2:].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], orig.loc['C':].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse[2:], orig[2:].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], + orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['A':'B'], - orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], orig.loc[:'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['A':'B'], + orig.loc['A':'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], + orig.loc[:'B'].to_sparse()) def test_loc(self): # need to be override to use different label orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse.loc['A'], - orig.loc['A'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B'], - orig.loc['B'].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse.loc['A'], + orig.loc['A'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B'], + orig.loc['B'].to_sparse()) result = sparse.loc[[1, 3, 4]] - exp = orig.loc[[1, 3, 4]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # exceeds the bounds result = sparse.loc[[1, 3, 4, 5]] - exp = orig.loc[[1, 3, 4, 5]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[1, 3, 4, 5]].to_sparse() tm.assert_sp_series_equal(result, exp) # single element list (GH 15447) result = sparse.loc[['A']] - exp = orig.loc[['A']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['A']].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - exp = orig.loc[orig % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -565,13 +774,20 @@ def test_loc_multi_tuple(self): def test_loc_slice(self): orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse.loc['A':], orig.loc['A':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], orig.loc['C':].to_sparse()) - - tm.assert_sp_series_equal(sparse.loc['A':'B'], - orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], orig.loc[:'B'].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse.loc['A':], + orig.loc['A':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], + orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse()) + + tm.assert_sp_series_equal(sparse.loc['A':'B'], + orig.loc['A':'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], + orig.loc[:'B'].to_sparse()) def test_reindex(self): # GH 15447 @@ -579,17 +795,26 @@ def test_reindex(self): sparse = self.sparse res = sparse.reindex([('A', 0), ('C', 1)]) - exp = orig.reindex([('A', 0), ('C', 1)]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex([('A', 0), ('C', 1)]).to_sparse() tm.assert_sp_series_equal(res, exp) # On specific level: res = sparse.reindex(['A', 'C', 'B'], level=0) - exp = orig.reindex(['A', 'C', 'B'], level=0).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B'], level=0).to_sparse() tm.assert_sp_series_equal(res, exp) # single element list (GH 15447) res = sparse.reindex(['A'], level=0) - exp = orig.reindex(['A'], level=0).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A'], level=0).to_sparse() tm.assert_sp_series_equal(res, exp) with pytest.raises(TypeError): @@ -598,14 +823,15 @@ def test_reindex(self): # "copy" argument: res = sparse.reindex(sparse.index, copy=True) - exp = orig.reindex(orig.index, copy=True).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(orig.index, copy=True).to_sparse() tm.assert_sp_series_equal(res, exp) assert sparse is not res @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseDataFrameIndexing: def test_getitem(self): @@ -614,18 +840,24 @@ def test_getitem(self): [np.nan, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse['x'], orig['x'].to_sparse()) - tm.assert_sp_frame_equal(sparse[['x']], orig[['x']].to_sparse()) - tm.assert_sp_frame_equal(sparse[['z', 'x']], - orig[['z', 'x']].to_sparse()) + tm.assert_sp_series_equal(sparse['x'], + orig['x'].to_sparse()) + tm.assert_sp_frame_equal(sparse[['x']], + orig[['x']].to_sparse()) + tm.assert_sp_frame_equal(sparse[['z', 'x']], + orig[['z', 'x']].to_sparse()) - tm.assert_sp_frame_equal(sparse[[True, False, True, True]], - orig[[True, False, True, True]].to_sparse()) + tm.assert_sp_frame_equal(sparse[[True, False, True, True]], + orig[[True, False, True, True]] + .to_sparse()) - tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], - orig.iloc[[1, 2]].to_sparse()) + tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], + orig.iloc[[1, 2]].to_sparse()) def test_getitem_fill_value(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -633,29 +865,50 @@ def test_getitem_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) result = sparse[['z']] - expected = orig[['z']].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + expected = orig[['z']].to_sparse(fill_value=0) tm.assert_sp_frame_equal(result, expected, check_fill_value=False) - tm.assert_sp_series_equal(sparse['y'], - orig['y'].to_sparse(fill_value=0)) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse['y'], + orig['y'].to_sparse(fill_value=0)) - exp = orig[['x']].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[['x']].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[['x']], exp) - exp = orig[['z', 'x']].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[['z', 'x']].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[['z', 'x']], exp) indexer = [True, False, True, True] - exp = orig[indexer].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig[indexer].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[indexer], exp) - exp = orig.iloc[[1, 2]].to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, 2]].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], exp) @@ -664,57 +917,84 @@ def test_loc(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.loc[0, 'x'] == 1 assert np.isnan(sparse.loc[1, 'z']) assert sparse.loc[2, 'z'] == 4 - # have to specify `kind='integer'`, since we construct a - # new SparseArray here, and the default sparse type is - # integer there, but block in SparseSeries - tm.assert_sp_series_equal(sparse.loc[0], - orig.loc[0].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[1], - orig.loc[1].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[2, :], - orig.loc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[2, :], - orig.loc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[:, 'y'], - orig.loc[:, 'y'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:, 'y'], - orig.loc[:, 'y'].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + # have to specify `kind='integer'`, since we construct a + # new SparseArray here, and the default sparse type is + # integer there, but block in SparseSeries + tm.assert_sp_series_equal(sparse.loc[0], + orig.loc[0].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[1], + orig.loc[1].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[2, :], + orig.loc[2, :].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[2, :], + orig.loc[2, :].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[:, 'y'], + orig.loc[:, 'y'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:, 'y'], + orig.loc[:, 'y'].to_sparse()) result = sparse.loc[[1, 2]] - exp = orig.loc[[1, 2]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[1, 2]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[[1, 2], :] - exp = orig.loc[[1, 2], :].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[1, 2], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[:, ['x', 'z']] - exp = orig.loc[:, ['x', 'z']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[:, ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[[0, 2], ['x', 'z']] - exp = orig.loc[[0, 2], ['x', 'z']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[[0, 2], ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) # exceeds the bounds result = sparse.reindex([1, 3, 4, 5]) - exp = orig.reindex([1, 3, 4, 5]).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex([1, 3, 4, 5]).to_sparse() tm.assert_sp_frame_equal(result, exp) # dense array result = sparse.loc[orig.x % 2 == 1] - exp = orig.loc[orig.x % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse.x % 2 == 1] - exp = orig.loc[orig.x % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array @@ -726,50 +1006,76 @@ def test_loc_index(self): [2, 3, np.nan], [np.nan, np.nan, 4]], index=list('abc'), columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.loc['a', 'x'] == 1 assert np.isnan(sparse.loc['b', 'z']) assert sparse.loc['c', 'z'] == 4 - tm.assert_sp_series_equal(sparse.loc['a'], - orig.loc['a'].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b'], - orig.loc['b'].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :].to_sparse(kind='integer')) - - tm.assert_sp_series_equal(sparse.loc[:, 'z'], - orig.loc[:, 'z'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:, 'z'], - orig.loc[:, 'z'].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse.loc['a'], + orig.loc['a'].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b'], + orig.loc['b'].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b', :], + orig.loc['b', :] + .to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b', :], + orig.loc['b', :] + .to_sparse(kind='integer')) + + tm.assert_sp_series_equal(sparse.loc[:, 'z'], + orig.loc[:, 'z'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:, 'z'], + orig.loc[:, 'z'].to_sparse()) result = sparse.loc[['a', 'b']] - exp = orig.loc[['a', 'b']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['a', 'b']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[['a', 'b'], :] - exp = orig.loc[['a', 'b'], :].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['a', 'b'], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[:, ['x', 'z']] - exp = orig.loc[:, ['x', 'z']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[:, ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[['c', 'a'], ['x', 'z']] - exp = orig.loc[['c', 'a'], ['x', 'z']].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[['c', 'a'], ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) # dense array result = sparse.loc[orig.x % 2 == 1] - exp = orig.loc[orig.x % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse.x % 2 == 1] - exp = orig.loc[orig.x % 2 == 1].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array @@ -781,45 +1087,68 @@ def test_loc_slice(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - sparse = orig.to_sparse() - tm.assert_sp_frame_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + tm.assert_sp_frame_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) def test_iloc(self): orig = pd.DataFrame([[1, np.nan, np.nan], [2, 3, np.nan], [np.nan, np.nan, 4]]) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.iloc[1, 1] == 3 assert np.isnan(sparse.iloc[2, 0]) - tm.assert_sp_series_equal(sparse.iloc[0], - orig.loc[0].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[1], - orig.loc[1].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[:, 1], - orig.iloc[:, 1].to_sparse()) - tm.assert_sp_series_equal(sparse.iloc[:, 1], - orig.iloc[:, 1].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + tm.assert_sp_series_equal(sparse.iloc[0], + orig.loc[0].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[1], + orig.loc[1].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[2, :], + orig.iloc[2, :] + .to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[2, :], + orig.iloc[2, :]. + to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[:, 1], + orig.iloc[:, 1].to_sparse()) + tm.assert_sp_series_equal(sparse.iloc[:, 1], + orig.iloc[:, 1].to_sparse()) result = sparse.iloc[[1, 2]] - exp = orig.iloc[[1, 2]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, 2]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[[1, 2], :] - exp = orig.iloc[[1, 2], :].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[1, 2], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[:, [1, 0]] - exp = orig.iloc[:, [1, 0]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[:, [1, 0]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[[2], [1, 0]] - exp = orig.iloc[[2], [1, 0]].to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.iloc[[2], [1, 0]].to_sparse() tm.assert_sp_frame_equal(result, exp) with pytest.raises(IndexError): @@ -830,8 +1159,12 @@ def test_iloc_slice(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - sparse = orig.to_sparse() - tm.assert_sp_frame_equal(sparse.iloc[2:], orig.iloc[2:].to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + tm.assert_sp_frame_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse()) def test_at(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -839,7 +1172,10 @@ def test_at(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.at['A', 'x'] == orig.at['A', 'x'] assert np.isnan(sparse.at['B', 'z']) assert np.isnan(sparse.at['C', 'y']) @@ -851,7 +1187,10 @@ def test_at_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse.at['A', 'x'] == orig.at['A', 'x'] assert np.isnan(sparse.at['B', 'z']) assert np.isnan(sparse.at['C', 'y']) @@ -863,7 +1202,10 @@ def test_iat(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() assert sparse.iat[0, 0] == orig.iat[0, 0] assert np.isnan(sparse.iat[1, 2]) assert np.isnan(sparse.iat[2, 1]) @@ -878,7 +1220,10 @@ def test_iat_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) assert sparse.iat[0, 0] == orig.iat[0, 0] assert np.isnan(sparse.iat[1, 2]) assert np.isnan(sparse.iat[2, 1]) @@ -893,14 +1238,17 @@ def test_take(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - sparse = orig.to_sparse() - - tm.assert_sp_frame_equal(sparse.take([0]), - orig.take([0]).to_sparse()) - tm.assert_sp_frame_equal(sparse.take([0, 1]), - orig.take([0, 1]).to_sparse()) - tm.assert_sp_frame_equal(sparse.take([-1, -2]), - orig.take([-1, -2]).to_sparse()) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() + + tm.assert_sp_frame_equal(sparse.take([0]), + orig.take([0]).to_sparse()) + tm.assert_sp_frame_equal(sparse.take([0, 1]), + orig.take([0, 1]).to_sparse()) + tm.assert_sp_frame_equal(sparse.take([-1, -2]), + orig.take([-1, -2]).to_sparse()) def test_take_fill_value(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -908,17 +1256,26 @@ def test_take_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) - exp = orig.take([0]).to_sparse(fill_value=0) + exp = orig.take([0]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([0]), exp) - exp = orig.take([0, 1]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.take([0, 1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([0, 1]), exp) - exp = orig.take([-1, -2]).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.take([-1, -2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([-1, -2]), exp) @@ -928,10 +1285,16 @@ def test_reindex(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() res = sparse.reindex(['A', 'C', 'B']) - exp = orig.reindex(['A', 'C', 'B']).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B']).to_sparse() tm.assert_sp_frame_equal(res, exp) orig = pd.DataFrame([[np.nan, np.nan, np.nan], @@ -939,10 +1302,16 @@ def test_reindex(self): [np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse() res = sparse.reindex(['A', 'C', 'B']) - exp = orig.reindex(['A', 'C', 'B']).to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B']).to_sparse() tm.assert_sp_frame_equal(res, exp) def test_reindex_fill_value(self): @@ -951,10 +1320,16 @@ def test_reindex_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) # all missing @@ -963,10 +1338,16 @@ def test_reindex_fill_value(self): [np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan]], index=list('ABCD'), columns=list('xyz')) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) # all fill_value @@ -976,10 +1357,16 @@ def test_reindex_fill_value(self): [0, 0, 0]], index=list('ABCD'), columns=list('xyz'), dtype=np.int) - sparse = orig.to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index f3965a7f4dda3..105702abc05ea 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -6,7 +6,6 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestPivotTable: def setup_method(self, method): @@ -18,7 +17,9 @@ def setup_method(self, method): 'D': np.random.randn(8), 'E': [np.nan, np.nan, 1, 2, np.nan, 1, np.nan, np.nan]}) - self.sparse = self.dense.to_sparse() + # GH 26557: DEPR + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): + self.sparse = self.dense.to_sparse() def test_pivot_table(self): res_sparse = pd.pivot_table(self.sparse, index='A', columns='B', diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index d64bb52cf5f83..e8d6b3bcaa77f 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -55,7 +55,6 @@ def setup_method(self, method): self.ymd.index.set_names(['year', 'month', 'day'], inplace=True) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestMultiLevel(Base): def test_append(self): @@ -675,7 +674,6 @@ def test_unstack_multiple_hierarchical(self): # it works! df.unstack(['b', 'c']) - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_groupby_transform(self): s = self.frame['A'] grouper = s.index.get_level_values(0) @@ -891,7 +889,6 @@ def test_count(self): with pytest.raises(KeyError, match=msg): frame.count(level='x') - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize('op', AGG_FUNCTIONS) @pytest.mark.parametrize('level', [0, 1]) @pytest.mark.parametrize('skipna', [True, False]) @@ -966,7 +963,6 @@ def test_frame_any_all_group(self): ex = DataFrame({'data': [False, False]}, index=['one', 'two']) tm.assert_frame_equal(result, ex) - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") def test_std_var_pass_ddof(self): index = MultiIndex.from_arrays([np.arange(5).repeat(10), np.tile( np.arange(10), 5)]) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index e4c78b3424bda..bc6946cbade4c 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -316,7 +316,6 @@ def test_preserve_metadata(self): assert s2.name == 'foo' assert s3.name == 'foo' - @pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") @pytest.mark.parametrize("func,window_size,expected_vals", [ ('rolling', 2, [[np.nan, np.nan, np.nan, np.nan], [15., 20., 25., 20.], @@ -419,7 +418,6 @@ def test_numpy_compat(self, method): getattr(w, method)(dtype=np.float64) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestRolling(Base): def setup_method(self, method): @@ -3295,7 +3293,6 @@ def test_rolling_min_max_numeric_types(self): assert result.dtypes[0] == np.dtype("f8") -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestGrouperGrouping: def setup_method(self, method): @@ -3465,7 +3462,6 @@ def test_expanding_apply(self, raw): tm.assert_frame_equal(result, expected) -@pytest.mark.filterwarnings("ignore:NDFrame.to_dense:FutureWarning") class TestRollingTS: # rolling time-series friendly From 104c12a684c4354216415c2acbbb49865a8dc246 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 13:53:30 +0530 Subject: [PATCH 19/33] Remove filterwarning from test_hist_method.py --- pandas/tests/plotting/test_hist_method.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 5fd2510d8a96f..f3f6c9c7fc2d4 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -261,7 +261,6 @@ def test_tight_layout(self): @td.skip_if_no_mpl -@pytest.mark.filterwarnings('ignore::FutureWarning') class TestDataFrameGroupByPlots(TestPlotBase): @pytest.mark.slow From e713fb02661537792f6d8f810d71582f77f7c43c Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 14:26:16 +0530 Subject: [PATCH 20/33] Update sparsearray test_arithmetics warning --- pandas/tests/arrays/sparse/test_arithmetics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index eb3af4e6dea73..31a8f13571d16 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -9,6 +9,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseArrayArithmetics: _base = np.array From 587b14ffd5146cf44b71730833e082b1dcfb56de Mon Sep 17 00:00:00 2001 From: Vikramjeet Das <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 14:39:56 +0530 Subject: [PATCH 21/33] Remove filterwarning from test_decimal.py --- pandas/tests/extension/decimal/test_decimal.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index a1225939117f7..97fae41bcc720 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -191,7 +191,6 @@ class TestCasting(BaseDecimal, base.BaseCastingTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BaseDecimal, base.BaseGroupbyTests): pass From 131867675f0db0782a0f4dc81740c6d154e9f5e6 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 14:45:30 +0530 Subject: [PATCH 22/33] Beautify --- pandas/tests/extension/decimal/test_decimal.py | 1 - pandas/tests/sparse/frame/test_frame.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/extension/decimal/test_decimal.py b/pandas/tests/extension/decimal/test_decimal.py index a1225939117f7..97fae41bcc720 100644 --- a/pandas/tests/extension/decimal/test_decimal.py +++ b/pandas/tests/extension/decimal/test_decimal.py @@ -191,7 +191,6 @@ class TestCasting(BaseDecimal, base.BaseCastingTests): pass -@pytest.mark.filterwarnings("ignore:NDFrame:FutureWarning") class TestGroupby(BaseDecimal, base.BaseGroupbyTests): pass diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index d661ba3378870..afb98d7a5d87b 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -204,7 +204,7 @@ def test_constructor_from_series(self): # TODO: y_sparse is unsused...fix # GH 26557: DEPR with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - y_sparse = y.to_sparse(fill_value=0) # noqa + y_sparse = y.to_sparse(fill_value=0) # noqa # without sparse value raises error # df2 = SparseDataFrame([x2_sparse, y]) From 58c678a53805ff42c1c1b46668bc7c067e0050b1 Mon Sep 17 00:00:00 2001 From: Vikramjeet Das <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 14:52:21 +0530 Subject: [PATCH 23/33] Beautify --- pandas/tests/sparse/frame/test_frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index d661ba3378870..afb98d7a5d87b 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -204,7 +204,7 @@ def test_constructor_from_series(self): # TODO: y_sparse is unsused...fix # GH 26557: DEPR with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - y_sparse = y.to_sparse(fill_value=0) # noqa + y_sparse = y.to_sparse(fill_value=0) # noqa # without sparse value raises error # df2 = SparseDataFrame([x2_sparse, y]) From 0c8f2874d6b4a61accbced7fdd343e20aa863c47 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 15:21:36 +0530 Subject: [PATCH 24/33] Update test warnings --- pandas/tests/series/test_api.py | 1 + pandas/tests/sparse/series/test_series.py | 1 + 2 files changed, 2 insertions(+) diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 9cfce092255a1..15005d823528c 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -87,6 +87,7 @@ def test_binop_maybe_preserve_name(self): result = getattr(s, op)(cp) assert result.name is None + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_combine_first_name(self): result = self.ts.combine_first(self.ts[:5]) assert result.name == self.ts.name diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 9d744144a94e0..b7bfa0d7fcea4 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -587,6 +587,7 @@ def test_setslice(self): Series(7., index=range(5, 10), name=self.bseries.name)) + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_operators(self): def _check_op(a, b, op): From a8f6c5658ddecac8fb5ad067cb797d9fffae918d Mon Sep 17 00:00:00 2001 From: Vikramjeet Das <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 17:23:58 +0530 Subject: [PATCH 25/33] Update pandas/core/generic.py Update DataFrame/Series.to_dense deprecation message Co-Authored-By: Joris Van den Bossche --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1201c1dcbf46c..ee98e0bffcc21 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1971,7 +1971,7 @@ def to_dense(self): %(klass)s Dense %(klass)s. """ - warnings.warn("NDFrame.to_dense is deprecated " + warnings.warn("DataFrame/Series.to_dense is deprecated " "and will be removed in a future version", FutureWarning, stacklevel=2) # compat From 6a6e333bfecd5302c0e8b5a410029dbdd7590ee8 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 21:37:29 +0530 Subject: [PATCH 26/33] Update test time warnings and rectify df/series.to_sparse double warnings --- pandas/core/frame.py | 8 +- pandas/core/series.py | 8 +- pandas/core/sparse/series.py | 2 + pandas/tests/frame/test_deprecations.py | 3 + pandas/tests/generic/test_generic.py | 1 + pandas/tests/io/json/test_pandas.py | 12 +- pandas/tests/io/test_packers.py | 32 +- pandas/tests/io/test_pytables.py | 44 +- pandas/tests/series/test_api.py | 6 +- pandas/tests/series/test_combine_concat.py | 22 +- pandas/tests/series/test_deprecations.py | 3 + pandas/tests/series/test_missing.py | 37 +- pandas/tests/sparse/frame/test_frame.py | 4 +- pandas/tests/sparse/series/test_series.py | 3 + pandas/tests/sparse/test_combine_concat.py | 208 ++--- pandas/tests/sparse/test_groupby.py | 29 +- pandas/tests/sparse/test_indexing.py | 858 ++++++--------------- pandas/tests/sparse/test_pivot.py | 5 +- 18 files changed, 380 insertions(+), 905 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9e8af3d88cfd8..6746844f4b1fa 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1945,9 +1945,11 @@ def to_sparse(self, fill_value=None, kind='block'): "in a future version", FutureWarning, stacklevel=2) from pandas.core.sparse.api import SparseDataFrame - return SparseDataFrame(self._series, index=self.index, - columns=self.columns, default_kind=kind, - default_fill_value=fill_value) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", message="SparseDataFrame") + return SparseDataFrame(self._series, index=self.index, + columns=self.columns, default_kind=kind, + default_fill_value=fill_value) @deprecate_kwarg(old_arg_name='encoding', new_arg_name=None) def to_stata(self, fname, convert_dates=None, write_index=True, diff --git a/pandas/core/series.py b/pandas/core/series.py index 405fa6615d815..c4a449154860f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1611,9 +1611,11 @@ def to_sparse(self, kind='block', fill_value=None): from pandas.core.sparse.series import SparseSeries values = SparseArray(self, kind=kind, fill_value=fill_value) - return SparseSeries( - values, index=self.index, name=self.name - ).__finalize__(self) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", message="SparseSeries") + return SparseSeries( + values, index=self.index, name=self.name + ).__finalize__(self) def _set_name(self, name, inplace=False): """ diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index c3b78f381facc..02032ba1e4d01 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -431,7 +431,9 @@ def _set_values(self, key, value): def to_dense(self): """ Convert SparseSeries to a Series. + .. deprecated:: 0.25.0 + Returns ------- s : Series diff --git a/pandas/tests/frame/test_deprecations.py b/pandas/tests/frame/test_deprecations.py index 03c9f0d6ed107..ef78a0eaf9c5b 100644 --- a/pandas/tests/frame/test_deprecations.py +++ b/pandas/tests/frame/test_deprecations.py @@ -7,6 +7,9 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_deprecated_to_sparse(): + # GH 26557 + # Deprecated 0.25.0 + df = pd.DataFrame({"A": [1, np.nan, 3]}) sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index bcf6d6ba2cd86..b1a083213debd 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -920,6 +920,7 @@ def test_axis_classmethods(self, box): box._get_block_manager_axis(v) def test_deprecated_to_dense(self): + # GH 26557: DEPR # Deprecated 0.25.0 df = pd.DataFrame({"A": [1, 2, 3]}) diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index 47c00018f170c..a935a731ccba6 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1013,24 +1013,20 @@ def test_datetime_tz(self): assert stz.to_json() == s_naive.to_json() @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_sparse(self): # GH4377 df.to_json segfaults with non-ndarray blocks df = pd.DataFrame(np.random.randn(10, 4)) df.loc[:8] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() expected = df.to_json() assert expected == sdf.to_json() s = pd.Series(np.random.randn(10)) s.loc[:8] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s.to_sparse() + ss = s.to_sparse() expected = s.to_json() assert expected == ss.to_json() diff --git a/pandas/tests/io/test_packers.py b/pandas/tests/io/test_packers.py index bb8d6d415c123..9337d5916acc6 100644 --- a/pandas/tests/io/test_packers.py +++ b/pandas/tests/io/test_packers.py @@ -551,6 +551,8 @@ def test_dataframe_duplicate_column_names(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparse(TestPackers): def _check_roundtrip(self, obj, comparator, **kwargs): @@ -566,24 +568,15 @@ def test_sparse_series(self): s = tm.makeStringSeries() s[3:5] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s.to_sparse() + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_series_equal, check_series_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss2 = s.to_sparse(kind='integer') + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_series_equal, check_series_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss3 = s.to_sparse(fill_value=0) + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_series_equal, check_series_type=True) @@ -592,25 +585,16 @@ def test_sparse_frame(self): s = tm.makeDataFrame() s.loc[3:5, 1:3] = np.nan s.loc[8:10, -2] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s.to_sparse() + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_frame_equal, check_frame_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss2 = s.to_sparse(kind='integer') + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_frame_equal, check_frame_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss3 = s.to_sparse(fill_value=0) + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_frame_equal, check_frame_type=True) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 3366e3f4672d9..8dc44faeec493 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -51,6 +51,12 @@ "ignore:object name:tables.exceptions.NaturalNameWarning" ) ignore_sparse = pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +ignore_dataframe_tosparse = pytest.mark.filterwarnings( + "ignore:DataFrame.to_sparse:FutureWarning" +) +ignore_series_tosparse = pytest.mark.filterwarnings( + "ignore:Series.to_sparse:FutureWarning" +) # contextmanager to ensure the file cleanup @@ -2245,56 +2251,40 @@ def test_series(self): check_index_type=False) @ignore_sparse + @ignore_series_tosparse def test_sparse_series(self): s = tm.makeStringSeries() s.iloc[3:5] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s.to_sparse() + ss = s.to_sparse() self._check_roundtrip(ss, tm.assert_series_equal, check_series_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss2 = s.to_sparse(kind='integer') + ss2 = s.to_sparse(kind='integer') self._check_roundtrip(ss2, tm.assert_series_equal, check_series_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss3 = s.to_sparse(fill_value=0) + ss3 = s.to_sparse(fill_value=0) self._check_roundtrip(ss3, tm.assert_series_equal, check_series_type=True) @ignore_sparse + @ignore_dataframe_tosparse def test_sparse_frame(self): s = tm.makeDataFrame() s.iloc[3:5, 1:3] = np.nan s.iloc[8:10, -2] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s.to_sparse() + ss = s.to_sparse() self._check_double_roundtrip(ss, tm.assert_frame_equal, check_frame_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss2 = s.to_sparse(kind='integer') + ss2 = s.to_sparse(kind='integer') self._check_double_roundtrip(ss2, tm.assert_frame_equal, check_frame_type=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss3 = s.to_sparse(fill_value=0) + ss3 = s.to_sparse(fill_value=0) self._check_double_roundtrip(ss3, tm.assert_frame_equal, check_frame_type=True) @@ -2619,16 +2609,14 @@ def test_overwrite_node(self): tm.assert_series_equal(store['a'], ts) @ignore_sparse + @ignore_dataframe_tosparse def test_sparse_with_compression(self): # GH 2931 # make sparse dataframe arr = np.random.binomial(n=1, p=.01, size=(1000, 10)) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - df = DataFrame(arr).to_sparse(fill_value=0) + df = DataFrame(arr).to_sparse(fill_value=0) # case 1: store uncompressed self._check_double_roundtrip(df, tm.assert_frame_equal, diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 7db45469cf52d..63725416740b5 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -124,11 +124,9 @@ def test_sort_index_name(self): assert result.name == self.ts.name @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_to_sparse_pass_name(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = self.ts.to_sparse() + result = self.ts.to_sparse() assert result.name == self.ts.name def test_constructor_dict(self): diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index b1856c0dc943c..d03c29ad79469 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -212,6 +212,7 @@ def test_combine_first_dt_tz_values(self, tz_naive_fixture): assert_series_equal(exp, result) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_concat_empty_series_dtypes(self): # booleans @@ -244,22 +245,16 @@ def test_concat_empty_series_dtypes(self): # sparse # TODO: move? - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='float64').to_sparse()]) + result = pd.concat([Series(dtype='float64').to_sparse(), + Series(dtype='float64').to_sparse()]) assert result.dtype == 'Sparse[float64]' # GH 26705 - Assert .ftype is deprecated with tm.assert_produces_warning(FutureWarning): assert result.ftype == 'float64:sparse' - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='float64')]) + result = pd.concat([Series(dtype='float64').to_sparse(), + Series(dtype='float64')]) # TODO: release-note: concat sparse dtype expected = pd.core.sparse.api.SparseDtype(np.float64) assert result.dtype == expected @@ -268,11 +263,8 @@ def test_concat_empty_series_dtypes(self): with tm.assert_produces_warning(FutureWarning): assert result.ftype == 'float64:sparse' - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = pd.concat([Series(dtype='float64').to_sparse(), Series( - dtype='object')]) + result = pd.concat([Series(dtype='float64').to_sparse(), + Series(dtype='object')]) # TODO: release-note: concat sparse dtype expected = pd.core.sparse.api.SparseDtype('object') assert result.dtype == expected diff --git a/pandas/tests/series/test_deprecations.py b/pandas/tests/series/test_deprecations.py index a539558166e3f..635ef22b4f8ea 100644 --- a/pandas/tests/series/test_deprecations.py +++ b/pandas/tests/series/test_deprecations.py @@ -8,6 +8,9 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_deprecated_to_sparse(): + # GH 26557 + # Deprecated 0.25.0 + ser = Series([1, np.nan, 3]) sparse_ser = pd.SparseSeries([1, np.nan, 3]) diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index ed6c1d7376ba8..5328a58e3fbff 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -781,14 +781,12 @@ def test_series_fillna_limit(self): assert_series_equal(result, expected) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_sparse_series_fillna_limit(self): index = np.arange(10) s = Series(np.random.randn(10), index=index) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s[:2].reindex(index).to_sparse() + ss = s[:2].reindex(index).to_sparse() # TODO: what is this test doing? why are result an expected # the same call to fillna? with tm.assert_produces_warning(PerformanceWarning, @@ -798,36 +796,25 @@ def test_sparse_series_fillna_limit(self): expected = ss.fillna(method='pad', limit=5) expected = expected.to_dense() expected[-3:] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() assert_series_equal(result, expected) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = s[-2:].reindex(index).to_sparse() + ss = s[-2:].reindex(index).to_sparse() with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): result = ss.fillna(method='backfill', limit=5) expected = ss.fillna(method='backfill') expected = expected.to_dense() expected[:3] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() assert_series_equal(result, expected) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_sparse_series_pad_backfill_limit(self): index = np.arange(10) s = Series(np.random.randn(10), index=index) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = s.to_sparse() + s = s.to_sparse() result = s[:2].reindex(index, method='pad', limit=5) with tm.assert_produces_warning(PerformanceWarning, @@ -835,10 +822,7 @@ def test_sparse_series_pad_backfill_limit(self): expected = s[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected[-3:] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() assert_series_equal(result, expected) result = s[-2:].reindex(index, method='backfill', limit=5) @@ -847,10 +831,7 @@ def test_sparse_series_pad_backfill_limit(self): expected = s[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected[:3] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() assert_series_equal(result, expected) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index afb98d7a5d87b..e42191d6400b5 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -1503,9 +1503,11 @@ def test_dropna(self, inplace, how): def test_deprecated_to_dense(): + # GH 26557 + # Deprecated 0.25.0 + df = pd.DataFrame({"A": [1, np.nan, 3]}) - # Deprecated 0.25.0 with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 22c578e999db3..3b15ef11851b1 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1648,6 +1648,9 @@ def test_block_deprecated(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_deprecate_to_dense(): + # GH 26557 + # Deprecated 0.25.0 + ser = pd.Series([1, 2, 3]) sparse_ser = pd.SparseSeries([1, 2, 3]) diff --git a/pandas/tests/sparse/test_combine_concat.py b/pandas/tests/sparse/test_combine_concat.py index 92537cd8710ba..25d54dd4edd43 100644 --- a/pandas/tests/sparse/test_combine_concat.py +++ b/pandas/tests/sparse/test_combine_concat.py @@ -180,6 +180,7 @@ def test_concat_sparse_dense(self, kind): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameConcat: def setup_method(self, method): @@ -201,112 +202,70 @@ def setup_method(self, method): def test_concat(self): # fill_value = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse() + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse() res = pd.concat([sparse, sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense1]).to_sparse() + exp = pd.concat([self.dense1, self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse2]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2, self.dense2]).to_sparse() + exp = pd.concat([self.dense2, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse, sparse2]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense2]).to_sparse() + exp = pd.concat([self.dense1, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2, self.dense1]).to_sparse() + exp = pd.concat([self.dense2, self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) # fill_value = 0 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse(fill_value=0) - sparse2 = self.dense2.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse(fill_value=0) + sparse2 = self.dense2.to_sparse(fill_value=0) res = pd.concat([sparse, sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense1]).to_sparse(fill_value=0) + exp = pd.concat([self.dense1, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse2]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2, self.dense2]).to_sparse(fill_value=0) + exp = pd.concat([self.dense2, self.dense2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse, sparse2]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense2]).to_sparse(fill_value=0) + exp = pd.concat([self.dense1, self.dense2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) res = pd.concat([sparse2, sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) + exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) def test_concat_different_fill_value(self): # 1st fill_value will be used - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse(fill_value=0) with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): res = pd.concat([sparse, sparse2]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense2]).to_sparse() + exp = pd.concat([self.dense1, self.dense2]).to_sparse() tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) with tm.assert_produces_warning(PerformanceWarning, raise_on_extra_warnings=False): res = pd.concat([sparse2, sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) + exp = pd.concat([self.dense2, self.dense1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True) def test_concat_different_columns_sort_warns(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() # stacklevel is wrong since we have two FutureWarnings, # one for depr, one for sorting. @@ -319,32 +278,20 @@ def test_concat_different_columns_sort_warns(self): raise_on_extra_warnings=False,): exp = pd.concat([self.dense1, self.dense3]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = exp.to_sparse() + exp = exp.to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) def test_concat_different_columns(self): # fill_value = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() res = pd.concat([sparse, sparse3], sort=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense3], sort=True).to_sparse() + exp = pd.concat([self.dense1, self.dense3], sort=True).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) res = pd.concat([sparse3, sparse], sort=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense3, self.dense1], sort=True).to_sparse() + exp = pd.concat([self.dense3, self.dense1], sort=True).to_sparse() exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False) @@ -359,39 +306,27 @@ def test_concat_bug(self): tm.assert_frame_equal(res, exp) def test_concat_different_columns_buggy(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse(fill_value=0) - sparse3 = self.dense3.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse(fill_value=0) + sparse3 = self.dense3.to_sparse(fill_value=0) res = pd.concat([sparse, sparse3], sort=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = (pd.concat([self.dense1, self.dense3], sort=True) - .to_sparse(fill_value=0)) + exp = (pd.concat([self.dense1, self.dense3], sort=True) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) res = pd.concat([sparse3, sparse], sort=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = (pd.concat([self.dense3, self.dense1], sort=True) - .to_sparse(fill_value=0)) + exp = (pd.concat([self.dense3, self.dense1], sort=True) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) # different fill values - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse(fill_value=0) # each columns keeps its fill_value, thus compare in dense res = pd.concat([sparse, sparse3], sort=True) exp = pd.concat([self.dense1, self.dense3], sort=True) @@ -405,11 +340,8 @@ def test_concat_different_columns_buggy(self): def test_concat_series(self): # fill_value = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse2 = self.dense2.to_sparse() + sparse = self.dense1.to_sparse() + sparse2 = self.dense2.to_sparse() for col in ['A', 'D']: res = pd.concat([sparse, sparse2[col]]) @@ -427,11 +359,8 @@ def test_concat_series(self): tm.assert_sp_frame_equal(res, exp, check_kind=False) # fill_value = 0 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse(fill_value=0) - sparse2 = self.dense2.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse(fill_value=0) + sparse2 = self.dense2.to_sparse(fill_value=0) for col in ['C', 'D']: res = pd.concat([sparse, sparse2[col]]) @@ -456,59 +385,38 @@ def test_concat_series(self): check_kind=False) def test_concat_axis1(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - # fill_value = np.nan - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse() + # fill_value = np.nan + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse() res = pd.concat([sparse, sparse3], axis=1) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense3], axis=1).to_sparse() + exp = pd.concat([self.dense1, self.dense3], axis=1).to_sparse() tm.assert_sp_frame_equal(res, exp) res = pd.concat([sparse3, sparse], axis=1) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense3, self.dense1], axis=1).to_sparse() + exp = pd.concat([self.dense3, self.dense1], axis=1).to_sparse() exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) # fill_value = 0 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse(fill_value=0) - sparse3 = self.dense3.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse(fill_value=0) + sparse3 = self.dense3.to_sparse(fill_value=0) res = pd.concat([sparse, sparse3], axis=1) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense3], - axis=1).to_sparse(fill_value=0) + exp = pd.concat([self.dense1, self.dense3], + axis=1).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) res = pd.concat([sparse3, sparse], axis=1) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense3, self.dense1], - axis=1).to_sparse(fill_value=0) + exp = pd.concat([self.dense3, self.dense1], + axis=1).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp) # different fill values - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = self.dense1.to_sparse() - sparse3 = self.dense3.to_sparse(fill_value=0) + sparse = self.dense1.to_sparse() + sparse3 = self.dense3.to_sparse(fill_value=0) # each columns keeps its fill_value, thus compare in dense res = pd.concat([sparse, sparse3], axis=1) exp = pd.concat([self.dense1, self.dense3], axis=1) @@ -526,12 +434,9 @@ def test_concat_axis1(self): [1, 0])) def test_concat_sparse_dense_rows(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense2] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_frame = [frames[dense_idx], - frames[sparse_idx] - .to_sparse(fill_value=fill_value)] + sparse_frame = [frames[dense_idx], + frames[sparse_idx] + .to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse @@ -557,12 +462,9 @@ def test_concat_sparse_dense_cols(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense3] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_frame = [frames[dense_idx], - frames[sparse_idx] - .to_sparse(fill_value=fill_value)] + sparse_frame = [frames[dense_idx], + frames[sparse_idx] + .to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse diff --git a/pandas/tests/sparse/test_groupby.py b/pandas/tests/sparse/test_groupby.py index e72cfd381ccb3..1b73270531d0f 100644 --- a/pandas/tests/sparse/test_groupby.py +++ b/pandas/tests/sparse/test_groupby.py @@ -6,6 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseGroupBy: def setup_method(self, method): @@ -17,10 +18,7 @@ def setup_method(self, method): 'D': np.random.randn(8), 'E': [np.nan, np.nan, 1, 2, np.nan, 1, np.nan, np.nan]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - self.sparse = self.dense.to_sparse() + self.sparse = self.dense.to_sparse() def test_first_last_nth(self): # tests for first / last / nth @@ -31,12 +29,9 @@ def test_first_last_nth(self): sparse_grouped_last = sparse_grouped.last() sparse_grouped_nth = sparse_grouped.nth(1) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - dense_grouped_first = dense_grouped.first().to_sparse() - dense_grouped_last = dense_grouped.last().to_sparse() - dense_grouped_nth = dense_grouped.nth(1).to_sparse() + dense_grouped_first = dense_grouped.first().to_sparse() + dense_grouped_last = dense_grouped.last().to_sparse() + dense_grouped_nth = dense_grouped.nth(1).to_sparse() # TODO: shouldn't these all be spares or not? tm.assert_frame_equal(sparse_grouped_first, @@ -50,11 +45,8 @@ def test_aggfuncs(self): sparse_grouped = self.sparse.groupby('A') dense_grouped = self.dense.groupby('A') - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = sparse_grouped.mean().to_sparse() - expected = dense_grouped.mean().to_sparse() + result = sparse_grouped.mean().to_sparse() + expected = dense_grouped.mean().to_sparse() tm.assert_frame_equal(result, expected) @@ -62,11 +54,8 @@ def test_aggfuncs(self): # tm.assert_frame_equal(sparse_grouped.sum(), # dense_grouped.sum()) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = sparse_grouped.count().to_sparse() - expected = dense_grouped.count().to_sparse() + result = sparse_grouped.count().to_sparse() + expected = dense_grouped.count().to_sparse() tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/sparse/test_indexing.py b/pandas/tests/sparse/test_indexing.py index d6d5298adac06..d7cc49884f7cf 100644 --- a/pandas/tests/sparse/test_indexing.py +++ b/pandas/tests/sparse/test_indexing.py @@ -7,14 +7,12 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesIndexing: def setup_method(self, method): self.orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - self.sparse = self.orig.to_sparse() + self.sparse = self.orig.to_sparse() def test_getitem(self): orig = self.orig @@ -25,26 +23,17 @@ def test_getitem(self): assert sparse[3] == 3 result = sparse[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[[1, 3, 4]].to_sparse() + exp = orig[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse() + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse() + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -55,13 +44,10 @@ def test_getitem_slice(self): orig = self.orig sparse = self.sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse[:2], orig[:2].to_sparse()) - tm.assert_sp_series_equal(sparse[4:2], orig[4:2].to_sparse()) - tm.assert_sp_series_equal(sparse[::2], orig[::2].to_sparse()) - tm.assert_sp_series_equal(sparse[-5:], orig[-5:].to_sparse()) + tm.assert_sp_series_equal(sparse[:2], orig[:2].to_sparse()) + tm.assert_sp_series_equal(sparse[4:2], orig[4:2].to_sparse()) + tm.assert_sp_series_equal(sparse[::2], orig[::2].to_sparse()) + tm.assert_sp_series_equal(sparse[-5:], orig[-5:].to_sparse()) def test_getitem_int_dtype(self): # GH 8292 @@ -80,10 +66,7 @@ def test_getitem_int_dtype(self): def test_getitem_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse[0] == 1 assert np.isnan(sparse[1]) @@ -91,26 +74,17 @@ def test_getitem_fill_value(self): assert sparse[3] == 3 result = sparse[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[[1, 3, 4]].to_sparse(fill_value=0) + exp = orig[[1, 3, 4]].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse(fill_value=0) + exp = orig[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse(fill_value=0) + exp = orig[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array @@ -127,18 +101,15 @@ def test_getitem_ellipsis(self): def test_getitem_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse[:2], - orig[:2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[4:2], - orig[4:2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[::2], - orig[::2].to_sparse(fill_value=0)) - tm.assert_sp_series_equal(sparse[-5:], - orig[-5:].to_sparse(fill_value=0)) + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse[:2], + orig[:2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[4:2], + orig[4:2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[::2], + orig[::2].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse[-5:], + orig[-5:].to_sparse(fill_value=0)) def test_loc(self): orig = self.orig @@ -148,36 +119,24 @@ def test_loc(self): assert np.isnan(sparse.loc[1]) result = sparse.loc[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[1, 3, 4]].to_sparse() + exp = orig.loc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # exceeds the bounds result = sparse.reindex([1, 3, 4, 5]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex([1, 3, 4, 5]).to_sparse() + exp = orig.reindex([1, 3, 4, 5]).to_sparse() tm.assert_sp_series_equal(result, exp) # padded with NaN assert np.isnan(result[-1]) # dense array result = sparse.loc[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -186,35 +145,23 @@ def test_loc(self): def test_loc_index(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.loc['A'] == 1 assert np.isnan(sparse.loc['B']) result = sparse.loc[['A', 'C', 'D']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['A', 'C', 'D']].to_sparse() + exp = orig.loc[['A', 'C', 'D']].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -223,63 +170,42 @@ def test_loc_index(self): def test_loc_index_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse.loc['A'] == 1 assert np.isnan(sparse.loc['B']) result = sparse.loc[['A', 'C', 'D']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['A', 'C', 'D']].to_sparse(fill_value=0) + exp = orig.loc[['A', 'C', 'D']].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) + exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) + exp = orig.loc[orig % 2 == 1].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) def test_loc_slice(self): orig = self.orig sparse = self.sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) def test_loc_slice_index_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse(fill_value=0)) def test_loc_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.loc[2:], - orig.loc[2:].to_sparse(fill_value=0)) + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse.loc[2:], + orig.loc[2:].to_sparse(fill_value=0)) def test_iloc(self): orig = self.orig @@ -289,17 +215,11 @@ def test_iloc(self): assert np.isnan(sparse.iloc[2]) result = sparse.iloc[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, 3, 4]].to_sparse() + exp = orig.iloc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) result = sparse.iloc[[1, -2, -4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, -2, -4]].to_sparse() + exp = orig.iloc[[1, -2, -4]].to_sparse() tm.assert_sp_series_equal(result, exp) with pytest.raises(IndexError): @@ -307,46 +227,31 @@ def test_iloc(self): def test_iloc_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse.iloc[3] == 3 assert np.isnan(sparse.iloc[1]) assert sparse.iloc[4] == 0 result = sparse.iloc[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, 3, 4]].to_sparse(fill_value=0) + exp = orig.iloc[[1, 3, 4]].to_sparse(fill_value=0) tm.assert_sp_series_equal(result, exp) def test_iloc_slice(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse()) + sparse = orig.to_sparse() + tm.assert_sp_series_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse()) def test_iloc_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse(fill_value=0)) + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse(fill_value=0)) def test_at(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.at[0] == orig.at[0] assert np.isnan(sparse.at[1]) assert np.isnan(sparse.at[2]) @@ -355,10 +260,7 @@ def test_at(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('abcde')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.at['a'] == orig.at['a'] assert np.isnan(sparse.at['b']) assert np.isnan(sparse.at['c']) @@ -368,10 +270,7 @@ def test_at(self): def test_at_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('abcde')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse.at['a'] == orig.at['a'] assert np.isnan(sparse.at['b']) assert sparse.at['c'] == orig.at['c'] @@ -393,10 +292,7 @@ def test_iat(self): def test_iat_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.iat[0] == orig.iat[0] assert np.isnan(sparse.iat[1]) assert sparse.iat[2] == orig.iat[2] @@ -428,172 +324,106 @@ def test_get(self): def test_take(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - - tm.assert_sp_series_equal(sparse.take([0]), - orig.take([0]).to_sparse()) - tm.assert_sp_series_equal(sparse.take([0, 1, 3]), - orig.take([0, 1, 3]).to_sparse()) - tm.assert_sp_series_equal(sparse.take([-1, -2]), - orig.take([-1, -2]).to_sparse()) + sparse = orig.to_sparse() + + tm.assert_sp_series_equal(sparse.take([0]), + orig.take([0]).to_sparse()) + tm.assert_sp_series_equal(sparse.take([0, 1, 3]), + orig.take([0, 1, 3]).to_sparse()) + tm.assert_sp_series_equal(sparse.take([-1, -2]), + orig.take([-1, -2]).to_sparse()) def test_take_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal(sparse.take([0]), - orig.take([0]).to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse.take([0]), + orig.take([0]).to_sparse(fill_value=0)) - exp = orig.take([0, 1, 3]).to_sparse(fill_value=0) + exp = orig.take([0, 1, 3]).to_sparse(fill_value=0) tm.assert_sp_series_equal(sparse.take([0, 1, 3]), exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.take([-1, -2]).to_sparse(fill_value=0) + exp = orig.take([-1, -2]).to_sparse(fill_value=0) tm.assert_sp_series_equal(sparse.take([-1, -2]), exp) def test_reindex(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() res = sparse.reindex(['A', 'E', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() tm.assert_sp_series_equal(res, exp) # all missing & fill_value res = sparse.reindex(['B', 'E', 'C']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['B', 'E', 'C']).to_sparse() + exp = orig.reindex(['B', 'E', 'C']).to_sparse() tm.assert_sp_series_equal(res, exp) orig = pd.Series([np.nan, np.nan, np.nan, np.nan, np.nan], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() res = sparse.reindex(['A', 'E', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse() tm.assert_sp_series_equal(res, exp) def test_fill_value_reindex(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # includes missing and fill_value res = sparse.reindex(['A', 'B', 'C']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'B', 'C']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'B', 'C']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # all missing orig = pd.Series([np.nan, np.nan, np.nan, np.nan, np.nan], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) # all fill_value orig = pd.Series([0., 0., 0., 0., 0.], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) def test_fill_value_reindex_coerces_float_int(self): orig = pd.Series([1, np.nan, 0, 3, 0], index=list('ABCDE')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'E', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'E', 'C', 'D']).to_sparse(fill_value=0) tm.assert_sp_series_equal(res, exp) def test_reindex_fill_value(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - floats = pd.Series([1., 2., 3.]).to_sparse() + floats = pd.Series([1., 2., 3.]).to_sparse() result = floats.reindex([1, 2, 3], fill_value=0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = pd.Series([2., 3., 0], index=[1, 2, 3]).to_sparse() + expected = pd.Series([2., 3., 0], index=[1, 2, 3]).to_sparse() tm.assert_sp_series_equal(result, expected) def test_reindex_nearest(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = pd.Series(np.arange(10, dtype='float64')).to_sparse() + s = pd.Series(np.arange(10, dtype='float64')).to_sparse() target = [0.1, 0.9, 1.5, 2.0] actual = s.reindex(target, method='nearest') - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = pd.Series(np.around(target), target).to_sparse() + expected = pd.Series(np.around(target), target).to_sparse() tm.assert_sp_series_equal(expected, actual) actual = s.reindex(target, method='nearest', tolerance=0.2) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = pd.Series([0, 1, np.nan, 2], target).to_sparse() + expected = pd.Series([0, 1, np.nan, 2], target).to_sparse() tm.assert_sp_series_equal(expected, actual) actual = s.reindex(target, method='nearest', tolerance=[0.3, 0.01, 0.4, 3]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = pd.Series([0, np.nan, np.nan, 2], target).to_sparse() + expected = pd.Series([0, np.nan, np.nan, 2], target).to_sparse() tm.assert_sp_series_equal(expected, actual) @pytest.mark.parametrize("kind", ["integer", "block"]) @@ -635,10 +465,7 @@ def setup_method(self, method): idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), ('C', 0), ('C', 1)]) self.orig = pd.Series([1, np.nan, np.nan, 3, np.nan], index=idx) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - self.sparse = self.orig.to_sparse() + self.sparse = self.orig.to_sparse() def test_getitem_multi(self): orig = self.orig @@ -648,33 +475,21 @@ def test_getitem_multi(self): assert np.isnan(sparse[1]) assert sparse[3] == orig[3] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse['A'], orig['A'].to_sparse()) - tm.assert_sp_series_equal(sparse['B'], orig['B'].to_sparse()) + tm.assert_sp_series_equal(sparse['A'], orig['A'].to_sparse()) + tm.assert_sp_series_equal(sparse['B'], orig['B'].to_sparse()) result = sparse[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[[1, 3, 4]].to_sparse() + exp = orig[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse() + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[orig % 2 == 1].to_sparse() + exp = orig[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -693,70 +508,49 @@ def test_getitems_slice_multi(self): orig = self.orig sparse = self.sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse[2:], orig[2:].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], - orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse()) + tm.assert_sp_series_equal(sparse[2:], orig[2:].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], + orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['A':'B'], - orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], - orig.loc[:'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['A':'B'], + orig.loc['A':'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], + orig.loc[:'B'].to_sparse()) def test_loc(self): # need to be override to use different label orig = self.orig sparse = self.sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse.loc['A'], - orig.loc['A'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B'], - orig.loc['B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['A'], + orig.loc['A'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B'], + orig.loc['B'].to_sparse()) result = sparse.loc[[1, 3, 4]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[1, 3, 4]].to_sparse() + exp = orig.loc[[1, 3, 4]].to_sparse() tm.assert_sp_series_equal(result, exp) # exceeds the bounds result = sparse.loc[[1, 3, 4, 5]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[1, 3, 4, 5]].to_sparse() + exp = orig.loc[[1, 3, 4, 5]].to_sparse() tm.assert_sp_series_equal(result, exp) # single element list (GH 15447) result = sparse.loc[['A']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['A']].to_sparse() + exp = orig.loc[['A']].to_sparse() tm.assert_sp_series_equal(result, exp) # dense array result = sparse.loc[orig % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig % 2 == 1].to_sparse() + exp = orig.loc[orig % 2 == 1].to_sparse() tm.assert_sp_series_equal(result, exp) # sparse array @@ -774,20 +568,17 @@ def test_loc_multi_tuple(self): def test_loc_slice(self): orig = self.orig sparse = self.sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse.loc['A':], - orig.loc['A':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], - orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse()) - - tm.assert_sp_series_equal(sparse.loc['A':'B'], - orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], - orig.loc[:'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['A':], + orig.loc['A':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], + orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], + orig.loc['C':].to_sparse()) + + tm.assert_sp_series_equal(sparse.loc['A':'B'], + orig.loc['A':'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], + orig.loc[:'B'].to_sparse()) def test_reindex(self): # GH 15447 @@ -795,26 +586,17 @@ def test_reindex(self): sparse = self.sparse res = sparse.reindex([('A', 0), ('C', 1)]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex([('A', 0), ('C', 1)]).to_sparse() + exp = orig.reindex([('A', 0), ('C', 1)]).to_sparse() tm.assert_sp_series_equal(res, exp) # On specific level: res = sparse.reindex(['A', 'C', 'B'], level=0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B'], level=0).to_sparse() + exp = orig.reindex(['A', 'C', 'B'], level=0).to_sparse() tm.assert_sp_series_equal(res, exp) # single element list (GH 15447) res = sparse.reindex(['A'], level=0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A'], level=0).to_sparse() + exp = orig.reindex(['A'], level=0).to_sparse() tm.assert_sp_series_equal(res, exp) with pytest.raises(TypeError): @@ -823,15 +605,14 @@ def test_reindex(self): # "copy" argument: res = sparse.reindex(sparse.index, copy=True) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(orig.index, copy=True).to_sparse() + exp = orig.reindex(orig.index, copy=True).to_sparse() tm.assert_sp_series_equal(res, exp) assert sparse is not res @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseDataFrameIndexing: def test_getitem(self): @@ -840,24 +621,21 @@ def test_getitem(self): [np.nan, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse['x'], - orig['x'].to_sparse()) - tm.assert_sp_frame_equal(sparse[['x']], - orig[['x']].to_sparse()) - tm.assert_sp_frame_equal(sparse[['z', 'x']], - orig[['z', 'x']].to_sparse()) + tm.assert_sp_series_equal(sparse['x'], + orig['x'].to_sparse()) + tm.assert_sp_frame_equal(sparse[['x']], + orig[['x']].to_sparse()) + tm.assert_sp_frame_equal(sparse[['z', 'x']], + orig[['z', 'x']].to_sparse()) - tm.assert_sp_frame_equal(sparse[[True, False, True, True]], - orig[[True, False, True, True]] - .to_sparse()) + tm.assert_sp_frame_equal(sparse[[True, False, True, True]], + orig[[True, False, True, True]] + .to_sparse()) - tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], - orig.iloc[[1, 2]].to_sparse()) + tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], + orig.iloc[[1, 2]].to_sparse()) def test_getitem_fill_value(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -865,50 +643,29 @@ def test_getitem_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) result = sparse[['z']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = orig[['z']].to_sparse(fill_value=0) + expected = orig[['z']].to_sparse(fill_value=0) tm.assert_sp_frame_equal(result, expected, check_fill_value=False) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse['y'], - orig['y'].to_sparse(fill_value=0)) + tm.assert_sp_series_equal(sparse['y'], + orig['y'].to_sparse(fill_value=0)) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[['x']].to_sparse(fill_value=0) + exp = orig[['x']].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[['x']], exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[['z', 'x']].to_sparse(fill_value=0) + exp = orig[['z', 'x']].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[['z', 'x']], exp) indexer = [True, False, True, True] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig[indexer].to_sparse(fill_value=0) + exp = orig[indexer].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse[indexer], exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, 2]].to_sparse(fill_value=0) + exp = orig.iloc[[1, 2]].to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], exp) @@ -917,84 +674,57 @@ def test_loc(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.loc[0, 'x'] == 1 assert np.isnan(sparse.loc[1, 'z']) assert sparse.loc[2, 'z'] == 4 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - # have to specify `kind='integer'`, since we construct a - # new SparseArray here, and the default sparse type is - # integer there, but block in SparseSeries - tm.assert_sp_series_equal(sparse.loc[0], - orig.loc[0].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[1], - orig.loc[1].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[2, :], - orig.loc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[2, :], - orig.loc[2, :].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc[:, 'y'], - orig.loc[:, 'y'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:, 'y'], - orig.loc[:, 'y'].to_sparse()) + # have to specify `kind='integer'`, since we construct a + # new SparseArray here, and the default sparse type is + # integer there, but block in SparseSeries + tm.assert_sp_series_equal(sparse.loc[0], + orig.loc[0].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[1], + orig.loc[1].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[2, :], + orig.loc[2, :].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[2, :], + orig.loc[2, :].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc[:, 'y'], + orig.loc[:, 'y'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:, 'y'], + orig.loc[:, 'y'].to_sparse()) result = sparse.loc[[1, 2]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[1, 2]].to_sparse() + exp = orig.loc[[1, 2]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[[1, 2], :] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[1, 2], :].to_sparse() + exp = orig.loc[[1, 2], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[:, ['x', 'z']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[:, ['x', 'z']].to_sparse() + exp = orig.loc[:, ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[[0, 2], ['x', 'z']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[[0, 2], ['x', 'z']].to_sparse() + exp = orig.loc[[0, 2], ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) # exceeds the bounds result = sparse.reindex([1, 3, 4, 5]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex([1, 3, 4, 5]).to_sparse() + exp = orig.reindex([1, 3, 4, 5]).to_sparse() tm.assert_sp_frame_equal(result, exp) # dense array result = sparse.loc[orig.x % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig.x % 2 == 1].to_sparse() + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse.x % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig.x % 2 == 1].to_sparse() + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array @@ -1006,76 +736,52 @@ def test_loc_index(self): [2, 3, np.nan], [np.nan, np.nan, 4]], index=list('abc'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.loc['a', 'x'] == 1 assert np.isnan(sparse.loc['b', 'z']) assert sparse.loc['c', 'z'] == 4 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse.loc['a'], - orig.loc['a'].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b'], - orig.loc['b'].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :] - .to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :] - .to_sparse(kind='integer')) - - tm.assert_sp_series_equal(sparse.loc[:, 'z'], - orig.loc[:, 'z'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:, 'z'], - orig.loc[:, 'z'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['a'], + orig.loc['a'].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b'], + orig.loc['b'].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b', :], + orig.loc['b', :] + .to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.loc['b', :], + orig.loc['b', :] + .to_sparse(kind='integer')) + + tm.assert_sp_series_equal(sparse.loc[:, 'z'], + orig.loc[:, 'z'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:, 'z'], + orig.loc[:, 'z'].to_sparse()) result = sparse.loc[['a', 'b']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['a', 'b']].to_sparse() + exp = orig.loc[['a', 'b']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[['a', 'b'], :] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['a', 'b'], :].to_sparse() + exp = orig.loc[['a', 'b'], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[:, ['x', 'z']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[:, ['x', 'z']].to_sparse() + exp = orig.loc[:, ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.loc[['c', 'a'], ['x', 'z']] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[['c', 'a'], ['x', 'z']].to_sparse() + exp = orig.loc[['c', 'a'], ['x', 'z']].to_sparse() tm.assert_sp_frame_equal(result, exp) # dense array result = sparse.loc[orig.x % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig.x % 2 == 1].to_sparse() + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array (actuary it coerces to normal Series) result = sparse.loc[sparse.x % 2 == 1] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.loc[orig.x % 2 == 1].to_sparse() + exp = orig.loc[orig.x % 2 == 1].to_sparse() tm.assert_sp_frame_equal(result, exp) # sparse array @@ -1087,68 +793,47 @@ def test_loc_slice(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - tm.assert_sp_frame_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) + sparse = orig.to_sparse() + tm.assert_sp_frame_equal(sparse.loc[2:], orig.loc[2:].to_sparse()) def test_iloc(self): orig = pd.DataFrame([[1, np.nan, np.nan], [2, 3, np.nan], [np.nan, np.nan, 4]]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.iloc[1, 1] == 3 assert np.isnan(sparse.iloc[2, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_series_equal(sparse.iloc[0], - orig.loc[0].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[1], - orig.loc[1].to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :] - .to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :]. - to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.iloc[:, 1], - orig.iloc[:, 1].to_sparse()) - tm.assert_sp_series_equal(sparse.iloc[:, 1], - orig.iloc[:, 1].to_sparse()) + tm.assert_sp_series_equal(sparse.iloc[0], + orig.loc[0].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[1], + orig.loc[1].to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[2, :], + orig.iloc[2, :] + .to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[2, :], + orig.iloc[2, :]. + to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.iloc[:, 1], + orig.iloc[:, 1].to_sparse()) + tm.assert_sp_series_equal(sparse.iloc[:, 1], + orig.iloc[:, 1].to_sparse()) result = sparse.iloc[[1, 2]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, 2]].to_sparse() + exp = orig.iloc[[1, 2]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[[1, 2], :] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[1, 2], :].to_sparse() + exp = orig.iloc[[1, 2], :].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[:, [1, 0]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[:, [1, 0]].to_sparse() + exp = orig.iloc[:, [1, 0]].to_sparse() tm.assert_sp_frame_equal(result, exp) result = sparse.iloc[[2], [1, 0]] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.iloc[[2], [1, 0]].to_sparse() + exp = orig.iloc[[2], [1, 0]].to_sparse() tm.assert_sp_frame_equal(result, exp) with pytest.raises(IndexError): @@ -1159,12 +844,9 @@ def test_iloc_slice(self): [2, 3, np.nan], [np.nan, np.nan, 4]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - tm.assert_sp_frame_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse()) + sparse = orig.to_sparse() + tm.assert_sp_frame_equal(sparse.iloc[2:], + orig.iloc[2:].to_sparse()) def test_at(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -1172,10 +854,7 @@ def test_at(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.at['A', 'x'] == orig.at['A', 'x'] assert np.isnan(sparse.at['B', 'z']) assert np.isnan(sparse.at['C', 'y']) @@ -1187,10 +866,7 @@ def test_at_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse.at['A', 'x'] == orig.at['A', 'x'] assert np.isnan(sparse.at['B', 'z']) assert np.isnan(sparse.at['C', 'y']) @@ -1202,10 +878,7 @@ def test_iat(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() assert sparse.iat[0, 0] == orig.iat[0, 0] assert np.isnan(sparse.iat[1, 2]) assert np.isnan(sparse.iat[2, 1]) @@ -1220,10 +893,7 @@ def test_iat_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) assert sparse.iat[0, 0] == orig.iat[0, 0] assert np.isnan(sparse.iat[1, 2]) assert np.isnan(sparse.iat[2, 1]) @@ -1238,17 +908,14 @@ def test_take(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - - tm.assert_sp_frame_equal(sparse.take([0]), - orig.take([0]).to_sparse()) - tm.assert_sp_frame_equal(sparse.take([0, 1]), - orig.take([0, 1]).to_sparse()) - tm.assert_sp_frame_equal(sparse.take([-1, -2]), - orig.take([-1, -2]).to_sparse()) + sparse = orig.to_sparse() + + tm.assert_sp_frame_equal(sparse.take([0]), + orig.take([0]).to_sparse()) + tm.assert_sp_frame_equal(sparse.take([0, 1]), + orig.take([0, 1]).to_sparse()) + tm.assert_sp_frame_equal(sparse.take([-1, -2]), + orig.take([-1, -2]).to_sparse()) def test_take_fill_value(self): orig = pd.DataFrame([[1, np.nan, 0], @@ -1256,26 +923,17 @@ def test_take_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) - exp = orig.take([0]).to_sparse(fill_value=0) + exp = orig.take([0]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([0]), exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.take([0, 1]).to_sparse(fill_value=0) + exp = orig.take([0, 1]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([0, 1]), exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.take([-1, -2]).to_sparse(fill_value=0) + exp = orig.take([-1, -2]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(sparse.take([-1, -2]), exp) @@ -1285,16 +943,10 @@ def test_reindex(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() res = sparse.reindex(['A', 'C', 'B']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B']).to_sparse() + exp = orig.reindex(['A', 'C', 'B']).to_sparse() tm.assert_sp_frame_equal(res, exp) orig = pd.DataFrame([[np.nan, np.nan, np.nan], @@ -1302,16 +954,10 @@ def test_reindex(self): [np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() res = sparse.reindex(['A', 'C', 'B']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B']).to_sparse() + exp = orig.reindex(['A', 'C', 'B']).to_sparse() tm.assert_sp_frame_equal(res, exp) def test_reindex_fill_value(self): @@ -1320,16 +966,10 @@ def test_reindex_fill_value(self): [0, np.nan, 4], [0, np.nan, 5]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) # all missing @@ -1338,16 +978,10 @@ def test_reindex_fill_value(self): [np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan]], index=list('ABCD'), columns=list('xyz')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) # all fill_value @@ -1357,16 +991,10 @@ def test_reindex_fill_value(self): [0, 0, 0]], index=list('ABCD'), columns=list('xyz'), dtype=np.int) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) + sparse = orig.to_sparse(fill_value=0) res = sparse.reindex(['A', 'C', 'B']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) + exp = orig.reindex(['A', 'C', 'B']).to_sparse(fill_value=0) tm.assert_sp_frame_equal(res, exp) diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index 105702abc05ea..c06caadfcce7b 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -6,6 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestPivotTable: def setup_method(self, method): @@ -17,9 +18,7 @@ def setup_method(self, method): 'D': np.random.randn(8), 'E': [np.nan, np.nan, 1, 2, np.nan, 1, np.nan, np.nan]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - self.sparse = self.dense.to_sparse() + self.sparse = self.dense.to_sparse() def test_pivot_table(self): res_sparse = pd.pivot_table(self.sparse, index='A', columns='B', From 4e678564830d7a0e8da2792b4f8408ab56713d66 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 22:29:37 +0530 Subject: [PATCH 27/33] Update more test time warnings --- pandas/tests/sparse/frame/test_apply.py | 24 +- pandas/tests/sparse/frame/test_frame.py | 64 ++-- pandas/tests/sparse/frame/test_to_csv.py | 8 +- .../tests/sparse/frame/test_to_from_scipy.py | 7 +- pandas/tests/sparse/series/test_series.py | 285 +++++++----------- pandas/tests/sparse/test_combine_concat.py | 34 +-- pandas/tests/sparse/test_format.py | 24 +- pandas/tests/sparse/test_groupby.py | 11 +- pandas/tests/sparse/test_indexing.py | 48 +-- pandas/tests/sparse/test_pivot.py | 1 + 10 files changed, 181 insertions(+), 325 deletions(-) diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py index 388d4ca67b4c9..897482168141e 100644 --- a/pandas/tests/sparse/frame/test_apply.py +++ b/pandas/tests/sparse/frame/test_apply.py @@ -38,6 +38,7 @@ def fill_frame(frame): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_apply(frame): applied = frame.apply(np.sqrt) assert isinstance(applied, SparseDataFrame) @@ -50,17 +51,13 @@ def test_apply(frame): broadcasted = frame.apply(np.sum, broadcast=True) assert isinstance(broadcasted, SparseDataFrame) - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = frame.to_dense().apply(np.sum, broadcast=True) + exp = frame.to_dense().apply(np.sum, broadcast=True) tm.assert_frame_equal(broadcasted.to_dense(), exp) applied = frame.apply(np.sum) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_series_equal(applied, - frame.to_dense().apply(nanops.nansum) - .to_sparse()) + tm.assert_series_equal(applied, + frame.to_dense().apply(nanops.nansum) + .to_sparse()) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @@ -75,12 +72,11 @@ def test_apply_empty(empty): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_apply_nonuq(): orig = DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sparse = orig.to_sparse() + sparse = orig.to_sparse() res = sparse.apply(lambda s: s[0], axis=1) exp = orig.apply(lambda s: s[0], axis=1) @@ -91,10 +87,8 @@ def test_apply_nonuq(): assert isinstance(res, Series) tm.assert_series_equal(res.to_dense(), exp) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - # df.T breaks - sparse = orig.T.to_sparse() + # df.T breaks + sparse = orig.T.to_sparse() res = sparse.apply(lambda s: s[0], axis=0) # noqa exp = orig.T.apply(lambda s: s[0], axis=0) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index e42191d6400b5..bdbf79ec9e700 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -26,6 +26,7 @@ def test_deprecated(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrame(SharedWithSparse): klass = SparseDataFrame @@ -181,9 +182,7 @@ def test_constructor_from_series(self): # GH 2873 x = Series(np.random.randn(10000), name='a') - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - x = x.to_sparse(fill_value=0) + x = x.to_sparse(fill_value=0) assert isinstance(x, SparseSeries) df = SparseDataFrame(x) assert isinstance(df, SparseDataFrame) @@ -193,18 +192,14 @@ def test_constructor_from_series(self): x2 = x.astype(float) x2.loc[:9998] = np.NaN # TODO: x_sparse is unused...fix - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - x_sparse = x2.to_sparse(fill_value=np.NaN) # noqa + x_sparse = x2.to_sparse(fill_value=np.NaN) # noqa # Currently fails too with weird ufunc error # df1 = SparseDataFrame([x_sparse, y]) y.loc[:9998] = 0 # TODO: y_sparse is unsused...fix - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - y_sparse = y.to_sparse(fill_value=0) # noqa + y_sparse = y.to_sparse(fill_value=0) # noqa # without sparse value raises error # df2 = SparseDataFrame([x2_sparse, y]) @@ -213,17 +208,13 @@ def test_constructor_from_dense_series(self): # series with name x = Series(np.random.randn(10000), name='a') result = SparseDataFrame(x) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - expected = x.to_frame().to_sparse() + expected = x.to_frame().to_sparse() tm.assert_sp_frame_equal(result, expected) # series with no name x = Series(np.random.randn(10000)) result = SparseDataFrame(x) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - expected = x.to_frame().to_sparse() + expected = x.to_frame().to_sparse() tm.assert_sp_frame_equal(result, expected) def test_constructor_from_unknown_type(self): @@ -267,9 +258,7 @@ def test_constructor_nan_dataframe(self): matrix = np.empty((len(index), len(trains))) matrix.fill(np.nan) df = pd.DataFrame(matrix, index=index, columns=trains, dtype=float) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = df.to_sparse() + result = df.to_sparse() expected = pd.SparseDataFrame(matrix, index=index, columns=trains, dtype=float) tm.assert_sp_frame_equal(result, expected) @@ -302,9 +291,7 @@ def test_nan_data_with_int_dtype_raises_error(self): def test_dtypes(self): df = DataFrame(np.random.randn(10000, 4)) df.loc[:9998] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() result = sdf.get_dtype_counts() expected = Series({'Sparse[float64, nan]': 4}) @@ -322,9 +309,7 @@ def test_str(self): df = DataFrame(np.random.randn(10000, 4)) df.loc[:9998] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() str(sdf) def test_array_interface(self, float_frame): @@ -350,24 +335,18 @@ def _test_roundtrip(frame, orig): def test_dense_to_sparse(self): df = DataFrame({'A': [nan, nan, nan, 1, 2], 'B': [1, 2, nan, nan, nan]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() assert isinstance(sdf, SparseDataFrame) assert np.isnan(sdf.default_fill_value) assert isinstance(sdf['A'].sp_index, BlockIndex) tm.assert_frame_equal(sdf.to_dense(), df) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sdf = df.to_sparse(kind='integer') + sdf = df.to_sparse(kind='integer') assert isinstance(sdf['A'].sp_index, IntIndex) df = DataFrame({'A': [0, 0, 0, 1, 2], 'B': [1, 2, 0, 0, 0]}, dtype=float) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - sdf = df.to_sparse(fill_value=0) + sdf = df.to_sparse(fill_value=0) assert sdf.default_fill_value == 0 tm.assert_frame_equal(sdf.to_dense(), df) @@ -803,20 +782,16 @@ def test_fillna(self, float_frame_fill0, float_frame_fill0_dense): result = df.fillna(0) expected = dense.fillna(0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), - exact_indices=False) + tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), + exact_indices=False) tm.assert_frame_equal(result.to_dense(), expected) result = df.copy() result.fillna(0, inplace=True) expected = dense.fillna(0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), - exact_indices=False) + tm.assert_sp_frame_equal(result, expected.to_sparse(fill_value=0), + exact_indices=False) tm.assert_frame_equal(result.to_dense(), expected) result = df.copy() @@ -1407,6 +1382,7 @@ def test_comparison_op_scalar(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameAnalytics: def test_cumsum(self, float_frame): @@ -1478,10 +1454,8 @@ def test_quantile_multi(self): def test_assign_with_sparse_frame(self): # GH 19163 df = pd.DataFrame({"a": [1, 2, 3]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - res = df.to_sparse(fill_value=False).assign(newcol=False) - exp = df.assign(newcol=False).to_sparse(fill_value=False) + res = df.to_sparse(fill_value=False).assign(newcol=False) + exp = df.assign(newcol=False).to_sparse(fill_value=False) tm.assert_sp_frame_equal(res, exp) diff --git a/pandas/tests/sparse/frame/test_to_csv.py b/pandas/tests/sparse/frame/test_to_csv.py index 7e38cc15abf46..35e5e2a52d1d7 100644 --- a/pandas/tests/sparse/frame/test_to_csv.py +++ b/pandas/tests/sparse/frame/test_to_csv.py @@ -6,6 +6,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameToCsv: fill_values = [np.nan, 0, None, 1] @@ -19,8 +20,5 @@ def test_to_csv_sparse_dataframe(self, fill_value): sdf.to_csv(path, index=False) df = read_csv(path, skip_blank_lines=False) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), - sdf) + tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), + sdf) diff --git a/pandas/tests/sparse/frame/test_to_from_scipy.py b/pandas/tests/sparse/frame/test_to_from_scipy.py index fbf83339c3fdb..50f4577d280cb 100644 --- a/pandas/tests/sparse/frame/test_to_from_scipy.py +++ b/pandas/tests/sparse/frame/test_to_from_scipy.py @@ -179,11 +179,8 @@ def test_index_names_multiple_nones(): # https://github.com/pandas-dev/pandas/pull/24092 sparse = pytest.importorskip("scipy.sparse") - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = (pd.Series(1, index=pd.MultiIndex - .from_product([['A', 'B'], [0, 1]])).to_sparse()) + s = (pd.Series(1, index=pd.MultiIndex + .from_product([['A', 'B'], [0, 1]])).to_sparse()) result, _, _ = s.to_coo() assert isinstance(result, sparse.coo_matrix) result = result.toarray() diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 3b15ef11851b1..80f4e3a8be09b 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -61,6 +61,7 @@ def _test_data2_zero(): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeries(SharedWithSparse): series_klass = SparseSeries @@ -183,10 +184,7 @@ def test_series_density(self): # GH2803 ts = Series(np.random.randn(10)) ts[2:-2] = nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sts = ts.to_sparse() + sts = ts.to_sparse() density = sts.density # don't die assert density == 4 / 10.0 @@ -230,11 +228,8 @@ def test_to_dense_fill_value(self): def test_dense_to_sparse(self): series = self.bseries.to_dense() - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - bseries = series.to_sparse(kind='block') - iseries = series.to_sparse(kind='integer') + bseries = series.to_sparse(kind='block') + iseries = series.to_sparse(kind='integer') tm.assert_sp_series_equal(bseries, self.bseries) tm.assert_sp_series_equal(iseries, self.iseries, check_names=False) assert iseries.name == self.bseries.name @@ -246,11 +241,8 @@ def test_dense_to_sparse(self): # non-NaN fill value series = self.zbseries.to_dense() - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - zbseries = series.to_sparse(kind='block', fill_value=0) - ziseries = series.to_sparse(kind='integer', fill_value=0) + zbseries = series.to_sparse(kind='block', fill_value=0) + ziseries = series.to_sparse(kind='integer', fill_value=0) tm.assert_sp_series_equal(zbseries, self.zbseries) tm.assert_sp_series_equal(ziseries, self.ziseries, check_names=False) assert ziseries.name == self.zbseries.name @@ -392,10 +384,7 @@ def test_shape(self): def test_astype(self): result = self.bseries.astype(SparseDtype(np.int64, 0)) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = (self.bseries.to_dense() + expected = (self.bseries.to_dense() .fillna(0) .astype(np.int64) .to_sparse(fill_value=0)) @@ -551,10 +540,7 @@ def _compare(idx): # XXX: changed test. Why wsa this considered a corner case? sp = SparseSeries(np.ones(10) * nan) exp = pd.Series(np.repeat(nan, 5)) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp.to_sparse()) + tm.assert_series_equal(sp.take([0, 1, 2, 3, 4]), exp.to_sparse()) # multiple FutureWarnings, can't check stacklevel with tm.assert_produces_warning(FutureWarning, @@ -847,16 +833,10 @@ def _compare_all(obj): series.fill_value = 2 _compare_all(series) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - nonna = Series(np.random.randn(20)).to_sparse() + nonna = Series(np.random.randn(20)).to_sparse() _compare_all(nonna) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - nonna2 = Series(np.random.randn(20)).to_sparse(fill_value=0) + nonna2 = Series(np.random.randn(20)).to_sparse(fill_value=0) _compare_all(nonna2) @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") @@ -949,106 +929,94 @@ def test_shift(self): def test_shift_nan(self): # GH 12908 orig = pd.Series([np.nan, 2, np.nan, 4, 0, np.nan, 0]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(1), - orig.shift(1).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(2), - orig.shift(2).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(3), - orig.shift(3).to_sparse(), - check_kind=False) - - tm.assert_sp_series_equal(sparse.shift(-1), - orig.shift(-1).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-2), - orig.shift(-2).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-3), - orig.shift(-3).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-4), - orig.shift(-4).to_sparse()) - - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=0) - tm.assert_sp_series_equal( - sparse.shift(0), - orig.shift(0).to_sparse(fill_value=sparse.fill_value) - ) - tm.assert_sp_series_equal(sparse.shift(1), - orig.shift(1).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(2), - orig.shift(2).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(3), - orig.shift(3).to_sparse(fill_value=0), - check_kind=False) - - tm.assert_sp_series_equal(sparse.shift(-1), - orig.shift(-1).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-2), - orig.shift(-2).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-3), - orig.shift(-3).to_sparse(fill_value=0), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-4), - orig.shift(-4).to_sparse(fill_value=0), - check_kind=False) + sparse = orig.to_sparse() + + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(1), + orig.shift(1).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(2), + orig.shift(2).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(3), + orig.shift(3).to_sparse(), + check_kind=False) + + tm.assert_sp_series_equal(sparse.shift(-1), + orig.shift(-1).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-2), + orig.shift(-2).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-3), + orig.shift(-3).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-4), + orig.shift(-4).to_sparse()) + + sparse = orig.to_sparse(fill_value=0) + tm.assert_sp_series_equal( + sparse.shift(0), + orig.shift(0).to_sparse(fill_value=sparse.fill_value) + ) + tm.assert_sp_series_equal(sparse.shift(1), + orig.shift(1).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(2), + orig.shift(2).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(3), + orig.shift(3).to_sparse(fill_value=0), + check_kind=False) + + tm.assert_sp_series_equal(sparse.shift(-1), + orig.shift(-1).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-2), + orig.shift(-2).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-3), + orig.shift(-3).to_sparse(fill_value=0), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-4), + orig.shift(-4).to_sparse(fill_value=0), + check_kind=False) def test_shift_dtype(self): # GH 12908 orig = pd.Series([1, 2, 3, 4], dtype=np.int64) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0).to_sparse()) - - sparse = orig.to_sparse(fill_value=np.nan) - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0). - to_sparse(fill_value=np.nan)) - - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - # shift(1) or more span changes dtype to float64 - # XXX: SparseSeries doesn't need to shift dtype here. - # Do we want to astype in shift, for backwards compat? - # If not, document it. - tm.assert_sp_series_equal(sparse.shift(1).astype('f8'), - orig.shift(1).to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.shift(2).astype('f8'), - orig.shift(2).to_sparse(kind='integer')) - tm.assert_sp_series_equal(sparse.shift(3).astype('f8'), - orig.shift(3).to_sparse(kind='integer')) - - tm.assert_sp_series_equal(sparse.shift(-1).astype('f8'), - orig.shift(-1).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-2).astype('f8'), - orig.shift(-2).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-3).astype('f8'), - orig.shift(-3).to_sparse(), - check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-4).astype('f8'), - orig.shift(-4).to_sparse(), - check_kind=False) + sparse = orig.to_sparse() + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0).to_sparse()) + + sparse = orig.to_sparse(fill_value=np.nan) + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0). + to_sparse(fill_value=np.nan)) + + # shift(1) or more span changes dtype to float64 + # XXX: SparseSeries doesn't need to shift dtype here. + # Do we want to astype in shift, for backwards compat? + # If not, document it. + tm.assert_sp_series_equal(sparse.shift(1).astype('f8'), + orig.shift(1).to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.shift(2).astype('f8'), + orig.shift(2).to_sparse(kind='integer')) + tm.assert_sp_series_equal(sparse.shift(3).astype('f8'), + orig.shift(3).to_sparse(kind='integer')) + + tm.assert_sp_series_equal(sparse.shift(-1).astype('f8'), + orig.shift(-1).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-2).astype('f8'), + orig.shift(-2).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-3).astype('f8'), + orig.shift(-3).to_sparse(), + check_kind=False) + tm.assert_sp_series_equal(sparse.shift(-4).astype('f8'), + orig.shift(-4).to_sparse(), + check_kind=False) @pytest.mark.parametrize("fill_value", [ 0, @@ -1059,16 +1027,10 @@ def test_shift_dtype(self): def test_shift_dtype_fill_value(self, fill_value, periods): # GH 12908 orig = pd.Series([1, 0, 0, 4], dtype=np.dtype('int64')) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = orig.to_sparse(fill_value=fill_value) + sparse = orig.to_sparse(fill_value=fill_value) result = sparse.shift(periods) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = orig.shift(periods).to_sparse(fill_value=fill_value) + expected = orig.shift(periods).to_sparse(fill_value=fill_value) tm.assert_sp_series_equal(result, expected, check_kind=False, @@ -1082,10 +1044,7 @@ def test_combine_first(self): result2 = s[::2].combine_first(s.to_dense()) expected = s[::2].to_dense().combine_first(s.to_dense()) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse(fill_value=s.fill_value) + expected = expected.to_sparse(fill_value=s.fill_value) tm.assert_sp_series_equal(result, result2) tm.assert_sp_series_equal(result, expected) @@ -1103,6 +1062,7 @@ def test_memory_usage_deep(self, deep, fill_value): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseHandlingMultiIndexes: def setup_method(self, method): @@ -1115,19 +1075,13 @@ def setup_method(self, method): self.dense_multiindex_frame = dense_multiindex_frame.fillna(value=3.14) def test_to_sparse_preserve_multiindex_names_columns(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() + sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() sparse_multiindex_frame = sparse_multiindex_frame.copy() tm.assert_index_equal(sparse_multiindex_frame.columns, self.dense_multiindex_frame.columns) def test_round_trip_preserve_multiindex_names(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() + sparse_multiindex_frame = self.dense_multiindex_frame.to_sparse() round_trip_multiindex_frame = sparse_multiindex_frame.to_dense() tm.assert_frame_equal(self.dense_multiindex_frame, round_trip_multiindex_frame, @@ -1156,23 +1110,17 @@ def setup_method(self, method): (2, 1, 'b', 0), (2, 1, 'b', 1)], names=['A', 'B', 'C', 'D']) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - self.sparse_series.append(s.to_sparse()) + self.sparse_series.append(s.to_sparse()) ss = self.sparse_series[0].copy() ss.index.names = [3, 0, 1, 2] self.sparse_series.append(ss) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = pd.Series([ - nan - ] * 12, index=cartesian_product((range(3), range(4)))).to_sparse() - for k, v in zip([(0, 0), (1, 2), (1, 3)], [3.0, 1.0, 2.0]): - ss[k] = v + ss = pd.Series([ + nan + ] * 12, index=cartesian_product((range(3), range(4)))).to_sparse() + for k, v in zip([(0, 0), (1, 2), (1, 3)], [3.0, 1.0, 2.0]): + ss[k] = v self.sparse_series.append(ss) # results used in tests @@ -1246,11 +1194,8 @@ def test_to_coo_bad_ilevel(self): ss.to_coo(['A', 'B'], ['C', 'D', 'E']) def test_to_coo_duplicate_index_entries(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - ss = pd.concat([self.sparse_series[0], - self.sparse_series[0]]).to_sparse() + ss = pd.concat([self.sparse_series[0], + self.sparse_series[0]]).to_sparse() msg = ("Duplicate index entries are not allowed in to_coo" " transformation") with pytest.raises(ValueError, match=msg): @@ -1264,10 +1209,7 @@ def test_from_coo_dense_index(self): def test_from_coo_nodense_index(self): ss = SparseSeries.from_coo(self.coo_matrices[0], dense_index=False) check = self.sparse_series[2] - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - check = check.dropna().to_sparse() + check = check.dropna().to_sparse() tm.assert_sp_series_equal(ss, check) def test_from_coo_long_repr(self): @@ -1521,6 +1463,7 @@ def _dense_series_compare(s, f): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesAnalytics: def setup_method(self, method): @@ -1538,10 +1481,7 @@ def test_cumsum(self): tm.assert_sp_series_equal(result, expected) result = self.zbseries.cumsum() - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = self.zbseries.to_dense().cumsum().to_sparse() + expected = self.zbseries.to_dense().cumsum().to_sparse() tm.assert_series_equal(result, expected) axis = 1 # Series is 1-D, so only axis = 0 is valid. @@ -1555,10 +1495,7 @@ def test_numpy_cumsum(self): tm.assert_sp_series_equal(result, expected) result = np.cumsum(self.zbseries) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = self.zbseries.to_dense().cumsum().to_sparse() + expected = self.zbseries.to_dense().cumsum().to_sparse() tm.assert_series_equal(result, expected) msg = "the 'dtype' parameter is not supported" diff --git a/pandas/tests/sparse/test_combine_concat.py b/pandas/tests/sparse/test_combine_concat.py index 25d54dd4edd43..4fed878a10ca6 100644 --- a/pandas/tests/sparse/test_combine_concat.py +++ b/pandas/tests/sparse/test_combine_concat.py @@ -311,7 +311,7 @@ def test_concat_different_columns_buggy(self): res = pd.concat([sparse, sparse3], sort=True) exp = (pd.concat([self.dense1, self.dense3], sort=True) - .to_sparse(fill_value=0)) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, @@ -319,7 +319,7 @@ def test_concat_different_columns_buggy(self): res = pd.concat([sparse3, sparse], sort=True) exp = (pd.concat([self.dense3, self.dense1], sort=True) - .to_sparse(fill_value=0)) + .to_sparse(fill_value=0)) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) @@ -345,17 +345,11 @@ def test_concat_series(self): for col in ['A', 'D']: res = pd.concat([sparse, sparse2[col]]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, self.dense2[col]]).to_sparse() + exp = pd.concat([self.dense1, self.dense2[col]]).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) res = pd.concat([sparse2[col], sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2[col], self.dense1]).to_sparse() + exp = pd.concat([self.dense2[col], self.dense1]).to_sparse() tm.assert_sp_frame_equal(res, exp, check_kind=False) # fill_value = 0 @@ -364,21 +358,15 @@ def test_concat_series(self): for col in ['C', 'D']: res = pd.concat([sparse, sparse2[col]]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense1, - self.dense2[col]]).to_sparse(fill_value=0) + exp = pd.concat([self.dense1, + self.dense2[col]]).to_sparse(fill_value=0) exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, check_kind=False, consolidate_block_indices=True) res = pd.concat([sparse2[col], sparse]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = pd.concat([self.dense2[col], - self.dense1]).to_sparse(fill_value=0) + exp = pd.concat([self.dense2[col], + self.dense1]).to_sparse(fill_value=0) exp['C'] = res['C'] exp._default_fill_value = np.nan tm.assert_sp_frame_equal(res, exp, consolidate_block_indices=True, @@ -435,8 +423,7 @@ def test_concat_axis1(self): def test_concat_sparse_dense_rows(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense2] sparse_frame = [frames[dense_idx], - frames[sparse_idx] - .to_sparse(fill_value=fill_value)] + frames[sparse_idx].to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse @@ -463,8 +450,7 @@ def test_concat_sparse_dense_cols(self, fill_value, sparse_idx, dense_idx): frames = [self.dense1, self.dense3] sparse_frame = [frames[dense_idx], - frames[sparse_idx] - .to_sparse(fill_value=fill_value)] + frames[sparse_idx].to_sparse(fill_value=fill_value)] dense_frame = [frames[dense_idx], frames[sparse_idx]] # This will try both directions sparse + dense and dense + sparse diff --git a/pandas/tests/sparse/test_format.py b/pandas/tests/sparse/test_format.py index a0bc965031f33..805f77eb21c2f 100644 --- a/pandas/tests/sparse/test_format.py +++ b/pandas/tests/sparse/test_format.py @@ -13,6 +13,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") class TestSparseSeriesFormatting: @property @@ -20,10 +21,7 @@ def dtype_format_for_platform(self): return '' if use_32bit_repr else ', dtype=int32' def test_sparse_max_row(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() + s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() result = repr(s) dfm = self.dtype_format_for_platform exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n" @@ -33,10 +31,7 @@ def test_sparse_max_row(self): assert result == exp def test_sparsea_max_row_truncated(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() + s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() dfm = self.dtype_format_for_platform with option_context("display.max_rows", 3): @@ -51,11 +46,8 @@ def test_sparsea_max_row_truncated(self): def test_sparse_mi_max_row(self): idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), ('C', 0), ('C', 1), ('C', 2)]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan], - index=idx).to_sparse() + s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan], + index=idx).to_sparse() result = repr(s) dfm = self.dtype_format_for_platform exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n" @@ -119,6 +111,7 @@ def test_sparse_int(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameFormatting: def test_sparse_frame(self): @@ -127,10 +120,7 @@ def test_sparse_frame(self): 'B': [True, False, True, False, True], 'C': [0, 0, 3, 0, 5], 'D': [np.nan, np.nan, np.nan, 1, 2]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = df.to_sparse() + sparse = df.to_sparse() assert repr(sparse) == repr(df) with option_context("display.max_rows", 3): diff --git a/pandas/tests/sparse/test_groupby.py b/pandas/tests/sparse/test_groupby.py index 1b73270531d0f..531a4360c78a2 100644 --- a/pandas/tests/sparse/test_groupby.py +++ b/pandas/tests/sparse/test_groupby.py @@ -62,17 +62,12 @@ def test_aggfuncs(self): @pytest.mark.parametrize("fill_value", [0, np.nan]) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") def test_groupby_includes_fill_value(fill_value): # https://github.com/pandas-dev/pandas/issues/5078 df = pd.DataFrame({'a': [fill_value, 1, fill_value, fill_value], 'b': [fill_value, 1, fill_value, fill_value]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sdf = df.to_sparse(fill_value=fill_value) + sdf = df.to_sparse(fill_value=fill_value) result = sdf.groupby('a').sum() - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = df.groupby('a').sum().to_sparse(fill_value=fill_value) + expected = df.groupby('a').sum().to_sparse(fill_value=fill_value) tm.assert_frame_equal(result, expected, check_index_type=False) diff --git a/pandas/tests/sparse/test_indexing.py b/pandas/tests/sparse/test_indexing.py index d7cc49884f7cf..df59f1dfe7b13 100644 --- a/pandas/tests/sparse/test_indexing.py +++ b/pandas/tests/sparse/test_indexing.py @@ -240,8 +240,7 @@ def test_iloc_fill_value(self): def test_iloc_slice(self): orig = pd.Series([1, np.nan, np.nan, 3, np.nan]) sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse()) + tm.assert_sp_series_equal(sparse.iloc[2:], orig.iloc[2:].to_sparse()) def test_iloc_slice_fill_value(self): orig = pd.Series([1, np.nan, 0, 3, 0]) @@ -509,15 +508,12 @@ def test_getitems_slice_multi(self): sparse = self.sparse tm.assert_sp_series_equal(sparse[2:], orig[2:].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], - orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], orig.loc['C':].to_sparse()) tm.assert_sp_series_equal(sparse.loc['A':'B'], orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], - orig.loc[:'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], orig.loc[:'B'].to_sparse()) def test_loc(self): # need to be override to use different label @@ -568,17 +564,13 @@ def test_loc_multi_tuple(self): def test_loc_slice(self): orig = self.orig sparse = self.sparse - tm.assert_sp_series_equal(sparse.loc['A':], - orig.loc['A':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['B':], - orig.loc['B':].to_sparse()) - tm.assert_sp_series_equal(sparse.loc['C':], - orig.loc['C':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['A':], orig.loc['A':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['B':], orig.loc['B':].to_sparse()) + tm.assert_sp_series_equal(sparse.loc['C':], orig.loc['C':].to_sparse()) tm.assert_sp_series_equal(sparse.loc['A':'B'], orig.loc['A':'B'].to_sparse()) - tm.assert_sp_series_equal(sparse.loc[:'B'], - orig.loc[:'B'].to_sparse()) + tm.assert_sp_series_equal(sparse.loc[:'B'], orig.loc[:'B'].to_sparse()) def test_reindex(self): # GH 15447 @@ -623,16 +615,13 @@ def test_getitem(self): columns=list('xyz')) sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse['x'], - orig['x'].to_sparse()) - tm.assert_sp_frame_equal(sparse[['x']], - orig[['x']].to_sparse()) + tm.assert_sp_series_equal(sparse['x'], orig['x'].to_sparse()) + tm.assert_sp_frame_equal(sparse[['x']], orig[['x']].to_sparse()) tm.assert_sp_frame_equal(sparse[['z', 'x']], orig[['z', 'x']].to_sparse()) tm.assert_sp_frame_equal(sparse[[True, False, True, True]], - orig[[True, False, True, True]] - .to_sparse()) + orig[[True, False, True, True]].to_sparse()) tm.assert_sp_frame_equal(sparse.iloc[[1, 2]], orig.iloc[[1, 2]].to_sparse()) @@ -747,11 +736,9 @@ def test_loc_index(self): tm.assert_sp_series_equal(sparse.loc['b'], orig.loc['b'].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :] - .to_sparse(kind='integer')) + orig.loc['b', :].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.loc['b', :], - orig.loc['b', :] - .to_sparse(kind='integer')) + orig.loc['b', :].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.loc[:, 'z'], orig.loc[:, 'z'].to_sparse()) @@ -810,11 +797,9 @@ def test_iloc(self): tm.assert_sp_series_equal(sparse.iloc[1], orig.loc[1].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :] - .to_sparse(kind='integer')) + orig.iloc[2, :].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.iloc[2, :], - orig.iloc[2, :]. - to_sparse(kind='integer')) + orig.iloc[2, :].to_sparse(kind='integer')) tm.assert_sp_series_equal(sparse.iloc[:, 1], orig.iloc[:, 1].to_sparse()) tm.assert_sp_series_equal(sparse.iloc[:, 1], @@ -845,8 +830,7 @@ def test_iloc_slice(self): [np.nan, np.nan, 4]], columns=list('xyz')) sparse = orig.to_sparse() - tm.assert_sp_frame_equal(sparse.iloc[2:], - orig.iloc[2:].to_sparse()) + tm.assert_sp_frame_equal(sparse.iloc[2:], orig.iloc[2:].to_sparse()) def test_at(self): orig = pd.DataFrame([[1, np.nan, 0], diff --git a/pandas/tests/sparse/test_pivot.py b/pandas/tests/sparse/test_pivot.py index c06caadfcce7b..114e7b4bacd94 100644 --- a/pandas/tests/sparse/test_pivot.py +++ b/pandas/tests/sparse/test_pivot.py @@ -7,6 +7,7 @@ @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestPivotTable: def setup_method(self, method): From 4a3181b8974adc0ad2cd6f22d094fbdbc890ffa0 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 22:46:06 +0530 Subject: [PATCH 28/33] Update test warnings --- pandas/tests/sparse/frame/test_apply.py | 7 +- pandas/tests/sparse/frame/test_frame.py | 84 +++++-------------- pandas/tests/sparse/frame/test_to_csv.py | 3 +- .../tests/sparse/frame/test_to_from_scipy.py | 4 +- pandas/tests/sparse/series/test_series.py | 50 ++++------- 5 files changed, 43 insertions(+), 105 deletions(-) diff --git a/pandas/tests/sparse/frame/test_apply.py b/pandas/tests/sparse/frame/test_apply.py index 897482168141e..4e677f5055e79 100644 --- a/pandas/tests/sparse/frame/test_apply.py +++ b/pandas/tests/sparse/frame/test_apply.py @@ -51,13 +51,14 @@ def test_apply(frame): broadcasted = frame.apply(np.sum, broadcast=True) assert isinstance(broadcasted, SparseDataFrame) - exp = frame.to_dense().apply(np.sum, broadcast=True) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + exp = frame.to_dense().apply(np.sum, broadcast=True) tm.assert_frame_equal(broadcasted.to_dense(), exp) applied = frame.apply(np.sum) tm.assert_series_equal(applied, - frame.to_dense().apply(nanops.nansum) - .to_sparse()) + frame.to_dense().apply(nanops.nansum).to_sparse()) @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index bdbf79ec9e700..5b7db199d45cd 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -817,10 +817,7 @@ def test_fillna_fill_value(self): def test_sparse_frame_pad_backfill_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() result = sdf[:2].reindex(index, method='pad', limit=5) @@ -829,10 +826,7 @@ def test_sparse_frame_pad_backfill_limit(self): expected = sdf[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected.values[-3:] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) result = sdf[-2:].reindex(index, method='backfill', limit=5) @@ -842,19 +836,13 @@ def test_sparse_frame_pad_backfill_limit(self): expected = sdf[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected.values[:3] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) def test_sparse_frame_fillna_limit(self): index = np.arange(10) df = DataFrame(np.random.randn(10, 4), index=index) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sdf = df.to_sparse() + sdf = df.to_sparse() result = sdf[:2].reindex(index) with tm.assert_produces_warning(PerformanceWarning, @@ -866,10 +854,7 @@ def test_sparse_frame_fillna_limit(self): expected = sdf[:2].reindex(index).fillna(method='pad') expected = expected.to_dense() expected.values[-3:] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) result = sdf[-2:].reindex(index) @@ -882,10 +867,7 @@ def test_sparse_frame_fillna_limit(self): expected = sdf[-2:].reindex(index).fillna(method='backfill') expected = expected.to_dense() expected.values[:3] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse() + expected = expected.to_sparse() tm.assert_frame_equal(result, expected) def test_rename(self, float_frame): @@ -907,11 +889,8 @@ def test_rename(self, float_frame): def test_corr(self, float_frame): res = float_frame.corr() # XXX: this stays sparse - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - tm.assert_frame_equal(res, - float_frame.to_dense().corr().to_sparse()) + tm.assert_frame_equal(res, + float_frame.to_dense().corr().to_sparse()) def test_describe(self, float_frame): float_frame['foo'] = np.nan @@ -999,10 +978,7 @@ def test_reindex_fill_value(self, float_frame_fill0, result = float_frame_fill0.reindex(rng, fill_value=0) exp = float_frame_fill0_dense.reindex(rng, fill_value=0) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = exp.to_sparse(float_frame_fill0.default_fill_value) + exp = exp.to_sparse(float_frame_fill0.default_fill_value) tm.assert_sp_frame_equal(result, exp) def test_reindex_method(self): @@ -1209,10 +1185,7 @@ def test_combine_first(self, float_frame): result = df[::2].combine_first(df) expected = df[::2].to_dense().combine_first(df.to_dense()) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse(fill_value=df.default_fill_value) + expected = expected.to_sparse(fill_value=df.default_fill_value) tm.assert_sp_frame_equal(result, expected) @@ -1225,10 +1198,7 @@ def test_combine_first_with_dense(self): result = df[::2].combine_first(df.to_dense()) expected = df[::2].to_dense().combine_first(df.to_dense()) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - expected = expected.to_sparse(fill_value=df.default_fill_value) + expected = expected.to_sparse(fill_value=df.default_fill_value) tm.assert_sp_frame_equal(result, expected) @@ -1238,19 +1208,13 @@ def test_combine_add(self, float_frame): df2['C'][:3] = np.nan df['A'][:3] = 5.7 - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = df.to_sparse().add(df2.to_sparse(), fill_value=0) - expected = df.add(df2, fill_value=0).to_sparse() + result = df.to_sparse().add(df2.to_sparse(), fill_value=0) + expected = df.add(df2, fill_value=0).to_sparse() tm.assert_sp_frame_equal(result, expected) def test_isin(self): - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_df = DataFrame({'flag': [1., 0., 1.]}) - sparse_df = sparse_df.to_sparse(fill_value=0.) + sparse_df = DataFrame({'flag': [1., 0., 1.]}) + sparse_df = sparse_df.to_sparse(fill_value=0.) xp = sparse_df[sparse_df.flag == 1.] rs = sparse_df[sparse_df.flag.isin([1.])] tm.assert_frame_equal(xp, rs) @@ -1286,10 +1250,7 @@ def test_as_blocks(self): def test_nan_columnname(self): # GH 8822 nan_colname = DataFrame(Series(1.0, index=[0]), columns=[nan]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - nan_colname_sparse = nan_colname.to_sparse() + nan_colname_sparse = nan_colname.to_sparse() assert np.isnan(nan_colname_sparse.columns[0]) def test_isna(self): @@ -1346,6 +1307,7 @@ def test_default_fill_value_with_no_data(self): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:DataFrame.to_sparse:FutureWarning") class TestSparseDataFrameArithmetic: def test_numeric_op_scalar(self): @@ -1353,12 +1315,9 @@ def test_numeric_op_scalar(self): 'B': [0, 1, 2, nan], 'C': [1., 2., 3., 4.], 'D': [nan, nan, nan, nan]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = df.to_sparse() + sparse = df.to_sparse() - tm.assert_sp_frame_equal(sparse + 1, (df + 1).to_sparse()) + tm.assert_sp_frame_equal(sparse + 1, (df + 1).to_sparse()) def test_comparison_op_scalar(self): # GH 13001 @@ -1366,10 +1325,7 @@ def test_comparison_op_scalar(self): 'B': [0, 1, 2, nan], 'C': [1., 2., 3., 4.], 'D': [nan, nan, nan, nan]}) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse = df.to_sparse() + sparse = df.to_sparse() # comparison changes internal repr, compare with dense res = sparse > 1 diff --git a/pandas/tests/sparse/frame/test_to_csv.py b/pandas/tests/sparse/frame/test_to_csv.py index 35e5e2a52d1d7..41d7bfabed44a 100644 --- a/pandas/tests/sparse/frame/test_to_csv.py +++ b/pandas/tests/sparse/frame/test_to_csv.py @@ -20,5 +20,4 @@ def test_to_csv_sparse_dataframe(self, fill_value): sdf.to_csv(path, index=False) df = read_csv(path, skip_blank_lines=False) - tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), - sdf) + tm.assert_sp_frame_equal(df.to_sparse(fill_value=fill_value), sdf) diff --git a/pandas/tests/sparse/frame/test_to_from_scipy.py b/pandas/tests/sparse/frame/test_to_from_scipy.py index 50f4577d280cb..881d8d31e5162 100644 --- a/pandas/tests/sparse/frame/test_to_from_scipy.py +++ b/pandas/tests/sparse/frame/test_to_from_scipy.py @@ -179,8 +179,8 @@ def test_index_names_multiple_nones(): # https://github.com/pandas-dev/pandas/pull/24092 sparse = pytest.importorskip("scipy.sparse") - s = (pd.Series(1, index=pd.MultiIndex - .from_product([['A', 'B'], [0, 1]])).to_sparse()) + s = (pd.Series(1, index=pd.MultiIndex.from_product([['A', 'B'], [0, 1]])) + .to_sparse()) result, _, _ = s.to_coo() assert isinstance(result, sparse.coo_matrix) result = result.toarray() diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 80f4e3a8be09b..c01a19826cf30 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -385,9 +385,9 @@ def test_shape(self): def test_astype(self): result = self.bseries.astype(SparseDtype(np.int64, 0)) expected = (self.bseries.to_dense() - .fillna(0) - .astype(np.int64) - .to_sparse(fill_value=0)) + .fillna(0) + .astype(np.int64) + .to_sparse(fill_value=0)) tm.assert_sp_series_equal(result, expected) def test_astype_all(self): @@ -576,7 +576,6 @@ def test_setslice(self): Series(7., index=range(5, 10), name=self.bseries.name)) - @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_operators(self): def _check_op(a, b, op): @@ -703,10 +702,7 @@ def _compare_with_series(sps, new_index): series = sps.to_dense() seriesre = series.reindex(new_index) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - seriesre = seriesre.to_sparse(fill_value=sps.fill_value) + seriesre = seriesre.to_sparse(fill_value=sps.fill_value) tm.assert_sp_series_equal(spsre, seriesre) tm.assert_series_equal(spsre.to_dense(), seriesre.to_dense()) @@ -839,7 +835,6 @@ def _compare_all(obj): nonna2 = Series(np.random.randn(20)).to_sparse(fill_value=0) _compare_all(nonna2) - @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_dropna(self): sp = SparseSeries([0, 0, 0, nan, nan, 5, 6], fill_value=0) @@ -931,27 +926,19 @@ def test_shift_nan(self): orig = pd.Series([np.nan, 2, np.nan, 4, 0, np.nan, 0]) sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0).to_sparse(), + tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse(), check_kind=False) - tm.assert_sp_series_equal(sparse.shift(1), - orig.shift(1).to_sparse(), + tm.assert_sp_series_equal(sparse.shift(1), orig.shift(1).to_sparse(), check_kind=False) - tm.assert_sp_series_equal(sparse.shift(2), - orig.shift(2).to_sparse(), + tm.assert_sp_series_equal(sparse.shift(2), orig.shift(2).to_sparse(), check_kind=False) - tm.assert_sp_series_equal(sparse.shift(3), - orig.shift(3).to_sparse(), + tm.assert_sp_series_equal(sparse.shift(3), orig.shift(3).to_sparse(), check_kind=False) - tm.assert_sp_series_equal(sparse.shift(-1), - orig.shift(-1).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-2), - orig.shift(-2).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-3), - orig.shift(-3).to_sparse()) - tm.assert_sp_series_equal(sparse.shift(-4), - orig.shift(-4).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-1), orig.shift(-1).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-2), orig.shift(-2).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-3), orig.shift(-3).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(-4), orig.shift(-4).to_sparse()) sparse = orig.to_sparse(fill_value=0) tm.assert_sp_series_equal( @@ -986,12 +973,10 @@ def test_shift_dtype(self): orig = pd.Series([1, 2, 3, 4], dtype=np.int64) sparse = orig.to_sparse() - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0).to_sparse()) + tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse()) sparse = orig.to_sparse(fill_value=np.nan) - tm.assert_sp_series_equal(sparse.shift(0), - orig.shift(0). + tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0). to_sparse(fill_value=np.nan)) # shift(1) or more span changes dtype to float64 @@ -1036,7 +1021,6 @@ def test_shift_dtype_fill_value(self, fill_value, periods): check_kind=False, consolidate_block_indices=True) - @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_combine_first(self): s = self.bseries @@ -1558,13 +1542,11 @@ def test_constructor_dict_datetime64_index(datetime_type): @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_to_sparse(): # https://github.com/pandas-dev/pandas/issues/22389 arr = pd.SparseArray([1, 2, None, 3]) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = pd.Series(arr).to_sparse() + result = pd.Series(arr).to_sparse() assert len(result) == 4 tm.assert_sp_array_equal(result.values, arr, check_kind=False) From a546a897ace4d5471154bfe0b26de4fbc84a3610 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 22:58:47 +0530 Subject: [PATCH 29/33] Update test warnings --- pandas/tests/io/test_pytables.py | 6 ++---- pandas/tests/series/test_api.py | 1 - pandas/tests/sparse/frame/test_frame.py | 19 +++++-------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 8dc44faeec493..299c0feb502be 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -3755,6 +3755,7 @@ def test_start_stop_multiple(self): tm.assert_frame_equal(result, expected) @ignore_sparse + @ignore_dataframe_tosparse def test_start_stop_fixed(self): with ensure_clean_store(self.path) as store: @@ -3796,10 +3797,7 @@ def test_start_stop_fixed(self): df = tm.makeDataFrame() df.iloc[3:5, 1:3] = np.nan df.iloc[8:10, -2] = np.nan - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - dfs = df.to_sparse() + dfs = df.to_sparse() store.put('dfs', dfs) with pytest.raises(NotImplementedError): store.select('dfs', start=0, stop=5) diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 63725416740b5..fac796fbf325a 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -87,7 +87,6 @@ def test_binop_maybe_preserve_name(self): result = getattr(s, op)(cp) assert result.name is None - @pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning") def test_combine_first_name(self): result = self.ts.combine_first(self.ts[:5]) assert result.name == self.ts.name diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 5b7db199d45cd..3e830e27aaedd 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -383,10 +383,7 @@ def _compare_to_dense(a, b, da, db, op): dense_result = op(da, db) fill = sparse_result.default_fill_value - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - dense_result = dense_result.to_sparse(fill_value=fill) + dense_result = dense_result.to_sparse(fill_value=fill) tm.assert_sp_frame_equal(sparse_result, dense_result, exact_indices=False) @@ -1131,20 +1128,14 @@ def _check(frame, orig): shifted = frame.shift(2, freq='B') exp = orig.shift(2, freq='B') - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = exp.to_sparse(frame.default_fill_value, - kind=frame.default_kind) + exp = exp.to_sparse(frame.default_fill_value, + kind=frame.default_kind) tm.assert_frame_equal(shifted, exp) shifted = frame.shift(2, freq=BDay()) exp = orig.shift(2, freq=BDay()) - # GH 26557: DEPR - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - exp = exp.to_sparse(frame.default_fill_value, - kind=frame.default_kind) + exp = exp.to_sparse(frame.default_fill_value, + kind=frame.default_kind) tm.assert_frame_equal(shifted, exp) _check(float_frame, float_frame_dense) From 5fdb2f88ae6b28961ee0eda4e2a971605504cf60 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Mon, 17 Jun 2019 23:02:36 +0530 Subject: [PATCH 30/33] Revert minor changes --- pandas/tests/sparse/frame/test_frame.py | 6 ++---- pandas/tests/sparse/series/test_series.py | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 3e830e27aaedd..ee6fe84897a50 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -886,8 +886,7 @@ def test_rename(self, float_frame): def test_corr(self, float_frame): res = float_frame.corr() # XXX: this stays sparse - tm.assert_frame_equal(res, - float_frame.to_dense().corr().to_sparse()) + tm.assert_frame_equal(res, float_frame.to_dense().corr().to_sparse()) def test_describe(self, float_frame): float_frame['foo'] = np.nan @@ -1204,8 +1203,7 @@ def test_combine_add(self, float_frame): tm.assert_sp_frame_equal(result, expected) def test_isin(self): - sparse_df = DataFrame({'flag': [1., 0., 1.]}) - sparse_df = sparse_df.to_sparse(fill_value=0.) + sparse_df = DataFrame({'flag': [1., 0., 1.]}).to_sparse(fill_value=0.) xp = sparse_df[sparse_df.flag == 1.] rs = sparse_df[sparse_df.flag.isin([1.])] tm.assert_frame_equal(xp, rs) diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index c01a19826cf30..cd488339b58e8 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -976,9 +976,8 @@ def test_shift_dtype(self): tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0).to_sparse()) sparse = orig.to_sparse(fill_value=np.nan) - tm.assert_sp_series_equal(sparse.shift(0), orig.shift(0). - to_sparse(fill_value=np.nan)) - + tm.assert_sp_series_equal(sparse.shift(0), + orig.shift(0).to_sparse(fill_value=np.nan)) # shift(1) or more span changes dtype to float64 # XXX: SparseSeries doesn't need to shift dtype here. # Do we want to astype in shift, for backwards compat? @@ -1012,6 +1011,7 @@ def test_shift_dtype(self): def test_shift_dtype_fill_value(self, fill_value, periods): # GH 12908 orig = pd.Series([1, 0, 0, 4], dtype=np.dtype('int64')) + sparse = orig.to_sparse(fill_value=fill_value) result = sparse.shift(periods) From a627828344b67498323bea41b73ebc3541500d53 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Tue, 18 Jun 2019 09:57:44 +0530 Subject: [PATCH 31/33] Change location of Series/df.test_deprecated_to_sparse --- pandas/tests/frame/test_deprecations.py | 20 -------------------- pandas/tests/series/test_deprecations.py | 21 --------------------- pandas/tests/sparse/frame/test_frame.py | 14 ++++++++++++++ pandas/tests/sparse/series/test_series.py | 17 ++++++++++++++++- 4 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 pandas/tests/frame/test_deprecations.py delete mode 100644 pandas/tests/series/test_deprecations.py diff --git a/pandas/tests/frame/test_deprecations.py b/pandas/tests/frame/test_deprecations.py deleted file mode 100644 index ef78a0eaf9c5b..0000000000000 --- a/pandas/tests/frame/test_deprecations.py +++ /dev/null @@ -1,20 +0,0 @@ -import numpy as np -import pytest - -import pandas as pd -from pandas.util import testing as tm - - -@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -def test_deprecated_to_sparse(): - # GH 26557 - # Deprecated 0.25.0 - - df = pd.DataFrame({"A": [1, np.nan, 3]}) - sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = df.to_sparse() - tm.assert_frame_equal(result, sparse_df) diff --git a/pandas/tests/series/test_deprecations.py b/pandas/tests/series/test_deprecations.py deleted file mode 100644 index 635ef22b4f8ea..0000000000000 --- a/pandas/tests/series/test_deprecations.py +++ /dev/null @@ -1,21 +0,0 @@ -import numpy as np -import pytest - -import pandas as pd -from pandas import Series -from pandas.util import testing as tm - - -@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -def test_deprecated_to_sparse(): - # GH 26557 - # Deprecated 0.25.0 - - ser = Series([1, np.nan, 3]) - sparse_ser = pd.SparseSeries([1, np.nan, 3]) - - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = ser.to_sparse() - tm.assert_series_equal(result, sparse_ser) diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index ee6fe84897a50..56e62c490186e 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -350,6 +350,20 @@ def test_dense_to_sparse(self): assert sdf.default_fill_value == 0 tm.assert_frame_equal(sdf.to_dense(), df) + @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") + def test_deprecated_to_sparse(): + # GH 26557 + # Deprecated 0.25.0 + + df = pd.DataFrame({"A": [1, np.nan, 3]}) + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + + # Deprecated 0.25.0 + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = df.to_sparse() + tm.assert_frame_equal(result, sparse_df) + def test_density(self): df = SparseSeries([nan, nan, nan, 0, 1, 2, 3, 4, 5, 6]) assert df.density == 0.7 diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index cd488339b58e8..50d9f59bfacea 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1551,6 +1551,21 @@ def test_to_sparse(): tm.assert_sp_array_equal(result.values, arr, check_kind=False) +@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") +def test_deprecated_to_sparse(): + # GH 26557 + # Deprecated 0.25.0 + + ser = Series([1, np.nan, 3]) + sparse_ser = pd.SparseSeries([1, np.nan, 3]) + + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = ser.to_sparse() + tm.assert_series_equal(result, sparse_ser) + + + @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_constructor_mismatched_raises(): msg = "Length of passed values is 2, index implies 3" @@ -1576,4 +1591,4 @@ def test_deprecate_to_dense(): # Deprecated 0.25.0 with tm.assert_produces_warning(FutureWarning): result = sparse_ser.to_dense() - tm.assert_series_equal(result, ser) + tm.assert_series_equal(result, ser) From 3d36430445a71382f0955e7af136b523ecc821bc Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Tue, 18 Jun 2019 10:16:54 +0530 Subject: [PATCH 32/33] Remove SDF/SS.to_dense depr:class already deprecated --- pandas/core/sparse/frame.py | 15 --------------- pandas/core/sparse/series.py | 6 ------ 2 files changed, 21 deletions(-) diff --git a/pandas/core/sparse/frame.py b/pandas/core/sparse/frame.py index 71d58082d008b..67ecbcbea67f9 100644 --- a/pandas/core/sparse/frame.py +++ b/pandas/core/sparse/frame.py @@ -282,21 +282,6 @@ def _unpickle_sparse_frame_compat(self, state): @Appender(SparseFrameAccessor.to_dense.__doc__) def to_dense(self): - """ - .. deprecated:: 0.25.0 - Use Dataframe.sparse.to_dense() instead - """ - - warning_message = """\ -SparseDataFrame.to_dense is deprecated and will be removed in a future version - - Use Dataframe.sparse.to_dense() instead - - >>> df = pd.DataFrame({"A": pd.SparseArray([0, 1, 0])}) - >>> df.sparse.to_dense() - """ - warnings.warn(warning_message, FutureWarning, stacklevel=2) - return SparseFrameAccessor(self).to_dense() def _apply_columns(self, func): diff --git a/pandas/core/sparse/series.py b/pandas/core/sparse/series.py index 02032ba1e4d01..3e3bae6444082 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -432,16 +432,10 @@ def to_dense(self): """ Convert SparseSeries to a Series. - .. deprecated:: 0.25.0 - Returns ------- s : Series """ - warnings.warn("SparseSeries.to_dense is deprecated " - "and will be removed in a future version", - FutureWarning, stacklevel=2) - return Series(self.values.to_dense(), index=self.index, name=self.name) From 9f888c5aa8524c27f5897c6e9fc1bf9c58c74480 Mon Sep 17 00:00:00 2001 From: Nighthawx <41290641+intEll1gent@users.noreply.github.com> Date: Tue, 18 Jun 2019 10:21:04 +0530 Subject: [PATCH 33/33] Add whatsnew entry --- doc/source/whatsnew/v0.25.0.rst | 1 + pandas/tests/sparse/frame/test_frame.py | 33 +++++++---------------- pandas/tests/sparse/series/test_series.py | 19 ++----------- 3 files changed, 12 insertions(+), 41 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 2b1a61186dca6..54462728dc38a 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -503,6 +503,7 @@ Other Deprecations - The :meth:`Series.ftype`, :meth:`Series.ftypes` and :meth:`DataFrame.ftypes` methods are deprecated and will be removed in a future version. Instead, use :meth:`Series.dtype` and :meth:`DataFrame.dtypes` (:issue:`26705`). - :meth:`Timedelta.resolution` is deprecated and replaced with :meth:`Timedelta.resolution_string`. In a future version, :meth:`Timedelta.resolution` will be changed to behave like the standard library :attr:`timedelta.resolution` (:issue:`21344`) +- :meth:`Series.to_sparse`, :meth:`DataFrame.to_sparse`, :meth:`Series.to_dense` and :meth:`DataFrame.to_dense` are deprecated and will be removed in a future version. (:issue:`26557`). .. _whatsnew_0250.prior_deprecations: diff --git a/pandas/tests/sparse/frame/test_frame.py b/pandas/tests/sparse/frame/test_frame.py index 56e62c490186e..2d0b338ef53c0 100644 --- a/pandas/tests/sparse/frame/test_frame.py +++ b/pandas/tests/sparse/frame/test_frame.py @@ -350,19 +350,17 @@ def test_dense_to_sparse(self): assert sdf.default_fill_value == 0 tm.assert_frame_equal(sdf.to_dense(), df) - @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") - def test_deprecated_to_sparse(): - # GH 26557 - # Deprecated 0.25.0 + def test_deprecated_dense_to_sparse(self): + # GH 26557 + # Deprecated 0.25.0 - df = pd.DataFrame({"A": [1, np.nan, 3]}) - sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) + df = pd.DataFrame({"A": [1, np.nan, 3]}) + sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - result = df.to_sparse() - tm.assert_frame_equal(result, sparse_df) + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=False): + result = df.to_sparse() + tm.assert_frame_equal(result, sparse_df) def test_density(self): df = SparseSeries([nan, nan, nan, 0, 1, 2, 3, 4, 5, 6]) @@ -1433,16 +1431,3 @@ def test_dropna(self, inplace, how): if inplace: result_df = input_df tm.assert_sp_frame_equal(expected, result_df) - - -def test_deprecated_to_dense(): - # GH 26557 - # Deprecated 0.25.0 - - df = pd.DataFrame({"A": [1, np.nan, 3]}) - - with tm.assert_produces_warning(FutureWarning, - check_stacklevel=False): - sparse_df = pd.SparseDataFrame({"A": [1, np.nan, 3]}) - result = sparse_df.to_dense() - tm.assert_frame_equal(result, df) diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 50d9f59bfacea..9ce1133cb39ca 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1555,17 +1555,16 @@ def test_to_sparse(): def test_deprecated_to_sparse(): # GH 26557 # Deprecated 0.25.0 - + ser = Series([1, np.nan, 3]) sparse_ser = pd.SparseSeries([1, np.nan, 3]) - + with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): result = ser.to_sparse() tm.assert_series_equal(result, sparse_ser) - @pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") def test_constructor_mismatched_raises(): msg = "Length of passed values is 2, index implies 3" @@ -1578,17 +1577,3 @@ def test_block_deprecated(): s = SparseSeries([1]) with tm.assert_produces_warning(FutureWarning): s.block - - -@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning") -def test_deprecate_to_dense(): - # GH 26557 - # Deprecated 0.25.0 - - ser = pd.Series([1, 2, 3]) - sparse_ser = pd.SparseSeries([1, 2, 3]) - - # Deprecated 0.25.0 - with tm.assert_produces_warning(FutureWarning): - result = sparse_ser.to_dense() - tm.assert_series_equal(result, ser)