Skip to content

Commit

Permalink
DOCS: fix docstring validation errors for pandas.Series.sparse
Browse files Browse the repository at this point in the history
Fixes:
-i "pandas.Series.sparse.fill_value SA01" \
-i "pandas.Series.sparse.from_coo PR07,SA01" \
-i "pandas.Series.sparse.npoints SA01" \
-i "pandas.Series.sparse.sp_values SA01" \
-i "pandas.Series.sparse.to_coo PR07,RT03,SA01" \
  • Loading branch information
ivonastojanovic committed Aug 24, 2024
1 parent 224c6ff commit dad8f56
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
4 changes: 0 additions & 4 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.sem PR01,RT03,SA01" \
-i "pandas.Series.sparse PR01,SA01" \
-i "pandas.Series.sparse.density SA01" \
-i "pandas.Series.sparse.fill_value SA01" \
-i "pandas.Series.sparse.from_coo PR07,SA01" \
-i "pandas.Series.sparse.npoints SA01" \
-i "pandas.Series.sparse.sp_values SA01" \
-i "pandas.Series.sparse.to_coo PR07,RT03,SA01" \
-i "pandas.Series.std PR01,RT03,SA01" \
-i "pandas.Series.str.match RT03" \
Expand Down
32 changes: 32 additions & 0 deletions pandas/core/arrays/sparse/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def from_coo(cls, A, dense_index: bool = False) -> Series:
Parameters
----------
A : scipy.sparse.coo_matrix
A sparse matrix in COOrdinate format. The matrix should have
non-zero elements that will be used to create a Series with sparse
values. The row and column indices of these elements form the index
of the Series.
dense_index : bool, default False
If False (default), the index consists of only the
coords of the non-null entries of the original coo_matrix.
Expand All @@ -90,6 +94,14 @@ def from_coo(cls, A, dense_index: bool = False) -> Series:
s : Series
A Series with sparse values.
See Also
--------
scipy.sparse.coo_matrix : Sparse matrix in COOrdinate format.
pd.Series.sparse : Accessor object for sparse data in a Series.
pd.DataFrame.sparse.from_spmatrix : Create a DataFrame with sparse
values from a scipy sparse matrix.
pd.SparseArray : Array type for storing sparse data.
Examples
--------
>>> from scipy import sparse
Expand Down Expand Up @@ -135,7 +147,13 @@ def to_coo(
Parameters
----------
row_levels : tuple/list
The levels of the MultiIndex to use for the row coordinates in the
resulting sparse matrix. These can be specified as the names or
numerical positions of the levels.
column_levels : tuple/list
The levels of the MultiIndex to use for the column coordinates in the
resulting sparse matrix. These can be specified as the names or
numerical positions of the levels.
sort_labels : bool, default False
Sort the row and column labels before forming the sparse matrix.
When `row_levels` and/or `column_levels` refer to a single level,
Expand All @@ -144,8 +162,22 @@ def to_coo(
Returns
-------
y : scipy.sparse.coo_matrix
A sparse matrix in COOrdinate format representing the non-NA values
of the Series.
rows : list (row labels)
The row labels corresponding to the row coordinates in the sparse matrix.
columns : list (column labels)
The column labels corresponding to the column coordinates in the sparse
matrix.
See Also
--------
scipy.sparse.coo_matrix : Sparse matrix in COOrdinate format.
pd.Series.sparse.from_coo : Create a Series with sparse values from a
scipy.sparse.coo_matrix.
pd.DataFrame.sparse.from_spmatrix : Create a DataFrame with sparse values
from a scipy sparse matrix.
pd.SparseArray : Array type for storing sparse data.
Examples
--------
Expand Down
20 changes: 20 additions & 0 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,15 @@ def sp_values(self) -> np.ndarray:
"""
An ndarray containing the non- ``fill_value`` values.
See Also
--------
SparseArray : Array type for storing sparse data.
SparseArray.sp_index : The index object storing the positions of
non-``fill_value`` values.
SparseArray.fill_value : The value considered as "missing" or not stored.
SparseArray.sp_values : Returns the non-``fill_value`` values in the sparse
array.
Examples
--------
>>> from pandas.arrays import SparseArray
Expand All @@ -623,6 +632,11 @@ def fill_value(self):
For memory savings, this should be the most common value in the array.
See Also
--------
pd.SparseDtype : Type for sparse data which holds the dtype and fill_value.
pd.Series.sparse : Accessor object for sparse data in a Series.
Examples
--------
>>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
Expand Down Expand Up @@ -685,6 +699,12 @@ def npoints(self) -> int:
"""
The number of non- ``fill_value`` points.
See Also
--------
SparseArray : Array type for storing sparse data.
SparseIndex : Stores the locations and counts of non-``fill_value`` data.
SparseArray.fill_value : The value considered as "missing" or not stored.
Examples
--------
>>> from pandas.arrays import SparseArray
Expand Down

0 comments on commit dad8f56

Please sign in to comment.