From 2acaea4403751cebdfbcf4b0b92a6143b49cc0f3 Mon Sep 17 00:00:00 2001 From: Tuhin Sharma Date: Sun, 6 Oct 2024 09:52:18 +0530 Subject: [PATCH] DOC: fix PR07,SA01,ES01 for pandas.Series.sparse.from_coo --- ci/code_checks.sh | 1 - pandas/core/arrays/sparse/accessor.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 16a3a22bc4876..c93dbf511aec0 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -96,7 +96,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Series.dt.tz_localize PR01,PR02" \ -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ - -i "pandas.Series.sparse.from_coo PR07,SA01" \ -i "pandas.Timedelta.max PR02" \ -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ diff --git a/pandas/core/arrays/sparse/accessor.py b/pandas/core/arrays/sparse/accessor.py index 8083371ed171a..0ed5f69fe4703 100644 --- a/pandas/core/arrays/sparse/accessor.py +++ b/pandas/core/arrays/sparse/accessor.py @@ -88,9 +88,17 @@ def from_coo(cls, A, dense_index: bool = False) -> Series: """ Create a Series with sparse values from a scipy.sparse.coo_matrix. + This method takes a ``scipy.sparse.coo_matrix`` (coordinate format) as input and + returns a pandas ``Series`` where the non-zero elements are represented as + sparse values. The index of the Series can either include only the coordinates + of non-zero elements (default behavior) or the full sorted set of coordinates + from the matrix if ``dense_index`` is set to `True`. + Parameters ---------- A : scipy.sparse.coo_matrix + The sparse matrix in coordinate format from which the sparse Series + will be created. 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. @@ -102,6 +110,12 @@ def from_coo(cls, A, dense_index: bool = False) -> Series: s : Series A Series with sparse values. + See Also + -------- + DataFrame.sparse.from_spmatrix : Create a new DataFrame from a scipy sparse + matrix. + scipy.sparse.coo_matrix : A sparse matrix in COOrdinate format. + Examples -------- >>> from scipy import sparse