Skip to content

Commit 94f976f

Browse files
authored
DOC: Improve sparse.rst (#45376)
1 parent 5ceeb43 commit 94f976f

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

doc/source/reference/arrays.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ be stored efficiently as a :class:`arrays.SparseArray`.
464464

465465
The ``Series.sparse`` accessor may be used to access sparse-specific attributes
466466
and methods if the :class:`Series` contains sparse values. See
467-
:ref:`api.series.sparse` for more.
467+
:ref:`api.series.sparse` and :ref:`the user guide <sparse>` for more.
468468

469469

470470
.. _api.arrays.string:

doc/source/user_guide/sparse.rst

+10-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ array that are ``nan`` aren't actually stored, only the non-``nan`` elements are
2323
Those non-``nan`` elements have a ``float64`` dtype.
2424

2525
The sparse objects exist for memory efficiency reasons. Suppose you had a
26-
large, mostly NA ``DataFrame``:
26+
large, mostly NA :class:`DataFrame`:
2727

2828
.. ipython:: python
2929
@@ -139,7 +139,7 @@ Sparse calculation
139139
------------------
140140

141141
You can apply NumPy `ufuncs <https://numpy.org/doc/stable/reference/ufuncs.html>`_
142-
to ``SparseArray`` and get a ``SparseArray`` as a result.
142+
to :class:`arrays.SparseArray` and get a :class:`arrays.SparseArray` as a result.
143143

144144
.. ipython:: python
145145
@@ -183,7 +183,7 @@ your code, rather than ignoring the warning.
183183
**Construction**
184184

185185
From an array-like, use the regular :class:`Series` or
186-
:class:`DataFrame` constructors with :class:`SparseArray` values.
186+
:class:`DataFrame` constructors with :class:`arrays.SparseArray` values.
187187

188188
.. code-block:: python
189189
@@ -240,7 +240,7 @@ Sparse-specific properties, like ``density``, are available on the ``.sparse`` a
240240
**General differences**
241241

242242
In a ``SparseDataFrame``, *all* columns were sparse. A :class:`DataFrame` can have a mixture of
243-
sparse and dense columns. As a consequence, assigning new columns to a ``DataFrame`` with sparse
243+
sparse and dense columns. As a consequence, assigning new columns to a :class:`DataFrame` with sparse
244244
values will not automatically convert the input to be sparse.
245245

246246
.. code-block:: python
@@ -269,7 +269,7 @@ have no replacement.
269269
Interaction with scipy.sparse
270270
-----------------------------
271271

272-
Use :meth:`DataFrame.sparse.from_spmatrix` to create a ``DataFrame`` with sparse values from a sparse matrix.
272+
Use :meth:`DataFrame.sparse.from_spmatrix` to create a :class:`DataFrame` with sparse values from a sparse matrix.
273273

274274
.. versionadded:: 0.25.0
275275

@@ -294,9 +294,9 @@ To convert back to sparse SciPy matrix in COO format, you can use the :meth:`Dat
294294
295295
sdf.sparse.to_coo()
296296
297-
:meth:`Series.sparse.to_coo` is implemented for transforming a ``Series`` with sparse values indexed by a :class:`MultiIndex` to a :class:`scipy.sparse.coo_matrix`.
297+
:meth:`Series.sparse.to_coo` is implemented for transforming a :class:`Series` with sparse values indexed by a :class:`MultiIndex` to a :class:`scipy.sparse.coo_matrix`.
298298

299-
The method requires a ``MultiIndex`` with two or more levels.
299+
The method requires a :class:`MultiIndex` with two or more levels.
300300

301301
.. ipython:: python
302302
@@ -315,7 +315,7 @@ The method requires a ``MultiIndex`` with two or more levels.
315315
ss = s.astype('Sparse')
316316
ss
317317
318-
In the example below, we transform the ``Series`` to a sparse representation of a 2-d array by specifying that the first and second ``MultiIndex`` levels define labels for the rows and the third and fourth levels define labels for the columns. We also specify that the column and row labels should be sorted in the final sparse representation.
318+
In the example below, we transform the :class:`Series` to a sparse representation of a 2-d array by specifying that the first and second ``MultiIndex`` levels define labels for the rows and the third and fourth levels define labels for the columns. We also specify that the column and row labels should be sorted in the final sparse representation.
319319

320320
.. ipython:: python
321321
@@ -341,7 +341,7 @@ Specifying different row and column labels (and not sorting them) yields a diffe
341341
rows
342342
columns
343343
344-
A convenience method :meth:`Series.sparse.from_coo` is implemented for creating a ``Series`` with sparse values from a ``scipy.sparse.coo_matrix``.
344+
A convenience method :meth:`Series.sparse.from_coo` is implemented for creating a :class:`Series` with sparse values from a ``scipy.sparse.coo_matrix``.
345345

346346
.. ipython:: python
347347
@@ -350,7 +350,7 @@ A convenience method :meth:`Series.sparse.from_coo` is implemented for creating
350350
A
351351
A.todense()
352352
353-
The default behaviour (with ``dense_index=False``) simply returns a ``Series`` containing
353+
The default behaviour (with ``dense_index=False``) simply returns a :class:`Series` containing
354354
only the non-null entries.
355355

356356
.. ipython:: python

0 commit comments

Comments
 (0)