Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEPR: Deprecate Series/Dataframe.to_dense/to_sparse #26684

Merged
merged 37 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a71737c
Deprecate Series/Dataframe.to_dense/to_sparse()
VikramjeetD Jun 5, 2019
fc08e93
Update series.py
VikramjeetD Jun 5, 2019
82c713d
Beautify
VikramjeetD Jun 5, 2019
39230d4
Beautify
VikramjeetD Jun 5, 2019
1e7c0e8
Beautify
VikramjeetD Jun 7, 2019
e68826c
Update Deprecated SparseDF/Series tests
VikramjeetD Jun 7, 2019
20b8962
Beautify
VikramjeetD Jun 8, 2019
50d0534
Deprecate NDFrame.to_dense
VikramjeetD Jun 8, 2019
933162d
Beautify
VikramjeetD Jun 8, 2019
dd1e6c2
Silence test time deprecation warnings
VikramjeetD Jun 8, 2019
c7f27fd
Beautify
VikramjeetD Jun 8, 2019
be14520
Propose changes to certain tests
VikramjeetD Jun 8, 2019
b12e447
Propose changes to tests. IGNORE PREV COMMIT.
VikramjeetD Jun 8, 2019
2d4de51
Silence test time deprecation warnings
VikramjeetD Jun 9, 2019
eede9b8
Add tests for Series/DataFrame.to_sparse
VikramjeetD Jun 9, 2019
0b08795
Beautify
VikramjeetD Jun 9, 2019
5182a1f
Modify test time warning silence
VikramjeetD Jun 12, 2019
15909c5
Modify groupby ops to remove NDFrame test warnings and add wcatch for…
VikramjeetD Jun 17, 2019
104c12a
Remove filterwarning from test_hist_method.py
VikramjeetD Jun 17, 2019
e713fb0
Update sparsearray test_arithmetics warning
VikramjeetD Jun 17, 2019
587b14f
Remove filterwarning from test_decimal.py
VikramjeetD Jun 17, 2019
1318676
Beautify
VikramjeetD Jun 17, 2019
9043e03
Merge branch 'master' of https://github.com/IntEll1gent/pandas
VikramjeetD Jun 17, 2019
58c678a
Beautify
VikramjeetD Jun 17, 2019
ca14ac1
Merge branch 'master' of https://github.com/IntEll1gent/pandas
VikramjeetD Jun 17, 2019
0c8f287
Update test warnings
VikramjeetD Jun 17, 2019
871ccff
Merge remote-tracking branch 'upstream/master'
VikramjeetD Jun 17, 2019
a8f6c56
Update pandas/core/generic.py
VikramjeetD Jun 17, 2019
72aaca5
Merge branch 'master' of https://github.com/IntEll1gent/pandas
VikramjeetD Jun 17, 2019
6a6e333
Update test time warnings and rectify df/series.to_sparse double warn…
VikramjeetD Jun 17, 2019
4e67856
Update more test time warnings
VikramjeetD Jun 17, 2019
4a3181b
Update test warnings
VikramjeetD Jun 17, 2019
a546a89
Update test warnings
VikramjeetD Jun 17, 2019
5fdb2f8
Revert minor changes
VikramjeetD Jun 17, 2019
a627828
Change location of Series/df.test_deprecated_to_sparse
VikramjeetD Jun 18, 2019
3d36430
Remove SDF/SS.to_dense depr:class already deprecated
VikramjeetD Jun 18, 2019
9f888c5
Add whatsnew entry
VikramjeetD Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
15 changes: 0 additions & 15 deletions pandas/core/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions pandas/core/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 0 additions & 20 deletions pandas/tests/frame/test_deprecations.py

This file was deleted.

21 changes: 0 additions & 21 deletions pandas/tests/series/test_deprecations.py

This file was deleted.

25 changes: 12 additions & 13 deletions pandas/tests/sparse/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ def test_dense_to_sparse(self):
assert sdf.default_fill_value == 0
tm.assert_frame_equal(sdf.to_dense(), df)

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]})

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
result = df.to_sparse()
tm.assert_frame_equal(result, sparse_df)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you put this in a class where those warnings you want to check for are generally ignored. Does that work? (just wondering)

Maybe we can also put it at the end of the file as a function instead of method, to avoid possible concerns about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since the tests are passing, this is probably fine ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually works fine, tm.assert_produces_warning doesn't seem to care about filterwarnings. Remove the warning from to_sparse and this test fails.

I wanted to keep both (test_dense_to_sparse and test_deprecated_dense_to_sparse) close for easy reference, thats all. Open to shifting it to the end though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking, then that sounds good!


def test_density(self):
df = SparseSeries([nan, nan, nan, 0, 1, 2, 3, 4, 5, 6])
assert df.density == 0.7
Expand Down Expand Up @@ -1419,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)
28 changes: 14 additions & 14 deletions pandas/tests/sparse/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,20 @@ 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"
Expand All @@ -1563,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)