diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 5957b23535350..1b3b0df1f2c29 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,11 @@ 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..6b46f1cf8c55b 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,9 @@ def to_sparse(self, kind='block', fill_value=None): SparseSeries Sparse representation of the Series. """ + + 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 0320da6d9a48d..9ee208197e79b 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..3e0150ea62292 100644 --- a/pandas/core/sparse/series.py +++ b/pandas/core/sparse/series.py @@ -428,12 +428,16 @@ def _set_values(self, key, value): def to_dense(self): """ - Convert SparseSeries to a Series. + ..deprecated:: 0.25.0 + Convert SparseSeries to a Series. Returns ------- s : Series """ + 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)