Skip to content

Commit 2171154

Browse files
authored
DOC: Remove old SparseDataFrame/SparseSeries references (#52092)
* DOC: Remove SparseDataFrame/SparseSeries references * fix doc error * fix doc bug * fix doc link issue
1 parent 900ffa3 commit 2171154

File tree

3 files changed

+4
-95
lines changed

3 files changed

+4
-95
lines changed

doc/source/user_guide/sparse.rst

+2-92
Original file line numberDiff line numberDiff line change
@@ -153,70 +153,14 @@ the correct dense result.
153153
np.abs(arr)
154154
np.abs(arr).to_dense()
155155
156-
.. _sparse.migration:
157-
158-
Migrating
159-
---------
160-
161-
.. note::
162-
163-
``SparseSeries`` and ``SparseDataFrame`` were removed in pandas 1.0.0. This migration
164-
guide is present to aid in migrating from previous versions.
165-
166-
In older versions of pandas, the ``SparseSeries`` and ``SparseDataFrame`` classes (documented below)
167-
were the preferred way to work with sparse data. With the advent of extension arrays, these subclasses
168-
are no longer needed. Their purpose is better served by using a regular Series or DataFrame with
169-
sparse values instead.
170-
171-
.. note::
172-
173-
There's no performance or memory penalty to using a Series or DataFrame with sparse values,
174-
rather than a SparseSeries or SparseDataFrame.
175-
176-
This section provides some guidance on migrating your code to the new style. As a reminder,
177-
you can use the Python warnings module to control warnings. But we recommend modifying
178-
your code, rather than ignoring the warning.
179-
180-
**Construction**
181-
182-
From an array-like, use the regular :class:`Series` or
183-
:class:`DataFrame` constructors with :class:`arrays.SparseArray` values.
184-
185-
.. code-block:: python
186-
187-
# Previous way
188-
>>> pd.SparseDataFrame({"A": [0, 1]})
189-
190-
.. ipython:: python
191-
192-
# New way
193-
pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])})
194-
195-
From a SciPy sparse matrix, use :meth:`DataFrame.sparse.from_spmatrix`,
196-
197-
.. code-block:: python
198-
199-
# Previous way
200-
>>> from scipy import sparse
201-
>>> mat = sparse.eye(3)
202-
>>> df = pd.SparseDataFrame(mat, columns=['A', 'B', 'C'])
203-
204-
.. ipython:: python
205-
206-
# New way
207-
from scipy import sparse
208-
mat = sparse.eye(3)
209-
df = pd.DataFrame.sparse.from_spmatrix(mat, columns=['A', 'B', 'C'])
210-
df.dtypes
211156
212157
**Conversion**
213158

214-
From sparse to dense, use the ``.sparse`` accessors
159+
To convert data from sparse to dense, use the ``.sparse`` accessors
215160

216161
.. ipython:: python
217162
218-
df.sparse.to_dense()
219-
df.sparse.to_coo()
163+
sdf.sparse.to_dense()
220164
221165
From dense to sparse, use :meth:`DataFrame.astype` with a :class:`SparseDtype`.
222166

@@ -226,40 +170,6 @@ From dense to sparse, use :meth:`DataFrame.astype` with a :class:`SparseDtype`.
226170
dtype = pd.SparseDtype(int, fill_value=0)
227171
dense.astype(dtype)
228172
229-
**Sparse Properties**
230-
231-
Sparse-specific properties, like ``density``, are available on the ``.sparse`` accessor.
232-
233-
.. ipython:: python
234-
235-
df.sparse.density
236-
237-
**General differences**
238-
239-
In a ``SparseDataFrame``, *all* columns were sparse. A :class:`DataFrame` can have a mixture of
240-
sparse and dense columns. As a consequence, assigning new columns to a :class:`DataFrame` with sparse
241-
values will not automatically convert the input to be sparse.
242-
243-
.. code-block:: python
244-
245-
# Previous Way
246-
>>> df = pd.SparseDataFrame({"A": [0, 1]})
247-
>>> df['B'] = [0, 0] # implicitly becomes Sparse
248-
>>> df['B'].dtype
249-
Sparse[int64, nan]
250-
251-
Instead, you'll need to ensure that the values being assigned are sparse
252-
253-
.. ipython:: python
254-
255-
df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1])})
256-
df['B'] = [0, 0] # remains dense
257-
df['B'].dtype
258-
df['B'] = pd.arrays.SparseArray([0, 0])
259-
df['B'].dtype
260-
261-
The ``SparseDataFrame.default_kind`` and ``SparseDataFrame.default_fill_value`` attributes
262-
have no replacement.
263173
264174
.. _sparse.scipysparse:
265175

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ by a ``Series`` or ``DataFrame`` with sparse values.
921921
df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 0, 1, 2])})
922922
df.dtypes
923923
924-
The memory usage of the two approaches is identical. See :ref:`sparse.migration` for more (:issue:`19239`).
924+
The memory usage of the two approaches is identical (:issue:`19239`).
925925
926926
msgpack format
927927
^^^^^^^^^^^^^^

doc/source/whatsnew/v1.0.0.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,7 @@ Removal of prior version deprecations/changes
872872

873873
``SparseSeries``, ``SparseDataFrame`` and the ``DataFrame.to_sparse`` method
874874
have been removed (:issue:`28425`). We recommend using a ``Series`` or
875-
``DataFrame`` with sparse values instead. See :ref:`sparse.migration` for help
876-
with migrating existing code.
875+
``DataFrame`` with sparse values instead.
877876

878877
.. _whatsnew_100.matplotlib_units:
879878

0 commit comments

Comments
 (0)